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.StructuralRelatedElementsAdd;
\r
14 import org.simantics.objmap.structural.annotations.StructuralRelatedElementsGet;
\r
15 import org.simantics.objmap.structural.annotations.StructuralRelatedElementsRem;
\r
16 import org.simantics.objmap.structural.rules.domain.StructuralRelatedObjectsAccessor;
\r
19 public class StructuralRelatedElementsRuleFactory2<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 StructuralRelatedElementsGet getterAnn = (StructuralRelatedElementsGet)annotation;
\r
26 return new MappedElementsRule<StructuralResource,Range>(new StructuralRelatedObjectsAccessor(g.getResource(getterAnn.value()),getterAnn.composition()),
\r
27 new CollectionAccessor<Range,Range>(getter, adder, remover));
\r
31 public boolean isAdder(Annotation getterAnnotation, Annotation annotation) {
\r
32 StructuralRelatedElementsGet getterAnn = (StructuralRelatedElementsGet)getterAnnotation;
\r
33 StructuralRelatedElementsAdd adderAnn = (StructuralRelatedElementsAdd)annotation;
\r
34 return getterAnn.value().equals(adderAnn.value());
\r
38 public boolean isRemover(Annotation getterAnnotation, Annotation annotation) {
\r
39 StructuralRelatedElementsGet getterAnn = (StructuralRelatedElementsGet)getterAnnotation;
\r
40 StructuralRelatedElementsRem adderAnn = (StructuralRelatedElementsRem)annotation;
\r
41 return getterAnn.value().equals(adderAnn.value());
\r