]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/EntityStringModifierFactory.java
Sync git svn branch with SVN repository r33389.
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / adapter / impl / EntityStringModifierFactory.java
1 /*******************************************************************************\r
2  * Copyright (c) 2013 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     Semantum Oy - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.db.layer0.adapter.impl;\r
13 \r
14 import org.simantics.db.ReadGraph;\r
15 import org.simantics.db.Resource;\r
16 import org.simantics.db.exception.DatabaseException;\r
17 import org.simantics.db.layer0.adapter.StringModifier;\r
18 import org.simantics.db.layer0.adapter.StringModifierFactory;\r
19 import org.simantics.db.layer0.variable.Variable;\r
20 import org.simantics.layer0.Layer0;\r
21 \r
22 /**\r
23  * Makes sure that two things apply for L0.HasName of any entity:\r
24  * <ol>\r
25  * <li>An entity must not have the same name as any of its\r
26  * L0.PartOf/L0.ConsistsOf related siblings</li>\r
27  * <li>An entity's name must not begin with one or more dots ('.'). Due to\r
28  * limitations imposed by the Variable specification no resources in the\r
29  * simantics database should be named beginning with one or more dots. '.' is\r
30  * variable browsing syntax for "parent" (see\r
31  * {@link Variable#browse(ReadGraph, String)}). This is comparable to file\r
32  * systems and the use of '.' and '..' therein.</li>\r
33  * </ol>\r
34  * \r
35  * @author Tuukka Lehtonen\r
36  */\r
37 public final class EntityStringModifierFactory implements StringModifierFactory {\r
38 \r
39     private Resource subject;\r
40 \r
41     public EntityStringModifierFactory(Resource subject) throws DatabaseException {\r
42         this.subject = subject;\r
43     }\r
44 \r
45     @Override\r
46     public StringModifier createModifier(ReadGraph graph, Resource relation, Resource property) throws DatabaseException {\r
47         Layer0 L0 = Layer0.getInstance(graph);\r
48 \r
49         // Names require special care in validation.\r
50         if (L0.HasName.equals(relation)) {\r
51             return new EntityNameModifier(graph, subject, property);\r
52         }\r
53 \r
54         return null;\r
55     }\r
56 \r
57 }\r