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