--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 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
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.db.common.request;\r
+\r
+import java.util.Set;\r
+\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.utils.Logger;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+\r
+public class SuperTypeString extends BinaryRead<Resource, String, String> {\r
+\r
+ public SuperTypeString(Resource type) {\r
+ super(type, " ");\r
+ }\r
+\r
+ public SuperTypeString(Resource type, String separator) {\r
+ super(type, separator);\r
+ if (separator == null)\r
+ throw new NullPointerException("null separator");\r
+ }\r
+\r
+ @Override\r
+ public String perform(ReadGraph graph) throws DatabaseException {\r
+ \r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ Set<Resource> supers = graph.getSupertypes(parameter);\r
+ final StringBuilder b = new StringBuilder();\r
+ String name = graph.getPossibleRelatedValue(parameter, L0.HasName, Bindings.STRING);\r
+ if(name != null) {\r
+ b.append(name);\r
+ for (Resource r : supers) {\r
+ name = graph.getPossibleRelatedValue(r, L0.HasName, Bindings.STRING);\r
+ if(name != null) {\r
+ b.append(parameter2);\r
+ b.append(name);\r
+ } else {\r
+ Logger.defaultLogError(new DatabaseException("No name for type " + r));\r
+ }\r
+ }\r
+ } else {\r
+ Logger.defaultLogError(new DatabaseException("No name for type " + parameter));\r
+ }\r
+ \r
+ return b.toString();\r
+\r
+ }\r
+\r
+}
\ No newline at end of file