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.MappedElementsRule;
\r
21 import org.simantics.objmap.graph.rules.factory.ICollectionRuleFactory;
\r
22 import org.simantics.objmap.graph.rules.range.CollectionAccessor;
\r
23 import org.simantics.objmap.structural.StructuralResource;
\r
24 import org.simantics.objmap.structural.annotations.TypeRelatedElementsAdd;
\r
25 import org.simantics.objmap.structural.annotations.TypeRelatedElementsGet;
\r
26 import org.simantics.objmap.structural.annotations.TypeRelatedElementsRem;
\r
27 import org.simantics.objmap.structural.rules.domain.RelatedObjectsAccessor;
\r
30 public class TypeRelatedElementsRuleFactory2<Range> implements ICollectionRuleFactory<StructuralResource,Range> {
\r
33 public IBidirectionalMappingRule<StructuralResource, Range> create(ReadGraph g, Annotation annotation,
\r
34 Method getter, Method adder, Method remover)
\r
35 throws DatabaseException {
\r
36 TypeRelatedElementsGet getterAnn = (TypeRelatedElementsGet)annotation;
\r
37 return new MappedElementsRule<StructuralResource,Range>(new RelatedObjectsAccessor(g.getResource(getterAnn.value()),getterAnn.composition(),true,true,true),
\r
38 new CollectionAccessor<Range,Range>(getter, adder, remover));
\r
42 public boolean isAdder(Annotation getterAnnotation, Annotation annotation) {
\r
43 TypeRelatedElementsGet getterAnn = (TypeRelatedElementsGet)getterAnnotation;
\r
44 TypeRelatedElementsAdd adderAnn = (TypeRelatedElementsAdd)annotation;
\r
45 return getterAnn.value().equals(adderAnn.value());
\r
49 public boolean isRemover(Annotation getterAnnotation, Annotation annotation) {
\r
50 TypeRelatedElementsGet getterAnn = (TypeRelatedElementsGet)getterAnnotation;
\r
51 TypeRelatedElementsRem adderAnn = (TypeRelatedElementsRem)annotation;
\r
52 return getterAnn.value().equals(adderAnn.value());
\r