]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/DefaultSchema.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.objmap2 / src / org / simantics / objmap / graph / schema / DefaultSchema.java
index e5adac845ad937c3d9bcfeb68ffaf1b19c76034d..0c81090079b5b3808ad91243a2405714a5c838e3 100644 (file)
@@ -1,98 +1,98 @@
-/*******************************************************************************\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
-\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
- * \r
- */\r
-public class DefaultSchema 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 " +\r
-                               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
-                       for (Class<?> clazz : element.getClass().getInterfaces()) {\r
-                               type = rangeLinkTypes.get(clazz);\r
-                               if (type != null)\r
-                                       return type;\r
-                               \r
-                       }\r
-                       throw new MappingException("Didn't find a link type for " +     element + ".");\r
-               }\r
-               return type;\r
-    }\r
-\r
-    \r
-    public ILinkType<Resource,Object> linkTypeOfDomainType(ReadGraph g, Resource type)  {        \r
-       return domainLinkTypes.get(type);\r
-    }\r
-    \r
-    public ILinkType<Resource,Object> linkTypeOfRangeType(Class<?> clazz) {\r
-       ILinkType<Resource,Object> type = rangeLinkTypes.get(clazz);\r
-       if(type == null)  {\r
-               // FIXME: c is not referenced at all, should it be?\r
-               // TODO: should this method take inheritance into account ?\r
-                       for (Class<?> c : clazz.getInterfaces()) {\r
-                               type = rangeLinkTypes.get(clazz);\r
-                               if (type != null)\r
-                                       return type;\r
-                               \r
-                       }\r
-               }\r
-       return null;\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 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;
+
+
+/**
+ * 
+ */
+public class DefaultSchema 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)  {
+                       for (Class<?> clazz : element.getClass().getInterfaces()) {
+                               type = rangeLinkTypes.get(clazz);
+                               if (type != null)
+                                       return type;
+                               
+                       }
+                       throw new MappingException("Didn't find a link type for " +     element + ".");
+               }
+               return type;
+    }
+
+    
+    public ILinkType<Resource,Object> linkTypeOfDomainType(ReadGraph g, Resource type)  {        
+       return domainLinkTypes.get(type);
+    }
+    
+    public ILinkType<Resource,Object> linkTypeOfRangeType(Class<?> clazz) {
+       ILinkType<Resource,Object> type = rangeLinkTypes.get(clazz);
+       if(type == null)  {
+               // FIXME: c is not referenced at all, should it be?
+               // TODO: should this method take inheritance into account ?
+                       for (Class<?> c : clazz.getInterfaces()) {
+                               type = rangeLinkTypes.get(clazz);
+                               if (type != null)
+                                       return type;
+                               
+                       }
+               }
+       return null;
+    }
+}