]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/SimpleSchema.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.objmap2 / src / org / simantics / objmap / graph / schema / SimpleSchema.java
index 734f101f421eb71e19d616628ab6bc2f5bef4f3b..b7d90433bdc76835d150276feb7d07bdb811c235 100644 (file)
@@ -1,94 +1,94 @@
-/*******************************************************************************\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.graph.schema;\r
-\r
-\r
-import java.util.Stack;\r
-\r
-import gnu.trove.map.hash.THashMap;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.utils.NameUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.objmap.exceptions.MappingException;\r
-\r
-\r
-/**\r
- * An implementation of IMappingSchema that contains\r
- * only SimpleLinkTypes. The link type of any domain\r
- * element is based solely on its type in database and\r
- * the link type of any range element is based on its class.\r
- * @author Hannu Niemistö\r
- */\r
-public class SimpleSchema implements IMappingSchema<Resource,Object> {\r
-\r
-    THashMap<Resource, ILinkType<Resource,Object>> domainLinkTypes = \r
-        new THashMap<Resource, ILinkType<Resource,Object>>();\r
-    THashMap<Class<?>, ILinkType<Resource,Object>> rangeLinkTypes = \r
-        new THashMap<Class<?>, ILinkType<Resource,Object>>();\r
-    \r
-    public void addLinkType(SimpleLinkType<Object> linkType) {\r
-        domainLinkTypes.put(linkType.domainType, linkType);\r
-        rangeLinkTypes.put(linkType.rangeType, linkType);\r
-    }\r
-    \r
-    public void addLinkType(AdaptedLinkType<Object> linkType) {\r
-        domainLinkTypes.put(linkType.domainType, linkType);\r
-        rangeLinkTypes.put(linkType.rangeType, linkType);\r
-    }\r
-    \r
-    @Override\r
-    public ILinkType<Resource,Object> linkTypeOfDomainElement(ReadGraph g, Resource element) throws MappingException {        \r
-        try {\r
-               \r
-               for(Resource type : g.getTypes(element)) {\r
-\r
-                       ILinkType<Resource,Object> linkType = domainLinkTypes.get(type);\r
-                       if(linkType != null) return linkType;\r
-                       \r
-               }\r
-               \r
-               throw new MappingException("Didn't find a link type for " +     NameUtils.getSafeName(g, element) + ".");\r
-                               \r
-        } catch (DatabaseException e) {\r
-            throw new MappingException(e);\r
-        }\r
-    }\r
-\r
-    @Override\r
-    public ILinkType<Resource,Object> linkTypeOfRangeElement(Object element) throws MappingException {\r
-       ILinkType<Resource,Object> type = rangeLinkTypes.get(element.getClass());\r
-       if(type == null)  {\r
-               Stack<Class<?>> clazzes = new Stack<Class<?>>();\r
-               for (Class<?> clazz : element.getClass().getInterfaces()) {\r
-                       clazzes.add(clazz);\r
-               }\r
-               clazzes.add(element.getClass().getSuperclass());\r
-               \r
-               \r
-                       while (!clazzes.isEmpty()) {\r
-                               Class<?> clazz = clazzes.pop();\r
-                       \r
-                               type = rangeLinkTypes.get(clazz);\r
-                               if (type != null)\r
-                                       return type;\r
-                               for (Class<?> c : clazz.getInterfaces())\r
-                                       clazzes.add(c);\r
-                               \r
-                       }\r
-                       throw new MappingException("Didn't find a link type for " +     element.getClass() + ".");\r
-               }\r
-               return type;\r
-    }\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.graph.schema;
+
+
+import java.util.Stack;
+
+import gnu.trove.map.hash.THashMap;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.objmap.exceptions.MappingException;
+
+
+/**
+ * An implementation of IMappingSchema that contains
+ * only SimpleLinkTypes. The link type of any domain
+ * element is based solely on its type in database and
+ * the link type of any range element is based on its class.
+ * @author Hannu Niemistö
+ */
+public class SimpleSchema implements IMappingSchema<Resource,Object> {
+
+    THashMap<Resource, ILinkType<Resource,Object>> domainLinkTypes = 
+        new THashMap<Resource, ILinkType<Resource,Object>>();
+    THashMap<Class<?>, ILinkType<Resource,Object>> rangeLinkTypes = 
+        new THashMap<Class<?>, ILinkType<Resource,Object>>();
+    
+    public void addLinkType(SimpleLinkType<Object> linkType) {
+        domainLinkTypes.put(linkType.domainType, linkType);
+        rangeLinkTypes.put(linkType.rangeType, linkType);
+    }
+    
+    public void addLinkType(AdaptedLinkType<Object> linkType) {
+        domainLinkTypes.put(linkType.domainType, linkType);
+        rangeLinkTypes.put(linkType.rangeType, linkType);
+    }
+    
+    @Override
+    public ILinkType<Resource,Object> linkTypeOfDomainElement(ReadGraph g, Resource element) throws MappingException {        
+        try {
+               
+               for(Resource type : g.getTypes(element)) {
+
+                       ILinkType<Resource,Object> linkType = domainLinkTypes.get(type);
+                       if(linkType != null) return linkType;
+                       
+               }
+               
+               throw new MappingException("Didn't find a link type for " +     NameUtils.getSafeName(g, element) + ".");
+                               
+        } catch (DatabaseException e) {
+            throw new MappingException(e);
+        }
+    }
+
+    @Override
+    public ILinkType<Resource,Object> linkTypeOfRangeElement(Object element) throws MappingException {
+       ILinkType<Resource,Object> type = rangeLinkTypes.get(element.getClass());
+       if(type == null)  {
+               Stack<Class<?>> clazzes = new Stack<Class<?>>();
+               for (Class<?> clazz : element.getClass().getInterfaces()) {
+                       clazzes.add(clazz);
+               }
+               clazzes.add(element.getClass().getSuperclass());
+               
+               
+                       while (!clazzes.isEmpty()) {
+                               Class<?> clazz = clazzes.pop();
+                       
+                               type = rangeLinkTypes.get(clazz);
+                               if (type != null)
+                                       return type;
+                               for (Class<?> c : clazz.getInterfaces())
+                                       clazzes.add(c);
+                               
+                       }
+                       throw new MappingException("Didn't find a link type for " +     element.getClass() + ".");
+               }
+               return type;
+    }
+
+}