X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.objmap2%2Fsrc%2Forg%2Fsimantics%2Fobjmap%2Fgraph%2Fannotations%2Ffactories%2FLinkedListRuleFactory2.java;fp=bundles%2Forg.simantics.objmap2%2Fsrc%2Forg%2Fsimantics%2Fobjmap%2Fgraph%2Fannotations%2Ffactories%2FLinkedListRuleFactory2.java;h=3ef69d9893321039aef2e9708ebd216d2fa3932e;hp=0000000000000000000000000000000000000000;hb=87d3c60a5c520cca584c54e6bc0fd8c9576141a7;hpb=240fea4f9c0aa8dba1e1af496aebb4157740fa20 diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/LinkedListRuleFactory2.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/LinkedListRuleFactory2.java new file mode 100644 index 000000000..3ef69d989 --- /dev/null +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/annotations/factories/LinkedListRuleFactory2.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2019 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum oy - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.graph.annotations.factories; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.objmap.bidirectional.IBidirectionalMappingRule; +import org.simantics.objmap.graph.annotations.LinkedListAdd; +import org.simantics.objmap.graph.annotations.LinkedListGet; +import org.simantics.objmap.graph.annotations.LinkedListRem; +import org.simantics.objmap.graph.rules.MappedElementsRule; +import org.simantics.objmap.graph.rules.domain.LinkedListAccessor; +import org.simantics.objmap.graph.rules.factory.ICollectionRuleFactory; +import org.simantics.objmap.graph.rules.range.CollectionAccessor; + +public class LinkedListRuleFactory2 implements ICollectionRuleFactory { + + @Override + public IBidirectionalMappingRule create(ReadGraph g, Annotation annotation, + Method getter, Method adder, Method remover) + throws DatabaseException { + LinkedListGet getterAnn = (LinkedListGet)annotation; + return new MappedElementsRule(new LinkedListAccessor(g.getResource(getterAnn.value()), g.getResource(getterAnn.type()), getterAnn.composition()), + new CollectionAccessor(getter, adder, remover)); + } + + @Override + public boolean isAdder(Annotation getterAnnotation, Annotation annotation) { + LinkedListGet getterAnn = (LinkedListGet)getterAnnotation; + LinkedListAdd adderAnn = (LinkedListAdd)annotation; + return getterAnn.value().equals(adderAnn.value()); + } + + @Override + public boolean isRemover(Annotation getterAnnotation, Annotation annotation) { + LinkedListGet getterAnn = (LinkedListGet)getterAnnotation; + LinkedListRem adderAnn = (LinkedListRem)annotation; + return getterAnn.value().equals(adderAnn.value()); + } + +}