X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.objmap2%2Fsrc%2Forg%2Fsimantics%2Fobjmap%2Fstructural%2Fschema%2FMappingSchemas.java;h=3f9169ec9f569bdbb57b42a5d8804114066ad87d;hb=7f13bdbb446dbb0c055a134d38295cd5d54b67c3;hp=c656368f1fb2ee0d1f2d1e61bdd031995b53a8f7;hpb=87b3241ec277ba3d8e414b26186a032c9cdcaeed;p=simantics%2F3d.git diff --git a/org.simantics.objmap2/src/org/simantics/objmap/structural/schema/MappingSchemas.java b/org.simantics.objmap2/src/org/simantics/objmap/structural/schema/MappingSchemas.java index c656368f..3f9169ec 100644 --- a/org.simantics.objmap2/src/org/simantics/objmap/structural/schema/MappingSchemas.java +++ b/org.simantics.objmap2/src/org/simantics/objmap/structural/schema/MappingSchemas.java @@ -1,3 +1,14 @@ +/******************************************************************************* + * 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.schema; import java.lang.annotation.Annotation; @@ -7,7 +18,6 @@ import java.util.ArrayList; import java.util.Collection; import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; import org.simantics.objmap.bidirectional.IBidirectionalMappingRule; import org.simantics.objmap.graph.annotations.GraphType; @@ -15,6 +25,7 @@ import org.simantics.objmap.graph.annotations.HasCollectionAdder; import org.simantics.objmap.graph.annotations.HasCollectionRemover; import org.simantics.objmap.graph.annotations.HasSetter; import org.simantics.objmap.graph.annotations.OptionalRelatedElements; +import org.simantics.objmap.graph.annotations.OrderedSetType; import org.simantics.objmap.graph.annotations.RelatedElements; import org.simantics.objmap.graph.annotations.RelatedElementsGet; import org.simantics.objmap.graph.annotations.RelatedGetObj; @@ -22,6 +33,18 @@ import org.simantics.objmap.graph.annotations.RelatedGetValue; import org.simantics.objmap.graph.annotations.RelatedOrderedSetElements; import org.simantics.objmap.graph.annotations.RelatedValue; import org.simantics.objmap.graph.annotations.UpdateMethod; +import org.simantics.objmap.graph.annotations.meta.IsClassRule; +import org.simantics.objmap.graph.annotations.meta.IsCollectionRule; +import org.simantics.objmap.graph.annotations.meta.IsFieldRule; +import org.simantics.objmap.graph.annotations.meta.IsGetSetRule; +import org.simantics.objmap.graph.annotations.meta.IsMethodRule; +import org.simantics.objmap.graph.rules.factory.IClassRuleFactory; +import org.simantics.objmap.graph.rules.factory.ICollectionRuleFactory; +import org.simantics.objmap.graph.rules.factory.IFieldRuleFactory; +import org.simantics.objmap.graph.rules.factory.IGetSetRuleFactory; +import org.simantics.objmap.graph.rules.factory.IMethodRuleFactory; +import org.simantics.objmap.structural.IStructuralObject; +import org.simantics.objmap.structural.StructuralResource; import org.simantics.objmap.structural.annotations.StructuralRelatedElementsGet; import org.simantics.objmap.structural.annotations.StructuralRelatedGetObj; import org.simantics.objmap.structural.annotations.TypeRelatedElementsGet; @@ -40,18 +63,6 @@ import org.simantics.objmap.structural.annotations.factories.TypeRelatedElements import org.simantics.objmap.structural.annotations.factories.TypeRelatedGetSetObjRuleFactory; import org.simantics.objmap.structural.annotations.factories.TypeRelatedGetSetValueRuleFactory; import org.simantics.objmap.structural.annotations.factories.UpdateMethodFactory; -import org.simantics.objmap.graph.annotations.meta.IsClassRule; -import org.simantics.objmap.graph.annotations.meta.IsCollectionRule; -import org.simantics.objmap.graph.annotations.meta.IsFieldRule; -import org.simantics.objmap.graph.annotations.meta.IsGetSetRule; -import org.simantics.objmap.graph.annotations.meta.IsMethodRule; -import org.simantics.objmap.graph.rules.factory.IClassRuleFactory; -import org.simantics.objmap.graph.rules.factory.ICollectionRuleFactory; -import org.simantics.objmap.graph.rules.factory.IFieldRuleFactory; -import org.simantics.objmap.graph.rules.factory.IGetSetRuleFactory; -import org.simantics.objmap.graph.rules.factory.IMethodRuleFactory; -import org.simantics.objmap.structural.IStructuralObject; -import org.simantics.objmap.structural.StructuralResource; public class MappingSchemas { @@ -65,12 +76,20 @@ public class MappingSchemas { public static SimpleLinkType fromAnnotations(ReadGraph g, Class clazz) throws DatabaseException, InstantiationException, IllegalAccessException { GraphType graphType = clazz.getAnnotation(GraphType.class); - ArrayList> rules = new ArrayList>(); - collectRulesFromAnnotations(g, clazz, rules); - - return new SimpleLinkType( - g.getResource(graphType.value()), - clazz, rules); + if (graphType != null) { + ArrayList> rules = new ArrayList>(); + collectRulesFromAnnotations(g, clazz, rules); + + return new SimpleLinkType(g.getResource(graphType.value()), clazz, rules); + } + OrderedSetType orderedSetType = clazz.getAnnotation(OrderedSetType.class); + if (orderedSetType != null) { + ArrayList> rules = new ArrayList>(); + collectRulesFromAnnotations(g, clazz, rules); + + return new OrderedSetSimpleLinkType(g.getResource(orderedSetType.value()), clazz, rules); + } + throw new IllegalArgumentException("Class " + clazz.toString() + " does not contain annotations."); } public static void collectRulesFromAnnotations(ReadGraph g, Class clazz, Collection> rules) throws DatabaseException, InstantiationException, IllegalAccessException {