]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/UnescapedPropertyMapOfResource.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / request / UnescapedPropertyMapOfResource.java
diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/UnescapedPropertyMapOfResource.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/UnescapedPropertyMapOfResource.java
new file mode 100644 (file)
index 0000000..ddddd34
--- /dev/null
@@ -0,0 +1,48 @@
+/*******************************************************************************\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.layer0.request;\r
+\r
+import gnu.trove.map.hash.THashMap;\r
+\r
+import java.util.Collection;\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.ResourceRead;\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+public class UnescapedPropertyMapOfResource extends ResourceRead<Map<String, PropertyInfo>> {\r
+\r
+       public UnescapedPropertyMapOfResource(Resource resource) {\r
+           super(resource);\r
+       }\r
+\r
+       @Override\r
+       public Map<String,PropertyInfo> perform(ReadGraph graph) throws DatabaseException {\r
+\r
+               Collection<Resource> predicates = graph.getPredicates(resource); \r
+        THashMap<String, PropertyInfo> result = new THashMap<String, PropertyInfo>(predicates.size());\r
+               for(Resource predicate : predicates) {\r
+                       PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(predicate), TransientCacheAsyncListener.<PropertyInfo>instance());\r
+                       if(info != null && info.isHasProperty) {\r
+                       String name = info.name;\r
+                       if (result.put(name, info) != null)\r
+                               System.err.println(this + ": The database resource $" + resource.getResourceId() + " contains siblings with the same name " + name + " (resource=$" + info.predicate.getResourceId() +").");\r
+                       }                               \r
+               }\r
+               return result;\r
+               \r
+       }\r
+       \r
+}\r