1 /*******************************************************************************
\r
2 * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
\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.g3d.objmap.schema;
\r
14 //import org.apache.log4j.Logger;
\r
15 import org.eclipse.core.runtime.IAdaptable;
\r
16 import org.simantics.db.ReadGraph;
\r
17 import org.simantics.db.Resource;
\r
18 import org.simantics.db.WriteGraph;
\r
19 import org.simantics.db.exception.DatabaseException;
\r
20 import org.simantics.objmap.IFunction;
\r
21 import org.simantics.objmap.ILinkType;
\r
22 import org.simantics.objmap.MappingException;
\r
25 * A link type that is associated with adaptable resource (ReadGraph.getAdapter(Resource,Class)).
\r
26 * The adapted object must implement IAdaptable interface for returning the original Resource.
\r
28 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
\r
31 public class AdaptedLinkType implements ILinkType {
\r
34 //static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
\r
36 Resource domainType;
\r
40 public AdaptedLinkType(Resource domainType, Class<?> rangeType) {
\r
41 this.domainType = domainType;
\r
42 this.rangeType = rangeType;
\r
46 public Resource createDomainElement(WriteGraph g, Object rangeElement)
\r
47 throws MappingException {
\r
49 IAdaptable adaptable = (IAdaptable)rangeElement;
\r
50 Resource res = (Resource)adaptable.getAdapter(Resource.class);
\r
52 throw new NullPointerException();
\r
54 } catch (Exception e) {
\r
55 throw new MappingException("Adapted object must implement IAdaptable interface to return the source Resource.", e);
\r
61 public Object createRangeElement(ReadGraph g, Resource domainElement)
\r
62 throws MappingException {
\r
64 return g.adapt(domainElement, rangeType);
\r
65 } catch (DatabaseException e) {
\r
66 throw new MappingException(e);
\r
71 public boolean updateDomain(WriteGraph g, IFunction<Object, Resource> map,
\r
72 Resource domainElement, Object rangeElement)
\r
73 throws MappingException {
\r
77 public boolean updateRange(ReadGraph g, IFunction<Resource, Object> map,
\r
78 Resource domainElement, Object rangeElement)
\r
79 throws MappingException {
\r