1 package org.simantics.objmap.graph.schema;
\r
3 //import org.apache.log4j.Logger;
\r
4 import org.eclipse.core.runtime.IAdaptable;
\r
5 import org.simantics.db.ReadGraph;
\r
6 import org.simantics.db.Resource;
\r
7 import org.simantics.db.WriteGraph;
\r
8 import org.simantics.db.exception.DatabaseException;
\r
10 import org.simantics.objmap.backward.IBackwardMapping;
\r
11 import org.simantics.objmap.exceptions.MappingException;
\r
12 import org.simantics.objmap.forward.IForwardMapping;
\r
15 * A link type that is associated with adaptable resource (ReadGraph.getAdapter(Resource,Class)).
\r
16 * The adapted object must implement IAdaptable interface for returning the original Resource.
\r
18 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
\r
21 public class AdaptedLinkType<Range> implements ILinkType<Resource,Range> {
\r
24 //static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
\r
26 Resource domainType;
\r
30 public AdaptedLinkType(Resource domainType, Class<?> rangeType) {
\r
31 this.domainType = domainType;
\r
32 this.rangeType = rangeType;
\r
36 public Resource createDomainElement(WriteGraph g, Range rangeElement)
\r
37 throws MappingException {
\r
39 IAdaptable adaptable = (IAdaptable)rangeElement;
\r
40 Resource res = (Resource)adaptable.getAdapter(Resource.class);
\r
42 throw new NullPointerException();
\r
44 } catch (Exception e) {
\r
45 throw new MappingException("Adapted object must implement IAdaptable interface to return the source Resource.", e);
\r
51 public Range createRangeElement(ReadGraph g, Resource domainElement)
\r
52 throws MappingException {
\r
54 return (Range)g.adapt(domainElement, rangeType);
\r
55 } catch (DatabaseException e) {
\r
56 throw new MappingException(e);
\r
60 public void createDomain(WriteGraph graph, IBackwardMapping<Resource,Range> mapping, Resource domainElement, Range rangeElement) throws MappingException {
\r
64 public void createRange(ReadGraph graph, org.simantics.objmap.forward.IForwardMapping<Resource,Range> mapping, Resource domainElement, Range rangeElement) throws MappingException {
\r
68 public boolean updateDomain(WriteGraph g, IBackwardMapping<Resource,Range> map, Resource domainElement, Range rangeElement) throws MappingException {
\r
72 public boolean updateRange(ReadGraph g, IForwardMapping<Resource,Range> map, Resource domainElement, Range rangeElement) throws MappingException {
\r