1 package org.simantics.g3d.objmap.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.g3d.objmap.annotations.RelatedElementsAdd;
\r
9 import org.simantics.g3d.objmap.annotations.RelatedElementsGet;
\r
10 import org.simantics.g3d.objmap.annotations.RelatedElementsRem;
\r
11 import org.simantics.g3d.objmap.rules.factory.ICollectionRuleFactory;
\r
12 import org.simantics.g3d.objmap.rules.range.CollectionAccessor;
\r
13 import org.simantics.objmap.IMappingRule;
\r
14 import org.simantics.objmap.rules.MappedElementsRule;
\r
15 import org.simantics.objmap.rules.domain.RelatedObjectsAccessor;
\r
17 public class RelatedElementsRuleFactory implements ICollectionRuleFactory {
\r
20 public IMappingRule create(ReadGraph g, Annotation annotation,
\r
21 Method getter, Method adder, Method remover)
\r
22 throws DatabaseException {
\r
23 RelatedElementsGet getterAnn = (RelatedElementsGet)annotation;
\r
24 return new MappedElementsRule(new RelatedObjectsAccessor(g.getResource(getterAnn.value()),true),
\r
25 new CollectionAccessor<Object>(getter, adder, remover));
\r
29 public boolean isAdder(Annotation getterAnnotation, Annotation annotation) {
\r
30 RelatedElementsGet getterAnn = (RelatedElementsGet)getterAnnotation;
\r
31 RelatedElementsAdd adderAnn = (RelatedElementsAdd)annotation;
\r
32 return getterAnn.value().equals(adderAnn.value());
\r
36 public boolean isRemover(Annotation getterAnnotation, Annotation annotation) {
\r
37 RelatedElementsGet getterAnn = (RelatedElementsGet)getterAnnotation;
\r
38 RelatedElementsRem adderAnn = (RelatedElementsRem)annotation;
\r
39 return getterAnn.value().equals(adderAnn.value());
\r