]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/EntityRemover.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / adapter / impl / EntityRemover.java
index ce0b44af74dbd9f2a248b99ba34358f932afbdb5..8dc9f6df00343f0cd8c768b55f880a29ce105cfc 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.layer0.adapter.impl;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.List;\r
-\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Statement;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.adapter.Remover;\r
-import org.simantics.db.layer0.exception.CannotRemoveException;\r
-import org.simantics.db.layer0.util.Layer0Utils;\r
-import org.simantics.layer0.Layer0;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class EntityRemover extends AbstractRemover {\r
-\r
-    public EntityRemover(Resource resource) {\r
-        super(resource);\r
-    }\r
-\r
-    @Override\r
-    public void remove(WriteGraph graph) throws DatabaseException {\r
-        remove(graph, resource, true);\r
-    }\r
-\r
-    public static void remove(WriteGraph graph, Resource resource) throws DatabaseException {\r
-        remove(graph, resource, true);\r
-    }\r
-\r
-    public static void remove(WriteGraph graph, Resource resource, boolean useAdapters) throws DatabaseException {\r
-\r
-        // Safety check\r
-        if (graph.isImmutable(resource))\r
-            throw new CannotRemoveException("Cannot remove immutable resources!");\r
-        \r
-        if (Layer0Utils.isContainerPublished(graph, resource))\r
-               throw new CannotRemoveException("Items in published libraries cannot be removed. Please create a new version to perform modifications.");\r
-\r
-        Layer0 l0 = Layer0.getInstance(graph);\r
-        Collection<Statement> stms = graph.getStatements(resource, l0.IsWeaklyRelatedTo);\r
-\r
-        List<Resource> composedOf = null;\r
-\r
-        // Remove the resource to the best of our ability.\r
-        // NOTE: this doesn't work correctly for ordered sets, which must be removed using\r
-        // OrderedSetUtils.\r
-        for (Statement stm : stms) {\r
-\r
-            Resource subject = stm.getSubject();\r
-\r
-            if (resource.equals(stm.getSubject())) {\r
-                Resource predicate = stm.getPredicate();\r
-                Resource object = stm.getObject();\r
-\r
-                Resource inverse = graph.getPossibleInverse(predicate);\r
-                graph.deny(subject, predicate, inverse, object);\r
-\r
-                // TODO: deny value/file related to subject too ??\r
-                graph.denyValue(subject);\r
-\r
-                if (!resource.equals(object) && graph.isSubrelationOf(predicate, l0.IsComposedOf)) {\r
-                    // Only remove entities that are not explicitly\r
-                    // defined as a part of something else when dealing with\r
-                    // L0.HasProperty.\r
-                    // TODO: This logic is a temporary workaround for ontology\r
-                    // problems. It will change in the future when we change\r
-                    // HasProperty to inherit DependsOn instead of IsComposedOf.\r
-                    if (graph.isSubrelationOf(predicate, l0.HasProperty)) {\r
-                        Resource partOf = graph.getPossibleObject(object, l0.PartOf);\r
-                        if (partOf != null && !partOf.equals(resource))\r
-                            continue;\r
-                    }\r
-\r
-                    if (composedOf == null)\r
-                        composedOf = new ArrayList<Resource>(stms.size());\r
-                    composedOf.add(object);\r
-                }\r
-            }\r
-        }\r
-\r
-        if (composedOf == null)\r
-            return;\r
-\r
-        // Recursively remove the objects this resource is composed of.\r
-        for (Resource object : composedOf) {\r
-            Remover remover = null;\r
-            if (useAdapters)\r
-                remover = graph.getPossibleAdapter(object, Remover.class);\r
-\r
-            if (remover != null)\r
-                remover.remove(graph);\r
-            else\r
-                remove(graph, object, useAdapters);\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.layer0.adapter.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.simantics.db.Resource;
+import org.simantics.db.Statement;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.Remover;
+import org.simantics.db.layer0.exception.CannotRemoveException;
+import org.simantics.db.layer0.util.Layer0Utils;
+import org.simantics.layer0.Layer0;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class EntityRemover extends AbstractRemover {
+
+    public EntityRemover(Resource resource) {
+        super(resource);
+    }
+
+    @Override
+    public void remove(WriteGraph graph) throws DatabaseException {
+        remove(graph, resource, true);
+    }
+
+    public static void remove(WriteGraph graph, Resource resource) throws DatabaseException {
+        remove(graph, resource, true);
+    }
+
+    public static void remove(WriteGraph graph, Resource resource, boolean useAdapters) throws DatabaseException {
+
+        // Safety check
+        if (graph.isImmutable(resource))
+            throw new CannotRemoveException("Cannot remove immutable resources!");
+        
+        if (Layer0Utils.isContainerPublished(graph, resource))
+               throw new CannotRemoveException("Items in published libraries cannot be removed. Please create a new version to perform modifications.");
+
+        Layer0 l0 = Layer0.getInstance(graph);
+        Collection<Statement> stms = graph.getStatements(resource, l0.IsWeaklyRelatedTo);
+
+        List<Resource> composedOf = null;
+
+        // Remove the resource to the best of our ability.
+        // NOTE: this doesn't work correctly for ordered sets, which must be removed using
+        // OrderedSetUtils.
+        for (Statement stm : stms) {
+
+            Resource subject = stm.getSubject();
+
+            if (resource.equals(stm.getSubject())) {
+                Resource predicate = stm.getPredicate();
+                Resource object = stm.getObject();
+
+                Resource inverse = graph.getPossibleInverse(predicate);
+                graph.deny(subject, predicate, inverse, object);
+
+                // TODO: deny value/file related to subject too ??
+                graph.denyValue(subject);
+
+                if (!resource.equals(object) && graph.isSubrelationOf(predicate, l0.IsComposedOf)) {
+                    // Only remove entities that are not explicitly
+                    // defined as a part of something else when dealing with
+                    // L0.HasProperty.
+                    // TODO: This logic is a temporary workaround for ontology
+                    // problems. It will change in the future when we change
+                    // HasProperty to inherit DependsOn instead of IsComposedOf.
+                    if (graph.isSubrelationOf(predicate, l0.HasProperty)) {
+                        Resource partOf = graph.getPossibleObject(object, l0.PartOf);
+                        if (partOf != null && !partOf.equals(resource))
+                            continue;
+                    }
+
+                    if (composedOf == null)
+                        composedOf = new ArrayList<Resource>(stms.size());
+                    composedOf.add(object);
+                }
+            }
+        }
+
+        if (composedOf == null)
+            return;
+
+        // Recursively remove the objects this resource is composed of.
+        for (Resource object : composedOf) {
+            Remover remover = null;
+            if (useAdapters)
+                remover = graph.getPossibleAdapter(object, Remover.class);
+
+            if (remover != null)
+                remover.remove(graph);
+            else
+                remove(graph, object, useAdapters);
+        }
+    }
+
+}