+/*******************************************************************************\r
+ * Copyright (c) 2013 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * Semantum Oy - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.db.layer0.adapter.impl;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.adapter.StringModifier;\r
+import org.simantics.db.layer0.adapter.StringModifierFactory;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.layer0.Layer0;\r
+\r
+/**\r
+ * Makes sure that two things apply for L0.HasName of any entity:\r
+ * <ol>\r
+ * <li>An entity must not have the same name as any of its\r
+ * L0.PartOf/L0.ConsistsOf related siblings</li>\r
+ * <li>An entity's name must not begin with one or more dots ('.'). Due to\r
+ * limitations imposed by the Variable specification no resources in the\r
+ * simantics database should be named beginning with one or more dots. '.' is\r
+ * variable browsing syntax for "parent" (see\r
+ * {@link Variable#browse(ReadGraph, String)}). This is comparable to file\r
+ * systems and the use of '.' and '..' therein.</li>\r
+ * </ol>\r
+ * \r
+ * @author Tuukka Lehtonen\r
+ */\r
+public final class EntityStringModifierFactory implements StringModifierFactory {\r
+\r
+ private Resource subject;\r
+\r
+ public EntityStringModifierFactory(Resource subject) throws DatabaseException {\r
+ this.subject = subject;\r
+ }\r
+\r
+ @Override\r
+ public StringModifier createModifier(ReadGraph graph, Resource relation, Resource property) throws DatabaseException {\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+\r
+ // Names require special care in validation.\r
+ if (L0.HasName.equals(relation)) {\r
+ return new EntityNameModifier(graph, subject, property);\r
+ }\r
+\r
+ return null;\r
+ }\r
+\r
+}\r