]> gerrit.simantics Code Review - simantics/3d.git/blob
ad30aee2293e97c4bc041cce3907aa3d04aa5de0
[simantics/3d.git] /
1 package org.simantics.objmap.structural.annotations.factories;\r
2 \r
3 import java.lang.annotation.Annotation;\r
4 import java.lang.reflect.Method;\r
5 \r
6 import org.simantics.db.ReadGraph;\r
7 import org.simantics.db.exception.DatabaseException;\r
8 import org.simantics.objmap.bidirectional.IBidirectionalMappingRule;\r
9 import org.simantics.objmap.graph.rules.MappedElementsRule;\r
10 import org.simantics.objmap.graph.rules.factory.ICollectionRuleFactory;\r
11 import org.simantics.objmap.graph.rules.range.CollectionAccessor;\r
12 import org.simantics.objmap.structural.StructuralResource;\r
13 import org.simantics.objmap.structural.annotations.StructuralRelatedElementsAdd;\r
14 import org.simantics.objmap.structural.annotations.StructuralRelatedElementsGet;\r
15 import org.simantics.objmap.structural.annotations.StructuralRelatedElementsRem;\r
16 import org.simantics.objmap.structural.rules.domain.StructuralRelatedObjectsAccessor;\r
17 \r
18 \r
19 public class StructuralRelatedElementsRuleFactory2<Range> implements ICollectionRuleFactory<StructuralResource,Range> {\r
20         \r
21         @Override\r
22         public IBidirectionalMappingRule<StructuralResource, Range> create(ReadGraph g, Annotation annotation,\r
23                         Method getter, Method adder, Method remover)\r
24                         throws DatabaseException {\r
25                 StructuralRelatedElementsGet getterAnn = (StructuralRelatedElementsGet)annotation;\r
26                 return new MappedElementsRule<StructuralResource,Range>(new StructuralRelatedObjectsAccessor(g.getResource(getterAnn.value()),getterAnn.composition()),\r
27                                         new CollectionAccessor<Range,Range>(getter, adder, remover));\r
28         }\r
29         \r
30         @Override\r
31         public boolean isAdder(Annotation getterAnnotation, Annotation annotation) {\r
32                 StructuralRelatedElementsGet getterAnn = (StructuralRelatedElementsGet)getterAnnotation;\r
33                 StructuralRelatedElementsAdd adderAnn = (StructuralRelatedElementsAdd)annotation;\r
34                 return getterAnn.value().equals(adderAnn.value());\r
35         }\r
36         \r
37         @Override\r
38         public boolean isRemover(Annotation getterAnnotation, Annotation annotation) {\r
39                 StructuralRelatedElementsGet getterAnn = (StructuralRelatedElementsGet)getterAnnotation;\r
40                 StructuralRelatedElementsRem adderAnn = (StructuralRelatedElementsRem)annotation;\r
41                 return getterAnn.value().equals(adderAnn.value());\r
42         }\r
43 \r
44 }\r