1 /*******************************************************************************
\r
2 * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
\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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.objmap.graph.annotations.factories;
\r
14 import java.lang.annotation.Annotation;
\r
15 import java.lang.reflect.Method;
\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
30 * Rule factory for mapped object using Getter/Setter-methods.
\r
32 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
\r
35 public class RelatedGetSetObjRuleFactory<Range> implements IGetSetRuleFactory<Resource,Range> {
\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
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