]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.objmap2/src/org/simantics/objmap/structural/StructuralResource.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.objmap2 / src / org / simantics / objmap / structural / StructuralResource.java
index 857d0e4ade20304652e6b1280f27eb88b4a5e98a..14723cb8090f9f0b302151cfe11a0904f884c9af 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2012, 2013 Association for Decentralized Information Management in\r
- * 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;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.layer0.Layer0;\r
-\r
-/**\r
- * An object representing structural Resource.\r
- * \r
- * \r
- * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
- *\r
- */\r
-public class StructuralResource  {\r
-\r
-       private Resource resource;\r
-       private List<Resource> context = new ArrayList<Resource>(1);\r
-       \r
-       private Resource typeResource = null;\r
-       \r
-       public StructuralResource(Resource resource) {\r
-               assert(resource != null);\r
-               this.resource = resource;\r
-       }\r
-       public StructuralResource(ReadGraph g, Resource resource, Resource context) throws DatabaseException {\r
-               assert(resource != null);\r
-               this.resource = resource;\r
-               this.context.add(context);\r
-               resolveType(g);\r
-       }\r
-       \r
-       public StructuralResource(ReadGraph g, Resource resource, Resource... context) throws DatabaseException {\r
-               assert(resource != null);\r
-               this.resource = resource;\r
-               for (Resource r : context)\r
-                       this.context.add(r);\r
-               resolveType(g);\r
-       }\r
-       \r
-       public StructuralResource(ReadGraph g, Resource resource, List<Resource> context) throws DatabaseException {\r
-               assert(resource != null);\r
-               this.resource = resource;\r
-               for (Resource r : context)\r
-                       this.context.add(r);\r
-               resolveType(g); \r
-       }\r
-       public StructuralResource(ReadGraph g, Resource resource, List<Resource> context, Resource context2) throws DatabaseException {\r
-               assert(resource != null);\r
-               this.resource = resource;\r
-               for (Resource r : context)\r
-                       this.context.add(r);\r
-               this.context.add(context2);\r
-               resolveType(g);\r
-       }\r
-       \r
-       private void resolveType(ReadGraph g) throws DatabaseException {\r
-               if (this.context.contains(resource)) {\r
-                       Layer0 l0 = Layer0.getInstance(g);\r
-                       typeResource = g.getSingleObject(resource, l0.InstanceOf);\r
-               } \r
-       }\r
-       \r
-       \r
-       /**\r
-        * The Resource in the DB.\r
-        * @return\r
-        */\r
-       public Resource getResource() {\r
-               return resource;\r
-       }\r
-       \r
-       /**\r
-        * Context in which this resource is accessed. Each context resource represents a structural model instance. \r
-        * @return\r
-        */\r
-       public List<Resource> getContext() {\r
-               return context;\r
-       }\r
-       \r
-       /**\r
-        * If the resource is structural model instance, this returns the type Resource. Otherwise returns null.\r
-        * @return\r
-        */\r
-       public Resource getTypeResource() {\r
-               return typeResource;\r
-       }\r
-       \r
-       /**\r
-        * Returns true, if the resource is structural, \r
-        * @return\r
-        */\r
-       public boolean isStructural() {\r
-               return context.size() > 0;\r
-       }\r
-       \r
-       /**\r
-        * Returns true is the Resource is root of Structural Model instance.\r
-        * In this case the resource instance is editable.\r
-        * \r
-        * @return\r
-        */\r
-       public boolean isStructuralRoot() {\r
-               return (context.size() == 1 && context.get(0).equals(resource));\r
-       }\r
-       \r
-       /**\r
-        * Returns true,  the resource is structural model instance.\r
-        * @return\r
-        */\r
-       public boolean isStructuralInstance() {\r
-               return typeResource != null;\r
-       }\r
-       \r
-       @Override\r
-       public int hashCode() {\r
-               int hashCode = resource.hashCode();\r
-               for (Resource ctx : context)\r
-                       hashCode += ctx.hashCode();\r
-               return hashCode;\r
-       }\r
-       \r
-       @Override\r
-       public boolean equals(Object obj) {\r
-               if (obj == this)\r
-                       return true;\r
-               if (obj == null)\r
-                       return false;\r
-               if (obj.getClass() != getClass())\r
-                       return false;\r
-               StructuralResource other = (StructuralResource)obj;\r
-               if (!resource.equals(other.resource))\r
-                       return false;\r
-               if (context.size() != other.context.size())\r
-                       return false;\r
-               for (int i = 0; i < context.size(); i++) {\r
-                       if (!context.get(i).equals(other.context.get(i)))\r
-                               return false;\r
-               }\r
-               return true;\r
-       }\r
-       \r
-       @Override\r
-       public String toString() {\r
-               String s = "Res: " + resource + " Context:";\r
-               for (Resource ctx : context) \r
-                       s+= " "+ ctx;\r
-               if (typeResource != null)\r
-                       s+= " Type: " + typeResource;\r
-               return s;\r
-       }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012, 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;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.layer0.Layer0;
+
+/**
+ * An object representing structural Resource.
+ * 
+ * 
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
+ *
+ */
+public class StructuralResource  {
+
+       private Resource resource;
+       private List<Resource> context = new ArrayList<Resource>(1);
+       
+       private Resource typeResource = null;
+       
+       public StructuralResource(Resource resource) {
+               assert(resource != null);
+               this.resource = resource;
+       }
+       public StructuralResource(ReadGraph g, Resource resource, Resource context) throws DatabaseException {
+               assert(resource != null);
+               this.resource = resource;
+               this.context.add(context);
+               resolveType(g);
+       }
+       
+       public StructuralResource(ReadGraph g, Resource resource, Resource... context) throws DatabaseException {
+               assert(resource != null);
+               this.resource = resource;
+               for (Resource r : context)
+                       this.context.add(r);
+               resolveType(g);
+       }
+       
+       public StructuralResource(ReadGraph g, Resource resource, List<Resource> context) throws DatabaseException {
+               assert(resource != null);
+               this.resource = resource;
+               for (Resource r : context)
+                       this.context.add(r);
+               resolveType(g); 
+       }
+       public StructuralResource(ReadGraph g, Resource resource, List<Resource> context, Resource context2) throws DatabaseException {
+               assert(resource != null);
+               this.resource = resource;
+               for (Resource r : context)
+                       this.context.add(r);
+               this.context.add(context2);
+               resolveType(g);
+       }
+       
+       private void resolveType(ReadGraph g) throws DatabaseException {
+               if (this.context.contains(resource)) {
+                       Layer0 l0 = Layer0.getInstance(g);
+                       typeResource = g.getSingleObject(resource, l0.InstanceOf);
+               } 
+       }
+       
+       
+       /**
+        * The Resource in the DB.
+        * @return
+        */
+       public Resource getResource() {
+               return resource;
+       }
+       
+       /**
+        * Context in which this resource is accessed. Each context resource represents a structural model instance. 
+        * @return
+        */
+       public List<Resource> getContext() {
+               return context;
+       }
+       
+       /**
+        * If the resource is structural model instance, this returns the type Resource. Otherwise returns null.
+        * @return
+        */
+       public Resource getTypeResource() {
+               return typeResource;
+       }
+       
+       /**
+        * Returns true, if the resource is structural, 
+        * @return
+        */
+       public boolean isStructural() {
+               return context.size() > 0;
+       }
+       
+       /**
+        * Returns true is the Resource is root of Structural Model instance.
+        * In this case the resource instance is editable.
+        * 
+        * @return
+        */
+       public boolean isStructuralRoot() {
+               return (context.size() == 1 && context.get(0).equals(resource));
+       }
+       
+       /**
+        * Returns true,  the resource is structural model instance.
+        * @return
+        */
+       public boolean isStructuralInstance() {
+               return typeResource != null;
+       }
+       
+       @Override
+       public int hashCode() {
+               int hashCode = resource.hashCode();
+               for (Resource ctx : context)
+                       hashCode += ctx.hashCode();
+               return hashCode;
+       }
+       
+       @Override
+       public boolean equals(Object obj) {
+               if (obj == this)
+                       return true;
+               if (obj == null)
+                       return false;
+               if (obj.getClass() != getClass())
+                       return false;
+               StructuralResource other = (StructuralResource)obj;
+               if (!resource.equals(other.resource))
+                       return false;
+               if (context.size() != other.context.size())
+                       return false;
+               for (int i = 0; i < context.size(); i++) {
+                       if (!context.get(i).equals(other.context.get(i)))
+                               return false;
+               }
+               return true;
+       }
+       
+       @Override
+       public String toString() {
+               String s = "Res: " + resource + " Context:";
+               for (Resource ctx : context) 
+                       s+= " "+ ctx;
+               if (typeResource != null)
+                       s+= " Type: " + typeResource;
+               return s;
+       }
+
+}