1 package org.simantics.objmap.structural.annotations.factories;
\r
3 import java.lang.annotation.Annotation;
\r
4 import java.lang.reflect.Method;
\r
6 import org.simantics.db.ReadGraph;
\r
7 import org.simantics.db.exception.DatabaseException;
\r
8 import org.simantics.objmap.bidirectional.IBidirectionalMappingRule;
\r
9 import org.simantics.objmap.graph.annotations.RelatedElementsAdd;
\r
10 import org.simantics.objmap.graph.annotations.RelatedElementsGet;
\r
11 import org.simantics.objmap.graph.annotations.RelatedElementsRem;
\r
12 import org.simantics.objmap.graph.rules.MappedElementsRule;
\r
13 import org.simantics.objmap.graph.rules.factory.ICollectionRuleFactory;
\r
14 import org.simantics.objmap.graph.rules.range.CollectionAccessor;
\r
15 import org.simantics.objmap.structural.StructuralResource;
\r
16 import org.simantics.objmap.structural.rules.domain.RelatedObjectsAccessor;
\r
19 public class RelatedElementsRuleFactory2<Range> implements ICollectionRuleFactory<StructuralResource,Range> {
\r
22 public IBidirectionalMappingRule<StructuralResource, Range> create(ReadGraph g, Annotation annotation,
\r
23 Method getter, Method adder, Method remover)
\r
24 throws DatabaseException {
\r
25 RelatedElementsGet getterAnn = (RelatedElementsGet)annotation;
\r
26 return new MappedElementsRule<StructuralResource,Range>(new RelatedObjectsAccessor(g.getResource(getterAnn.value()),getterAnn.composition(),false,true,false),
\r
27 new CollectionAccessor<Range,Range>(getter, adder, remover));
\r
31 public boolean isAdder(Annotation getterAnnotation, Annotation annotation) {
\r
32 RelatedElementsGet getterAnn = (RelatedElementsGet)getterAnnotation;
\r
33 RelatedElementsAdd adderAnn = (RelatedElementsAdd)annotation;
\r
34 return getterAnn.value().equals(adderAnn.value());
\r
38 public boolean isRemover(Annotation getterAnnotation, Annotation annotation) {
\r
39 RelatedElementsGet getterAnn = (RelatedElementsGet)getterAnnotation;
\r
40 RelatedElementsRem adderAnn = (RelatedElementsRem)annotation;
\r
41 return getterAnn.value().equals(adderAnn.value());
\r