1 /*******************************************************************************
2 * Copyright (c) 2007, 2013 Association for Decentralized Information Management
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 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.objmap.structural.annotations.factories;
14 import java.lang.annotation.Annotation;
15 import java.lang.reflect.Field;
16 import java.util.Collection;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.exception.ResourceNotFoundException;
20 import org.simantics.db.exception.ServiceException;
21 import org.simantics.db.exception.ValidationException;
22 import org.simantics.objmap.bidirectional.IBidirectionalMappingRule;
23 import org.simantics.objmap.graph.annotations.RelatedElements;
24 import org.simantics.objmap.graph.rules.MappedElementsRule;
25 import org.simantics.objmap.structural.rules.domain.RelatedObjectsAccessor;
26 import org.simantics.objmap.graph.rules.factory.IFieldRuleFactory;
27 import org.simantics.objmap.graph.rules.range.FieldAccessor;
28 import org.simantics.objmap.structural.StructuralResource;
31 public class RelatedElementsRuleFactory<Range> implements IFieldRuleFactory<StructuralResource, Range> {
34 public IBidirectionalMappingRule<StructuralResource, Range> create(ReadGraph g, Annotation _annotation, Field field) throws ResourceNotFoundException, ValidationException, ServiceException {
35 RelatedElements annotation = (RelatedElements)_annotation;
36 return new MappedElementsRule<StructuralResource,Range>(
37 new RelatedObjectsAccessor(g.getResource(annotation.value()),
38 annotation.composition(),false),
39 new FieldAccessor<Range,Collection<Range>>(field)