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.structural.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.exception.DatabaseException;
\r
19 import org.simantics.objmap.bidirectional.IBidirectionalMappingRule;
\r
20 import org.simantics.objmap.graph.rules.MappedElementRule;
\r
21 import org.simantics.objmap.graph.rules.factory.IGetSetRuleFactory;
\r
22 import org.simantics.objmap.graph.rules.range.GetSetObjectAccessor;
\r
23 import org.simantics.objmap.structural.StructuralResource;
\r
24 import org.simantics.objmap.structural.annotations.StructuralRelatedGetObj;
\r
25 import org.simantics.objmap.structural.annotations.StructuralRelatedSetObj;
\r
26 import org.simantics.objmap.structural.rules.domain.StructuralRelatedObjectAccessor;
\r
30 * Rule factory for mapped object using Getter/Setter-methods.
\r
32 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
\r
35 public class StructuralRelatedGetSetObjRuleFactory<Range> implements IGetSetRuleFactory<StructuralResource,Range> {
\r
38 public IBidirectionalMappingRule<StructuralResource,Range> create(ReadGraph g, Annotation annotation,
\r
39 Method getter, Method setter)
\r
40 throws DatabaseException {
\r
41 StructuralRelatedGetObj getterAnn = (StructuralRelatedGetObj)annotation;
\r
42 return new MappedElementRule<StructuralResource,Range>(new StructuralRelatedObjectAccessor(g.getResource(getterAnn.value()),false,true,false),
\r
43 new GetSetObjectAccessor<Range,Range>(getter, setter));
\r
47 public boolean isSetter(Annotation getterAnnotation, Annotation annotation) {
\r
48 StructuralRelatedGetObj getterAnn = (StructuralRelatedGetObj)getterAnnotation;
\r
49 StructuralRelatedSetObj setterAnn = (StructuralRelatedSetObj)annotation;
\r
50 return getterAnn.value().equals(setterAnn.value());
\r