]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.objmap2/src/org/simantics/objmap/structural/annotations/factories/RelatedOrderedSetElementsRuleFactory.java
b2e65648e9794511360c0e912d6423e8e65f13f3
[simantics/3d.git] / org.simantics.objmap2 / src / org / simantics / objmap / structural / annotations / factories / RelatedOrderedSetElementsRuleFactory.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2013 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.objmap.structural.annotations.factories;\r
13 \r
14 import java.lang.annotation.Annotation;\r
15 import java.lang.reflect.Field;\r
16 import java.util.Collection;\r
17 \r
18 import org.simantics.db.ReadGraph;\r
19 import org.simantics.db.exception.ResourceNotFoundException;\r
20 import org.simantics.db.exception.ServiceException;\r
21 import org.simantics.db.exception.ValidationException;\r
22 import org.simantics.objmap.bidirectional.IBidirectionalMappingRule;\r
23 import org.simantics.objmap.graph.annotations.RelatedOrderedSetElements;\r
24 import org.simantics.objmap.graph.rules.MappedElementsRule;\r
25 import org.simantics.objmap.graph.rules.factory.IFieldRuleFactory;\r
26 import org.simantics.objmap.graph.rules.range.FieldAccessor;\r
27 import org.simantics.objmap.structural.StructuralResource;\r
28 import org.simantics.objmap.structural.rules.domain.RelatedOrderedSetElementsAccessor;\r
29 \r
30 \r
31 public class RelatedOrderedSetElementsRuleFactory<Range> implements IFieldRuleFactory<StructuralResource, Range> {\r
32 \r
33     @Override\r
34     public IBidirectionalMappingRule<StructuralResource, Range> create(ReadGraph g, Annotation _annotation, Field field) throws ResourceNotFoundException, ValidationException, ServiceException {\r
35         RelatedOrderedSetElements annotation = (RelatedOrderedSetElements)_annotation;\r
36         return new MappedElementsRule<StructuralResource,Range>(\r
37                 new RelatedOrderedSetElementsAccessor(annotation.composition(),false),\r
38                 new FieldAccessor<Range,Collection<Range>>(field)\r
39                 );\r
40     }\r
41 \r
42 }\r