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.g3d.objmap.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.g3d.objmap.annotations.RelatedElementsAdd;
\r
20 import org.simantics.g3d.objmap.annotations.RelatedElementsGet;
\r
21 import org.simantics.g3d.objmap.annotations.RelatedElementsRem;
\r
22 import org.simantics.g3d.objmap.rules.factory.ICollectionRuleFactory;
\r
23 import org.simantics.g3d.objmap.rules.range.CollectionAccessor;
\r
24 import org.simantics.objmap.IMappingRule;
\r
25 import org.simantics.objmap.rules.MappedElementsRule;
\r
26 import org.simantics.objmap.rules.domain.RelatedObjectsAccessor;
\r
28 public class RelatedElementsRuleFactory implements ICollectionRuleFactory {
\r
31 public IMappingRule create(ReadGraph g, Annotation annotation,
\r
32 Method getter, Method adder, Method remover)
\r
33 throws DatabaseException {
\r
34 RelatedElementsGet getterAnn = (RelatedElementsGet)annotation;
\r
35 return new MappedElementsRule(new RelatedObjectsAccessor(g.getResource(getterAnn.value()),true),
\r
36 new CollectionAccessor<Object>(getter, adder, remover));
\r
40 public boolean isAdder(Annotation getterAnnotation, Annotation annotation) {
\r
41 RelatedElementsGet getterAnn = (RelatedElementsGet)getterAnnotation;
\r
42 RelatedElementsAdd adderAnn = (RelatedElementsAdd)annotation;
\r
43 return getterAnn.value().equals(adderAnn.value());
\r
47 public boolean isRemover(Annotation getterAnnotation, Annotation annotation) {
\r
48 RelatedElementsGet getterAnn = (RelatedElementsGet)getterAnnotation;
\r
49 RelatedElementsRem adderAnn = (RelatedElementsRem)annotation;
\r
50 return getterAnn.value().equals(adderAnn.value());
\r