--- /dev/null
+/*******************************************************************************\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.annotations;\r
+\r
+import java.lang.annotation.ElementType;\r
+import java.lang.annotation.Retention;\r
+import java.lang.annotation.RetentionPolicy;\r
+import java.lang.annotation.Target;\r
+\r
+@Retention(RetentionPolicy.RUNTIME)\r
+@Target(ElementType.TYPE) \r
+public @interface OrderedSetType {\r
+ String value();\r
+}\r
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.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
\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
--- /dev/null
+package org.simantics.objmap.graph.schema;\r
+\r
+import java.util.ArrayList;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.objmap.bidirectional.IBidirectionalMappingRule;\r
+import org.simantics.objmap.exceptions.MappingException;\r
+\r
+public class OrderedSetSimpleLinkType<Range> extends SimpleLinkType<Range> {\r
+\r
+ public OrderedSetSimpleLinkType(Resource domainType, Class<?> rangeType, ArrayList<IBidirectionalMappingRule<Resource, Range>> rules) {\r
+ super(domainType, rangeType, rules);\r
+ }\r
+\r
+ public OrderedSetSimpleLinkType(Resource domainType, Class<?> rangeType) {\r
+ super(domainType, rangeType);\r
+ }\r
+ \r
+ public Resource createDomainElement(org.simantics.db.WriteGraph g, Range rangeElement) throws org.simantics.objmap.exceptions.MappingException {\r
+ try {\r
+ if(LOGGER.isInfoEnabled())\r
+ LOGGER.info("SimpleLinkType.createDomainElement " +\r
+ rangeElement.toString()\r
+ );\r
+ Resource result = OrderedSetUtils.create(g, domainType);\r
+ return result;\r
+ } catch(DatabaseException e) {\r
+ throw new MappingException(e);\r
+ }\r
+ };\r
+\r
+}\r
import java.util.Collection;\r
\r
import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.objmap.bidirectional.IBidirectionalMappingRule;\r
import org.simantics.objmap.graph.annotations.GraphType;\r
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.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
import org.simantics.objmap.graph.annotations.RelatedOrderedSetElements;\r
import org.simantics.objmap.graph.annotations.RelatedValue;\r
import org.simantics.objmap.graph.annotations.UpdateMethod;\r
+import org.simantics.objmap.graph.annotations.meta.IsClassRule;\r
+import org.simantics.objmap.graph.annotations.meta.IsCollectionRule;\r
+import org.simantics.objmap.graph.annotations.meta.IsFieldRule;\r
+import org.simantics.objmap.graph.annotations.meta.IsGetSetRule;\r
+import org.simantics.objmap.graph.annotations.meta.IsMethodRule;\r
+import org.simantics.objmap.graph.rules.factory.IClassRuleFactory;\r
+import org.simantics.objmap.graph.rules.factory.ICollectionRuleFactory;\r
+import org.simantics.objmap.graph.rules.factory.IFieldRuleFactory;\r
+import org.simantics.objmap.graph.rules.factory.IGetSetRuleFactory;\r
+import org.simantics.objmap.graph.rules.factory.IMethodRuleFactory;\r
+import org.simantics.objmap.structural.IStructuralObject;\r
+import org.simantics.objmap.structural.StructuralResource;\r
import org.simantics.objmap.structural.annotations.StructuralRelatedElementsGet;\r
import org.simantics.objmap.structural.annotations.StructuralRelatedGetObj;\r
import org.simantics.objmap.structural.annotations.TypeRelatedElementsGet;\r
import org.simantics.objmap.structural.annotations.factories.TypeRelatedGetSetObjRuleFactory;\r
import org.simantics.objmap.structural.annotations.factories.TypeRelatedGetSetValueRuleFactory;\r
import org.simantics.objmap.structural.annotations.factories.UpdateMethodFactory;\r
-import org.simantics.objmap.graph.annotations.meta.IsClassRule;\r
-import org.simantics.objmap.graph.annotations.meta.IsCollectionRule;\r
-import org.simantics.objmap.graph.annotations.meta.IsFieldRule;\r
-import org.simantics.objmap.graph.annotations.meta.IsGetSetRule;\r
-import org.simantics.objmap.graph.annotations.meta.IsMethodRule;\r
-import org.simantics.objmap.graph.rules.factory.IClassRuleFactory;\r
-import org.simantics.objmap.graph.rules.factory.ICollectionRuleFactory;\r
-import org.simantics.objmap.graph.rules.factory.IFieldRuleFactory;\r
-import org.simantics.objmap.graph.rules.factory.IGetSetRuleFactory;\r
-import org.simantics.objmap.graph.rules.factory.IMethodRuleFactory;\r
-import org.simantics.objmap.structural.IStructuralObject;\r
-import org.simantics.objmap.structural.StructuralResource;\r
\r
\r
public class MappingSchemas {\r
public static SimpleLinkType fromAnnotations(ReadGraph g, Class<?> clazz) throws DatabaseException, InstantiationException, IllegalAccessException {\r
GraphType graphType = clazz.getAnnotation(GraphType.class);\r
\r
- ArrayList<IBidirectionalMappingRule<StructuralResource, IStructuralObject>> rules = new ArrayList<IBidirectionalMappingRule<StructuralResource, IStructuralObject>>();\r
- collectRulesFromAnnotations(g, clazz, rules);\r
- \r
- return new SimpleLinkType(\r
- g.getResource(graphType.value()), \r
- clazz, rules); \r
+ if (graphType != null) {\r
+ ArrayList<IBidirectionalMappingRule<StructuralResource, IStructuralObject>> rules = new ArrayList<IBidirectionalMappingRule<StructuralResource, IStructuralObject>>();\r
+ collectRulesFromAnnotations(g, clazz, rules);\r
+ \r
+ return new SimpleLinkType(g.getResource(graphType.value()), clazz, rules); \r
+ }\r
+ OrderedSetType orderedSetType = clazz.getAnnotation(OrderedSetType.class);\r
+ if (orderedSetType != null) {\r
+ ArrayList<IBidirectionalMappingRule<StructuralResource, IStructuralObject>> rules = new ArrayList<IBidirectionalMappingRule<StructuralResource, IStructuralObject>>();\r
+ collectRulesFromAnnotations(g, clazz, rules);\r
+ \r
+ return new OrderedSetSimpleLinkType(g.getResource(orderedSetType.value()), clazz, rules);\r
+ }\r
+ throw new IllegalArgumentException("Class " + clazz.toString() + " does not contain annotations.");\r
}\r
\r
public static void collectRulesFromAnnotations(ReadGraph g, Class<?> clazz, Collection<IBidirectionalMappingRule<StructuralResource, IStructuralObject>> rules) throws DatabaseException, InstantiationException, IllegalAccessException {\r
--- /dev/null
+package org.simantics.objmap.structural.schema;\r
+\r
+import java.util.ArrayList;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.objmap.bidirectional.IBidirectionalMappingRule;\r
+import org.simantics.objmap.structural.IStructuralObject;\r
+import org.simantics.objmap.structural.StructuralResource;\r
+\r
+public class OrderedSetSimpleLinkType extends SimpleLinkType {\r
+\r
+ public OrderedSetSimpleLinkType(Resource domainType, Class<?> rangeType, ArrayList<IBidirectionalMappingRule<StructuralResource, IStructuralObject>> rules) {\r
+ super(domainType, rangeType, rules);\r
+ }\r
+\r
+ public OrderedSetSimpleLinkType(Resource domainType, Class<?> rangeType) {\r
+ super(domainType, rangeType);\r
+ }\r
+ \r
+ @Override\r
+ protected Resource newResource(WriteGraph g, Resource type) throws DatabaseException {\r
+ return OrderedSetUtils.create(g, type);\r
+ }\r
+\r
+}\r
);\r
if (rangeElement.getContext().size() == 0) {\r
// there is no context, this not a structural resource / object.\r
- Resource result = g.newResource();\r
- g.claim(result, Layer0.getInstance(g).InstanceOf, null, domainType);\r
+ Resource result = newResource(g, domainType);\r
return new StructuralResource(g,result);\r
} else {\r
if (rangeElement.getContext().size() == 1 && rangeElement.getContext().get(0).equals(rangeElement)) {\r
// Structural object's context is itself, we are instantiating a new structural model.\r
Resource type = rangeElement.getType();\r
- Resource result = g.newResource();\r
- g.claim(result, Layer0.getInstance(g).InstanceOf, null, type);\r
+ Resource result = newResource(g, type);\r
return new StructuralResource(g,result,result);\r
} else {\r
// Structural object's context is not itself, which means that the object is inside of a structural model.\r
throw new MappingException(e);\r
}\r
}\r
+ \r
+ protected Resource newResource(WriteGraph g, Resource type) throws DatabaseException {\r
+ Resource result = g.newResource();\r
+ g.claim(result, Layer0.getInstance(g).InstanceOf, null, type);\r
+ return result;\r
+ }\r
@Override\r
public IStructuralObject createRangeElement(ReadGraph g, StructuralResource domainElement)\r
throws MappingException {\r