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