]> gerrit.simantics Code Review - simantics/3d.git/blob
1f5d8ece4179f1dc754b0e12f06fe0096c8cb0a3
[simantics/3d.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2012, 2013 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.g3d.objmap.annotations.factories;\r
13 \r
14 import java.lang.annotation.Annotation;\r
15 import java.lang.reflect.Method;\r
16 \r
17 import org.simantics.db.ReadGraph;\r
18 import org.simantics.db.exception.DatabaseException;\r
19 import org.simantics.g3d.objmap.annotations.RelatedGetObj;\r
20 import org.simantics.g3d.objmap.annotations.RelatedGetValue;\r
21 import org.simantics.g3d.objmap.annotations.RelatedSetObj;\r
22 import org.simantics.g3d.objmap.annotations.RelatedSetValue;\r
23 import org.simantics.g3d.objmap.rules.factory.IGetSetRuleFactory;\r
24 import org.simantics.g3d.objmap.rules.range.GetSetObjectAccessor;\r
25 import org.simantics.objmap.IMappingRule;\r
26 import org.simantics.objmap.rules.MappedElementRule;\r
27 import org.simantics.objmap.rules.domain.RelatedObjectAccessor;\r
28 \r
29 /**\r
30  * Rule factory for mapped object using Getter/Setter-methods.\r
31  * \r
32  * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
33  *\r
34  */\r
35 public class RelatedGetSetObjRuleFactory implements IGetSetRuleFactory {\r
36         \r
37         @Override\r
38         public IMappingRule create(ReadGraph g, Annotation annotation,\r
39                         Method getter, Method setter)\r
40                         throws DatabaseException {\r
41                 RelatedGetObj getterAnn = (RelatedGetObj)annotation;\r
42                 return new MappedElementRule(new RelatedObjectAccessor(g.getResource(getterAnn.value())),\r
43                                         new GetSetObjectAccessor<Object>(getter, setter));\r
44         }\r
45         \r
46         @Override\r
47         public boolean isSetter(Annotation getterAnnotation, Annotation annotation) {\r
48                 RelatedGetObj getterAnn = (RelatedGetObj)getterAnnotation;\r
49                 RelatedSetObj setterAnn = (RelatedSetObj)annotation;\r
50                 return getterAnn.value().equals(setterAnn.value());\r
51         }\r
52         \r
53         \r
54 \r
55 }\r