]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.common/src/org/simantics/db/common/request/MappedPartsAsync.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / request / MappedPartsAsync.java
index d5d672399d586afc99a0c8872e4716ec07bc08db..dc21b99f2a585111a5fad0009a01c631c8b433cb 100644 (file)
-/*******************************************************************************\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.HashMap;\r
-import java.util.Map;\r
-\r
-import org.simantics.db.AsyncReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.ProcedureBarrier;\r
-import org.simantics.db.procedure.AsyncMultiProcedure;\r
-import org.simantics.db.procedure.AsyncProcedure;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.operation.Layer0X;\r
-\r
-public class MappedPartsAsync extends ResourceAsyncRead<Map<Resource, Resource>> {\r
-\r
-    public MappedPartsAsync(Resource realization) {\r
-        super(realization);\r
-    }\r
-    \r
-    @Override\r
-    public void perform(AsyncReadGraph graph, final AsyncProcedure<Map<Resource, Resource>> procedure) {\r
-\r
-       final Layer0 L0 = graph.getService(Layer0.class);\r
-       final Layer0X L0X = graph.getService(Layer0X.class);\r
-       final HashMap<Resource, Resource> result = new HashMap<Resource, Resource>();\r
-       final ProcedureBarrier<Map<Resource, Resource>> ready = new ProcedureBarrier<Map<Resource, Resource>>(1);\r
-       \r
-       graph.forEachObject(resource, L0.ConsistsOf, new AsyncMultiProcedure<Resource>() {\r
-\r
-                       @Override\r
-                       public void execute(AsyncReadGraph graph, final Resource object) {\r
-                               \r
-                               ready.incrementAndGet();\r
-                               \r
-                               graph.forEachObject(object, L0X.Represents, new AsyncMultiProcedure<Resource>() {\r
-\r
-                                       @Override\r
-                                       public void execute(AsyncReadGraph graph, Resource mapped) {\r
-\r
-                                               synchronized(result) {\r
-                                                       result.put(mapped, object);\r
-                                               }\r
-\r
-                                       }\r
-\r
-                                       @Override\r
-                                       public void finished(AsyncReadGraph graph) {\r
-\r
-                                               ready.dec(graph, procedure, result);\r
-\r
-                                       }\r
-\r
-                                       @Override\r
-                                       public void exception(AsyncReadGraph graph, Throwable throwable) {\r
-\r
-                                               ready.except(throwable);\r
-                                               ready.dec(graph, procedure, result);\r
-\r
-                                       }\r
-\r
-                               });\r
-                               \r
-                       }\r
-\r
-                       @Override\r
-                       public void finished(AsyncReadGraph graph) {\r
-                               \r
-                               ready.dec(graph, procedure, result);\r
-                               \r
-                       }\r
-\r
-                       @Override\r
-                       public void exception(AsyncReadGraph graph, Throwable throwable) {\r
-                               \r
-                               ready.except(throwable);\r
-                               ready.dec(graph, procedure, result);\r
-                               \r
-                       }\r
-               \r
-       });\r
-       \r
-    }\r
-    \r
-//    @Override\r
-//    public Map<Resource, Resource> perform(ReadGraph graph) throws DatabaseException {\r
-//        \r
-//        Builtins b = graph.getBuiltins();\r
-//        Map<Resource, Resource> result = new HashMap<Resource, Resource>();\r
-//        \r
-//        for(Resource part : graph.syncRequest(new ObjectsWithType(resource, b.ConsistsOf, resource2))) {\r
-//             Resource represents = graph.getPossibleObject(part, b.Represents);\r
-//             if(represents != null) result.put(represents, part);\r
-//        }\r
-//        \r
-//        return result;\r
-//        \r
-//    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.common.request;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.ProcedureBarrier;
+import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.AsyncProcedure;
+import org.simantics.layer0.Layer0;
+import org.simantics.operation.Layer0X;
+
+public class MappedPartsAsync extends ResourceAsyncRead<Map<Resource, Resource>> {
+
+    public MappedPartsAsync(Resource realization) {
+        super(realization);
+    }
+    
+    @Override
+    public void perform(AsyncReadGraph graph, final AsyncProcedure<Map<Resource, Resource>> procedure) {
+
+       final Layer0 L0 = graph.getService(Layer0.class);
+       final Layer0X L0X = graph.getService(Layer0X.class);
+       final HashMap<Resource, Resource> result = new HashMap<Resource, Resource>();
+       final ProcedureBarrier<Map<Resource, Resource>> ready = new ProcedureBarrier<Map<Resource, Resource>>(1);
+       
+       graph.forEachObject(resource, L0.ConsistsOf, new AsyncMultiProcedure<Resource>() {
+
+                       @Override
+                       public void execute(AsyncReadGraph graph, final Resource object) {
+                               
+                               ready.incrementAndGet();
+                               
+                               graph.forEachObject(object, L0X.Represents, new AsyncMultiProcedure<Resource>() {
+
+                                       @Override
+                                       public void execute(AsyncReadGraph graph, Resource mapped) {
+
+                                               synchronized(result) {
+                                                       result.put(mapped, object);
+                                               }
+
+                                       }
+
+                                       @Override
+                                       public void finished(AsyncReadGraph graph) {
+
+                                               ready.dec(graph, procedure, result);
+
+                                       }
+
+                                       @Override
+                                       public void exception(AsyncReadGraph graph, Throwable throwable) {
+
+                                               ready.except(throwable);
+                                               ready.dec(graph, procedure, result);
+
+                                       }
+
+                               });
+                               
+                       }
+
+                       @Override
+                       public void finished(AsyncReadGraph graph) {
+                               
+                               ready.dec(graph, procedure, result);
+                               
+                       }
+
+                       @Override
+                       public void exception(AsyncReadGraph graph, Throwable throwable) {
+                               
+                               ready.except(throwable);
+                               ready.dec(graph, procedure, result);
+                               
+                       }
+               
+       });
+       
+    }
+    
+//    @Override
+//    public Map<Resource, Resource> perform(ReadGraph graph) throws DatabaseException {
+//        
+//        Builtins b = graph.getBuiltins();
+//        Map<Resource, Resource> result = new HashMap<Resource, Resource>();
+//        
+//        for(Resource part : graph.syncRequest(new ObjectsWithType(resource, b.ConsistsOf, resource2))) {
+//             Resource represents = graph.getPossibleObject(part, b.Represents);
+//             if(represents != null) result.put(represents, part);
+//        }
+//        
+//        return result;
+//        
+//    }
+
+}