]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/RelatedGetSetObjRuleFactory.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.objmap2 / src / org / simantics / objmap / graph / annotations / factories / RelatedGetSetObjRuleFactory.java
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.objmap.graph.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.Resource;\r
19 import org.simantics.db.exception.DatabaseException;\r
20 import org.simantics.objmap.bidirectional.IBidirectionalMappingRule;\r
21 import org.simantics.objmap.graph.annotations.RelatedGetObj;\r
22 import org.simantics.objmap.graph.annotations.RelatedSetObj;\r
23 import org.simantics.objmap.graph.rules.MappedElementRule;\r
24 import org.simantics.objmap.graph.rules.domain.RelatedObjectAccessor;\r
25 import org.simantics.objmap.graph.rules.factory.IGetSetRuleFactory;\r
26 import org.simantics.objmap.graph.rules.range.GetSetObjectAccessor;\r
27 \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<Range> implements IGetSetRuleFactory<Resource,Range> {\r
36         \r
37         @Override\r
38         public IBidirectionalMappingRule<Resource,Range> 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<Resource,Range>(new RelatedObjectAccessor(g.getResource(getterAnn.value())),\r
43                                         new GetSetObjectAccessor<Range,Range>(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