1 /*******************************************************************************
2 * Copyright (c) 2019 Association for Decentralized Information Management in
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
10 * Semantum oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.objmap.graph.annotations.factories;
14 import java.lang.annotation.Annotation;
15 import java.lang.reflect.Method;
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.LinkedListAdd;
22 import org.simantics.objmap.graph.annotations.LinkedListGet;
23 import org.simantics.objmap.graph.annotations.LinkedListRem;
24 import org.simantics.objmap.graph.rules.MappedElementsRule;
25 import org.simantics.objmap.graph.rules.domain.LinkedListAccessor;
26 import org.simantics.objmap.graph.rules.factory.ICollectionRuleFactory;
27 import org.simantics.objmap.graph.rules.range.CollectionAccessor;
29 public class LinkedListRuleFactory2<Range> implements ICollectionRuleFactory<Resource,Range> {
32 public IBidirectionalMappingRule<Resource, Range> create(ReadGraph g, Annotation annotation,
33 Method getter, Method adder, Method remover)
34 throws DatabaseException {
35 LinkedListGet getterAnn = (LinkedListGet)annotation;
36 return new MappedElementsRule<Resource,Range>(new LinkedListAccessor(g.getResource(getterAnn.value()), g.getResource(getterAnn.type()), getterAnn.composition()),
37 new CollectionAccessor<Range,Range>(getter, adder, remover));
41 public boolean isAdder(Annotation getterAnnotation, Annotation annotation) {
42 LinkedListGet getterAnn = (LinkedListGet)getterAnnotation;
43 LinkedListAdd adderAnn = (LinkedListAdd)annotation;
44 return getterAnn.value().equals(adderAnn.value());
48 public boolean isRemover(Annotation getterAnnotation, Annotation annotation) {
49 LinkedListGet getterAnn = (LinkedListGet)getterAnnotation;
50 LinkedListRem adderAnn = (LinkedListRem)annotation;
51 return getterAnn.value().equals(adderAnn.value());