1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.objmap.annotations.factories;
\r
14 import java.lang.annotation.Annotation;
\r
15 import java.lang.reflect.Field;
\r
17 import org.simantics.db.ReadGraph;
\r
18 import org.simantics.db.exception.ResourceNotFoundException;
\r
19 import org.simantics.db.exception.ServiceException;
\r
20 import org.simantics.db.exception.ValidationException;
\r
21 import org.simantics.objmap.IMappingRule;
\r
22 import org.simantics.objmap.annotations.RelatedValue;
\r
23 import org.simantics.objmap.rules.ValueRule;
\r
24 import org.simantics.objmap.rules.domain.RelatedValueAccessor;
\r
25 import org.simantics.objmap.rules.factory.IFieldRuleFactory;
\r
26 import org.simantics.objmap.rules.range.FieldAccessor;
\r
28 public class RelatedValueRuleFactory implements IFieldRuleFactory {
\r
31 public IMappingRule create(ReadGraph g, Annotation _annotation, Field field) throws ResourceNotFoundException, ValidationException, ServiceException {
\r
32 RelatedValue annotation = (RelatedValue)_annotation;
\r
33 //Builtins b = g.getBuiltins();
\r
34 return new ValueRule(
\r
35 new RelatedValueAccessor(
\r
36 g.getResource(annotation.value()),
\r
37 DataTypeUtils.dataTypeOfClass(g, field.getType())
\r
39 new FieldAccessor<Object>(field)
\r