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.objmap.graph.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
21 import org.simantics.objmap.backward.IBackwardMapping;
\r
22 import org.simantics.objmap.exceptions.MappingException;
\r
23 import org.simantics.objmap.forward.IForwardMapping;
\r
26 * A link type that is associated with adaptable resource (ReadGraph.getAdapter(Resource,Class)).
\r
27 * The adapted object must implement IAdaptable interface for returning the original Resource.
\r
29 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
\r
32 public class AdaptedLinkType<Range> implements ILinkType<Resource,Range> {
\r
35 //static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
\r
37 Resource domainType;
\r
41 public AdaptedLinkType(Resource domainType, Class<?> rangeType) {
\r
42 this.domainType = domainType;
\r
43 this.rangeType = rangeType;
\r
47 public Resource createDomainElement(WriteGraph g, Range rangeElement)
\r
48 throws MappingException {
\r
50 IAdaptable adaptable = (IAdaptable)rangeElement;
\r
51 Resource res = (Resource)adaptable.getAdapter(Resource.class);
\r
53 throw new NullPointerException();
\r
55 } catch (Exception e) {
\r
56 throw new MappingException("Adapted object must implement IAdaptable interface to return the source Resource.", e);
\r
61 @SuppressWarnings("unchecked")
\r
63 public Range createRangeElement(ReadGraph g, Resource domainElement)
\r
64 throws MappingException {
\r
66 return (Range)g.adapt(domainElement, rangeType);
\r
67 } catch (DatabaseException e) {
\r
68 throw new MappingException(e);
\r
72 public void createDomain(WriteGraph graph, IBackwardMapping<Resource,Range> mapping, Resource domainElement, Range rangeElement) throws MappingException {
\r
76 public void createRange(ReadGraph graph, org.simantics.objmap.forward.IForwardMapping<Resource,Range> mapping, Resource domainElement, Range rangeElement) throws MappingException {
\r
80 public boolean updateDomain(WriteGraph g, IBackwardMapping<Resource,Range> map, Resource domainElement, Range rangeElement) throws MappingException {
\r
84 public boolean updateRange(ReadGraph g, IForwardMapping<Resource,Range> map, Resource domainElement, Range rangeElement) throws MappingException {
\r