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