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.rules.MappedElementsRule;
\r
10 import org.simantics.objmap.graph.rules.factory.ICollectionRuleFactory;
\r
11 import org.simantics.objmap.graph.rules.range.CollectionAccessor;
\r
12 import org.simantics.objmap.structural.StructuralResource;
\r
13 import org.simantics.objmap.structural.annotations.TypeRelatedElementsAdd;
\r
14 import org.simantics.objmap.structural.annotations.TypeRelatedElementsGet;
\r
15 import org.simantics.objmap.structural.annotations.TypeRelatedElementsRem;
\r
16 import org.simantics.objmap.structural.rules.domain.RelatedObjectsAccessor;
\r
19 public class TypeRelatedElementsRuleFactory2<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 TypeRelatedElementsGet getterAnn = (TypeRelatedElementsGet)annotation;
\r
26 return new MappedElementsRule<StructuralResource,Range>(new RelatedObjectsAccessor(g.getResource(getterAnn.value()),getterAnn.composition(),true,true,true),
\r
27 new CollectionAccessor<Range,Range>(getter, adder, remover));
\r
31 public boolean isAdder(Annotation getterAnnotation, Annotation annotation) {
\r
32 TypeRelatedElementsGet getterAnn = (TypeRelatedElementsGet)getterAnnotation;
\r
33 TypeRelatedElementsAdd adderAnn = (TypeRelatedElementsAdd)annotation;
\r
34 return getterAnn.value().equals(adderAnn.value());
\r
38 public boolean isRemover(Annotation getterAnnotation, Annotation annotation) {
\r
39 TypeRelatedElementsGet getterAnn = (TypeRelatedElementsGet)getterAnnotation;
\r
40 TypeRelatedElementsRem adderAnn = (TypeRelatedElementsRem)annotation;
\r
41 return getterAnn.value().equals(adderAnn.value());
\r