1 package org.simantics.objmap.graph.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.Resource;
\r
8 import org.simantics.db.exception.DatabaseException;
\r
9 import org.simantics.objmap.bidirectional.IBidirectionalMappingRule;
\r
10 import org.simantics.objmap.graph.annotations.RelatedGetObj;
\r
11 import org.simantics.objmap.graph.annotations.RelatedSetObj;
\r
12 import org.simantics.objmap.graph.rules.MappedElementRule;
\r
13 import org.simantics.objmap.graph.rules.domain.RelatedObjectAccessor;
\r
14 import org.simantics.objmap.graph.rules.factory.IGetSetRuleFactory;
\r
15 import org.simantics.objmap.graph.rules.range.GetSetObjectAccessor;
\r
19 * Rule factory for mapped object using Getter/Setter-methods.
\r
21 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
\r
24 public class RelatedGetSetObjRuleFactory<Range> implements IGetSetRuleFactory<Resource,Range> {
\r
27 public IBidirectionalMappingRule<Resource,Range> create(ReadGraph g, Annotation annotation,
\r
28 Method getter, Method setter)
\r
29 throws DatabaseException {
\r
30 RelatedGetObj getterAnn = (RelatedGetObj)annotation;
\r
31 return new MappedElementRule<Resource,Range>(new RelatedObjectAccessor(g.getResource(getterAnn.value())),
\r
32 new GetSetObjectAccessor<Range,Range>(getter, setter));
\r
36 public boolean isSetter(Annotation getterAnnotation, Annotation annotation) {
\r
37 RelatedGetObj getterAnn = (RelatedGetObj)getterAnnotation;
\r
38 RelatedSetObj setterAnn = (RelatedSetObj)annotation;
\r
39 return getterAnn.value().equals(setterAnn.value());
\r