]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.objmap2/src/org/simantics/objmap/graph/schema/MappingSchemas.java
OrderedSet support (graph mappings)
[simantics/3d.git] / org.simantics.objmap2 / src / org / simantics / objmap / graph / schema / MappingSchemas.java
index 6a7d940f626251e1e0e96b7d4949a632bc9f67dd..b863fbadca0d1b2924433edef63266abfa632b8c 100644 (file)
@@ -1,3 +1,14 @@
+/*******************************************************************************\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.graph.schema;\r
 \r
 import java.lang.annotation.Annotation;\r
@@ -17,6 +28,8 @@ import org.simantics.objmap.graph.annotations.HasCollectionAdder;
 import org.simantics.objmap.graph.annotations.HasCollectionRemover;\r
 import org.simantics.objmap.graph.annotations.HasSetter;\r
 import org.simantics.objmap.graph.annotations.OptionalRelatedElements;\r
+import org.simantics.objmap.graph.annotations.OrderedElementsGet;\r
+import org.simantics.objmap.graph.annotations.OrderedSetType;\r
 import org.simantics.objmap.graph.annotations.RelatedElements;\r
 import org.simantics.objmap.graph.annotations.RelatedElementsGet;\r
 import org.simantics.objmap.graph.annotations.RelatedGetObj;\r
@@ -26,6 +39,7 @@ import org.simantics.objmap.graph.annotations.RelatedValue;
 import org.simantics.objmap.graph.annotations.UpdateMethod;\r
 import org.simantics.objmap.graph.annotations.factories.CompoundRelatedGetSetValueRuleFactory;\r
 import org.simantics.objmap.graph.annotations.factories.OptionalRelatedElementsRuleFactory;\r
+import org.simantics.objmap.graph.annotations.factories.OrderedElementsRuleFactory;\r
 import org.simantics.objmap.graph.annotations.factories.RelatedElementsRuleFactory;\r
 import org.simantics.objmap.graph.annotations.factories.RelatedElementsRuleFactory2;\r
 import org.simantics.objmap.graph.annotations.factories.RelatedGetSetObjRuleFactory;\r
@@ -69,6 +83,13 @@ public class MappingSchemas {
                    \r
                    return new DynamicSimpleLinkType<Object>(g.getResource(dynamicType.value()), clazz, rules);\r
            }\r
+           OrderedSetType orderedSetType = clazz.getAnnotation(OrderedSetType.class);\r
+           if (orderedSetType != null) {\r
+               ArrayList<IBidirectionalMappingRule<Resource, Object>> rules = new ArrayList<IBidirectionalMappingRule<Resource, Object>>();\r
+                   collectRulesFromAnnotations(g, clazz, rules);\r
+                   \r
+                   return new OrderedSetSimpleLinkType<Object>(g.getResource(orderedSetType.value()), clazz, rules);\r
+           }\r
            throw new IllegalArgumentException("Class " + clazz.toString() + " does not contain annotations.");\r
        }\r
        \r
@@ -217,6 +238,8 @@ public class MappingSchemas {
        public static ICollectionRuleFactory<Resource,Object> createCollectionRuleFactory(ReadGraph g, Annotation annotation, Method getter) {\r
                if (annotation.annotationType().equals(RelatedElementsGet.class))\r
                        return new RelatedElementsRuleFactory2<Object>();\r
+               if (annotation.annotationType().equals(OrderedElementsGet.class))\r
+                       return new OrderedElementsRuleFactory<Object>();\r
                return null;\r
        }\r
        \r