]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network/src/org/simantics/district/network/techtype/requests/PossibleTechTypeKeyName.java
Tech type table content validation
[simantics/district.git] / org.simantics.district.network / src / org / simantics / district / network / techtype / requests / PossibleTechTypeKeyName.java
diff --git a/org.simantics.district.network/src/org/simantics/district/network/techtype/requests/PossibleTechTypeKeyName.java b/org.simantics.district.network/src/org/simantics/district/network/techtype/requests/PossibleTechTypeKeyName.java
new file mode 100644 (file)
index 0000000..bd4b721
--- /dev/null
@@ -0,0 +1,29 @@
+package org.simantics.district.network.techtype.requests;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.ResourceRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.district.network.ontology.DistrictNetworkResource;
+import org.simantics.layer0.Layer0;
+
+public class PossibleTechTypeKeyName extends ResourceRead<String> {
+       public PossibleTechTypeKeyName(Resource componentType) {
+               super(componentType);
+       }
+
+       @Override
+       public String perform(ReadGraph graph) throws DatabaseException {
+               Layer0 L0 = Layer0.getInstance(graph);
+               DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+               
+               for (Resource r : graph.getObjects(resource, L0.DomainOf)) {
+                       Resource accessor = graph.getPossibleObject(r, L0.valueAccessor);
+                       if (accessor.equals(DN.TechType_Functions_techTypeCodeValueAccessor)) {
+                               return graph.getRelatedValue2(r, L0.HasName);
+                       }
+               }
+               
+               return null;
+       }
+}