]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/rules/domain/RelatedObjectsAccessor.java
Use trace level debug messages with ObjMap
[simantics/platform.git] / bundles / org.simantics.objmap2 / src / org / simantics / objmap / structural / rules / domain / RelatedObjectsAccessor.java
index c56ffb6d1b3fb72e4b5df9c4583e062b2d124933..b09de09b83551a1c9d7427c6e11441d4544b0504 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2013 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.objmap.structural.rules.domain;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.Collections;\r
-import java.util.List;\r
-\r
-import org.apache.log4j.Logger;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.objmap.exceptions.MappingException;\r
-import org.simantics.objmap.graph.rules.domain.IDomainAccessor;\r
-import org.simantics.objmap.graph.rules.domain.MappingUtils;\r
-import org.simantics.objmap.structural.StructuralResource;\r
-\r
-\r
-public class RelatedObjectsAccessor implements IDomainAccessor<StructuralResource,Collection<StructuralResource>> {\r
-\r
-    static Logger LOGGER = Logger.getLogger("org.simantics.objmap");\r
-    \r
-       Resource relation;\r
-       boolean deleteExtraObjects;\r
-       boolean useTypeResource;\r
-       \r
-       private boolean preventStructuralChanges = true;\r
-       private boolean preventStructuralRootChanges = true;\r
-\r
-       public RelatedObjectsAccessor(Resource relation, boolean deleteExtraObjects, boolean useTypeResource) {\r
-        super();\r
-        this.relation = relation;\r
-        this.deleteExtraObjects = deleteExtraObjects;\r
-        this.useTypeResource = useTypeResource;\r
-    }\r
-       \r
-       public RelatedObjectsAccessor(Resource relation, boolean deleteExtraObjects, boolean useTypeResource, boolean preventStructuralChanges, boolean preventStructuralRootChanges) {\r
-        super();\r
-        this.relation = relation;\r
-        this.deleteExtraObjects = deleteExtraObjects;\r
-        this.useTypeResource = useTypeResource;\r
-               this.preventStructuralChanges = preventStructuralChanges;\r
-               this.preventStructuralRootChanges = preventStructuralRootChanges;\r
-    }\r
-\r
-    @Override\r
-       public Collection<StructuralResource> get(ReadGraph g, StructuralResource element) throws MappingException {\r
-               try {\r
-                   LOGGER.info("        RelatedObjectsAccessor.get");\r
-                       \r
-                  \r
-                   Resource res = getServiceResource(g, element);\r
-                   if (res == null)\r
-                       return Collections.emptyList();\r
-                   Collection<Resource> coll = g.getObjects(res, relation);\r
-                       List<StructuralResource> result = new ArrayList<StructuralResource>(coll.size());\r
-                       for (Resource r : coll) {\r
-                               if (StructuralUtils.isStructuralInstance(g, r)) {\r
-                                       result.add(new StructuralResource(g, r, element.getContext(),r));\r
-                               } else {\r
-                                       result.add(new StructuralResource(g, r, element.getContext()));\r
-                               }\r
-                       }\r
-                       return result;\r
-               } catch (DatabaseException e) {\r
-                       throw new MappingException(e);\r
-               }\r
-       }\r
-    \r
-    private boolean preventChange(StructuralResource element) {\r
-       return preventStructuralChanges && element.isStructural() && (!element.isStructuralRoot()||preventStructuralRootChanges);       \r
-    }\r
-       \r
-       @Override\r
-       public boolean set(WriteGraph g, StructuralResource element, Collection<StructuralResource> value)\r
-                       throws MappingException {\r
-               try {\r
-                   LOGGER.info("        RelatedObjectsAccessor.set");\r
-                   Resource res = getServiceResource(g, element);\r
-                   if (res == null)\r
-                       return false;\r
-                   if (preventChange(element))\r
-                               return false;\r
-                   Resource[] arr = new Resource[value.size()];\r
-                   int i = 0; \r
-                   for (StructuralResource sr : value) {\r
-                       arr[i++] = sr.getResource();\r
-                   }\r
-                       return MappingUtils.synchronizeStatements(g, res, relation, \r
-                               arr, deleteExtraObjects);\r
-               } catch (DatabaseException e) {\r
-                       throw new MappingException(e);\r
-               }\r
-               \r
-       }\r
-\r
-       private Resource getServiceResource(ReadGraph g, StructuralResource element) {\r
-               if (!useTypeResource)\r
-                       return element.getResource();\r
-               return element.getTypeResource();\r
-       }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2013 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.objmap.structural.rules.domain;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.objmap.exceptions.MappingException;
+import org.simantics.objmap.graph.rules.domain.IDomainAccessor;
+import org.simantics.objmap.graph.rules.domain.MappingUtils;
+import org.simantics.objmap.structural.StructuralResource;
+
+
+public class RelatedObjectsAccessor implements IDomainAccessor<StructuralResource,Collection<StructuralResource>> {
+
+    static Logger LOGGER = LoggerFactory.getLogger(RelatedObjectsAccessor.class);
+    
+       Resource relation;
+       boolean deleteExtraObjects;
+       boolean useTypeResource;
+       
+       private boolean preventStructuralChanges = true;
+       private boolean preventStructuralRootChanges = true;
+
+       public RelatedObjectsAccessor(Resource relation, boolean deleteExtraObjects, boolean useTypeResource) {
+        super();
+        this.relation = relation;
+        this.deleteExtraObjects = deleteExtraObjects;
+        this.useTypeResource = useTypeResource;
+    }
+       
+       public RelatedObjectsAccessor(Resource relation, boolean deleteExtraObjects, boolean useTypeResource, boolean preventStructuralChanges, boolean preventStructuralRootChanges) {
+        super();
+        this.relation = relation;
+        this.deleteExtraObjects = deleteExtraObjects;
+        this.useTypeResource = useTypeResource;
+               this.preventStructuralChanges = preventStructuralChanges;
+               this.preventStructuralRootChanges = preventStructuralRootChanges;
+    }
+
+    @Override
+       public Collection<StructuralResource> get(ReadGraph g, StructuralResource element) throws MappingException {
+               try {
+                   LOGGER.trace("        RelatedObjectsAccessor.get");
+                       
+                  
+                   Resource res = getServiceResource(g, element);
+                   if (res == null)
+                       return Collections.emptyList();
+                   Collection<Resource> coll = g.getObjects(res, relation);
+                       List<StructuralResource> result = new ArrayList<StructuralResource>(coll.size());
+                       for (Resource r : coll) {
+                               if (StructuralUtils.isStructuralInstance(g, r)) {
+                                       result.add(new StructuralResource(g, r, element.getContext(),r));
+                               } else {
+                                       result.add(new StructuralResource(g, r, element.getContext()));
+                               }
+                       }
+                       return result;
+               } catch (DatabaseException e) {
+                       throw new MappingException(e);
+               }
+       }
+    
+    private boolean preventChange(StructuralResource element) {
+       return preventStructuralChanges && element.isStructural() && (!element.isStructuralRoot()||preventStructuralRootChanges);       
+    }
+       
+       @Override
+       public boolean set(WriteGraph g, StructuralResource element, Collection<StructuralResource> value)
+                       throws MappingException {
+               try {
+                   LOGGER.trace("        RelatedObjectsAccessor.set");
+                   Resource res = getServiceResource(g, element);
+                   if (res == null)
+                       return false;
+                   if (preventChange(element))
+                               return false;
+                   Resource[] arr = new Resource[value.size()];
+                   int i = 0; 
+                   for (StructuralResource sr : value) {
+                       arr[i++] = sr.getResource();
+                   }
+                       return MappingUtils.synchronizeStatements(g, res, relation, 
+                               arr, deleteExtraObjects);
+               } catch (DatabaseException e) {
+                       throw new MappingException(e);
+               }
+               
+       }
+
+       private Resource getServiceResource(ReadGraph g, StructuralResource element) {
+               if (!useTypeResource)
+                       return element.getResource();
+               return element.getTypeResource();
+       }
+}