]> gerrit.simantics Code Review - simantics/3d.git/blob
3f75b03c05d57a056cd859cea551dcb3907c09a3
[simantics/3d.git] /
1 package org.simantics.g3d.objmap.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.g3d.objmap.annotations.RelatedGetObj;\r
9 import org.simantics.g3d.objmap.annotations.RelatedGetValue;\r
10 import org.simantics.g3d.objmap.annotations.RelatedSetObj;\r
11 import org.simantics.g3d.objmap.annotations.RelatedSetValue;\r
12 import org.simantics.g3d.objmap.rules.factory.IGetSetRuleFactory;\r
13 import org.simantics.g3d.objmap.rules.range.GetSetObjectAccessor;\r
14 import org.simantics.objmap.IMappingRule;\r
15 import org.simantics.objmap.rules.MappedElementRule;\r
16 import org.simantics.objmap.rules.domain.RelatedObjectAccessor;\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 implements IGetSetRuleFactory {\r
25         \r
26         @Override\r
27         public IMappingRule 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(new RelatedObjectAccessor(g.getResource(getterAnn.value())),\r
32                                         new GetSetObjectAccessor<Object>(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