]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.structural2/src/org/simantics/structural2/queries/ConnectionPointMapOfResource.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.structural2 / src / org / simantics / structural2 / queries / ConnectionPointMapOfResource.java
diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/queries/ConnectionPointMapOfResource.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/queries/ConnectionPointMapOfResource.java
new file mode 100644 (file)
index 0000000..2dff0a7
--- /dev/null
@@ -0,0 +1,68 @@
+/*******************************************************************************\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.structural2.queries;\r
+\r
+import gnu.trove.map.hash.THashMap;\r
+\r
+import java.util.Collection;\r
+import java.util.Collections;\r
+import java.util.Map;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;\r
+import org.simantics.db.common.request.TransientResourceRead;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.request.PropertyInfo;\r
+import org.simantics.db.request.RequestFlags;\r
+import org.simantics.db.service.QueryControl;\r
+\r
+public class ConnectionPointMapOfResource extends TransientResourceRead<Map<String, Resource>> {\r
+\r
+       public ConnectionPointMapOfResource(ReadGraph graph, Resource resource) throws DatabaseException {\r
+           super(graph, resource);\r
+       }\r
+       \r
+       public ConnectionPointMapOfResource(ReadGraph graph, QueryControl qc, Resource resource) throws DatabaseException {\r
+               super(graph, qc, resource);\r
+       }\r
+\r
+       @Override\r
+       public Map<String,Resource> perform(ReadGraph graph, Resource resource) throws DatabaseException {\r
+           \r
+               Collection<Resource> predicates = graph.getPredicates(resource);\r
+               \r
+               THashMap<String,Resource> result = null;\r
+               \r
+               for(Resource predicate : predicates) {\r
+                       \r
+                       PropertyInfo info = graph.syncRequest(new PossibleConnectionPointInfo(predicate), TransientCacheAsyncListener.<PropertyInfo>instance());\r
+                       if(info != null) {\r
+                               if (result == null) result = new THashMap<String,Resource>(predicates.size());\r
+                               if (result.put(info.name, predicate) != null)\r
+                                       System.err.println(this + ": The database contains siblings with the same name " + info.name + " (resource=$" + resource.getResourceId() + ").");\r
+                       }                               \r
+                       \r
+               }\r
+\r
+               if(result != null) return result;\r
+               \r
+               else return Collections.emptyMap();\r
+                       \r
+       }\r
+       \r
+       @Override\r
+       public int getType() {\r
+               return RequestFlags.INVALIDATE;\r
+       }\r
+       \r
+}\r