]> gerrit.simantics Code Review - simantics/3d.git/blob
9c6bc77638a322bc3b3359eabb347a23494c94fc
[simantics/3d.git] /
1 package org.simantics.objmap.structural.annotations.factories;\r
2 \r
3 import java.lang.annotation.Annotation;\r
4 import java.lang.reflect.Method;\r
5 \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.annotations.RelatedGetObj;\r
10 import org.simantics.objmap.graph.annotations.RelatedSetObj;\r
11 import org.simantics.objmap.graph.rules.MappedElementRule;\r
12 import org.simantics.objmap.structural.rules.domain.RelatedObjectAccessor;\r
13 import org.simantics.objmap.graph.rules.factory.IGetSetRuleFactory;\r
14 import org.simantics.objmap.graph.rules.range.GetSetObjectAccessor;\r
15 import org.simantics.objmap.structural.StructuralResource;\r
16 \r
17 \r
18 /**\r
19  * Rule factory for mapped object using Getter/Setter-methods.\r
20  * \r
21  * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
22  *\r
23  */\r
24 public class RelatedGetSetObjRuleFactory<Range> implements IGetSetRuleFactory<StructuralResource,Range> {\r
25         \r
26         @Override\r
27         public IBidirectionalMappingRule<StructuralResource,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<StructuralResource,Range>(new RelatedObjectAccessor(g.getResource(getterAnn.value()),false,true,false),\r
32                                         new GetSetObjectAccessor<Range,Range>(getter, setter));\r
33         }\r
34         \r
35         @Override\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
40         }\r
41         \r
42         \r
43 \r
44 }\r