]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.common/src/org/simantics/db/common/request/SuperTypeString.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / request / SuperTypeString.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 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  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.db.common.request;\r
13 \r
14 import java.util.Set;\r
15 \r
16 import org.simantics.databoard.Bindings;\r
17 import org.simantics.db.ReadGraph;\r
18 import org.simantics.db.Resource;\r
19 import org.simantics.db.common.utils.Logger;\r
20 import org.simantics.db.exception.DatabaseException;\r
21 import org.simantics.layer0.Layer0;\r
22 \r
23 public class SuperTypeString extends BinaryRead<Resource, String, String> {\r
24 \r
25     public SuperTypeString(Resource type) {\r
26         super(type, " ");\r
27     }\r
28 \r
29     public SuperTypeString(Resource type, String separator) {\r
30         super(type, separator);\r
31         if (separator == null)\r
32             throw new NullPointerException("null separator");\r
33     }\r
34 \r
35     @Override\r
36     public String perform(ReadGraph graph) throws DatabaseException {\r
37         \r
38         Layer0 L0 = Layer0.getInstance(graph);\r
39         Set<Resource> supers = graph.getSupertypes(parameter);\r
40         final StringBuilder b = new StringBuilder();\r
41         String name = graph.getPossibleRelatedValue(parameter, L0.HasName, Bindings.STRING);\r
42         if(name != null) {\r
43                 b.append(name);\r
44             for (Resource r : supers) {\r
45                 name = graph.getPossibleRelatedValue(r, L0.HasName, Bindings.STRING);\r
46                 if(name != null) {\r
47                         b.append(parameter2);\r
48                         b.append(name);\r
49                 } else {\r
50                         Logger.defaultLogError(new DatabaseException("No name for type " + r));\r
51                 }\r
52             }\r
53         } else {\r
54                 Logger.defaultLogError(new DatabaseException("No name for type " + parameter));\r
55         }\r
56         \r
57         return b.toString();\r
58 \r
59     }\r
60 \r
61 }