X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.objmap2%2Fsrc%2Forg%2Fsimantics%2Fobjmap%2Fgraph%2Fschema%2FAdaptedLinkType.java;h=b0d8d965f087ff9be1f098c48c01f144bf6a6839;hp=d66e4f1bbed63812c82b5f617164d26d8f3eb528;hb=d5db319fc2c400a8c76249e1ed7ffd9deb9f7609;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/AdaptedLinkType.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/AdaptedLinkType.java index d66e4f1bb..b0d8d965f 100644 --- a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/AdaptedLinkType.java +++ b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/schema/AdaptedLinkType.java @@ -1,87 +1,96 @@ -/******************************************************************************* - * Copyright (c) 2012, 2013 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.objmap.graph.schema; - -//import org.apache.log4j.Logger; -import org.eclipse.core.runtime.IAdaptable; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.exception.DatabaseException; - -import org.simantics.objmap.backward.IBackwardMapping; -import org.simantics.objmap.exceptions.MappingException; -import org.simantics.objmap.forward.IForwardMapping; - -/** - * A link type that is associated with adaptable resource (ReadGraph.getAdapter(Resource,Class)). - * The adapted object must implement IAdaptable interface for returning the original Resource. - * - * @author Marko Luukkainen - * - */ -public class AdaptedLinkType implements ILinkType { - - - //static Logger LOGGER = Logger.getLogger("org.simantics.objmap"); - - Resource domainType; - Class rangeType; - - - public AdaptedLinkType(Resource domainType, Class rangeType) { - this.domainType = domainType; - this.rangeType = rangeType; - } - - @Override - public Resource createDomainElement(WriteGraph g, Range rangeElement) - throws MappingException { - try { - IAdaptable adaptable = (IAdaptable)rangeElement; - Resource res = (Resource)adaptable.getAdapter(Resource.class); - if (res == null) - throw new NullPointerException(); - return res; - } catch (Exception e) { - throw new MappingException("Adapted object must implement IAdaptable interface to return the source Resource.", e); - } - - } - - @SuppressWarnings("unchecked") - @Override - public Range createRangeElement(ReadGraph g, Resource domainElement) - throws MappingException { - try { - return (Range)g.adapt(domainElement, rangeType); - } catch (DatabaseException e) { - throw new MappingException(e); - } - } - - public void createDomain(WriteGraph graph, IBackwardMapping mapping, Resource domainElement, Range rangeElement) throws MappingException { - - }; - - public void createRange(ReadGraph graph, org.simantics.objmap.forward.IForwardMapping mapping, Resource domainElement, Range rangeElement) throws MappingException { - - }; - - public boolean updateDomain(WriteGraph g, IBackwardMapping map, Resource domainElement, Range rangeElement) throws MappingException { - return false; - } - - public boolean updateRange(ReadGraph g, IForwardMapping map, Resource domainElement, Range rangeElement) throws MappingException { - return false; - } -} +/******************************************************************************* + * Copyright (c) 2012, 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.objmap.graph.schema; + +//import org.slf4j.Logger; +import org.eclipse.core.runtime.IAdaptable; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; + +import org.simantics.objmap.backward.IBackwardMapping; +import org.simantics.objmap.exceptions.MappingException; +import org.simantics.objmap.forward.IForwardMapping; + +/** + * A link type that is associated with adaptable resource (ReadGraph.getAdapter(Resource,Class)). + * The adapted object must implement IAdaptable interface for returning the original Resource. + * + * @author Marko Luukkainen + * + */ +public class AdaptedLinkType implements ILinkType { + + + //static Logger LOGGER = Logger.getLogger("org.simantics.objmap"); + + Resource domainType; + Class rangeType; + + + public AdaptedLinkType(Resource domainType, Class rangeType) { + this.domainType = domainType; + this.rangeType = rangeType; + } + + @Override + public Resource createDomainElement(WriteGraph g, Range rangeElement) + throws MappingException { + try { + IAdaptable adaptable = (IAdaptable)rangeElement; + Resource res = (Resource)adaptable.getAdapter(Resource.class); + if (res == null) + throw new NullPointerException(); + return res; + } catch (Exception e) { + throw new MappingException("Adapted object must implement IAdaptable interface to return the source Resource.", e); + } + + } + + @SuppressWarnings("unchecked") + @Override + public Range createRangeElement(ReadGraph g, Resource domainElement) + throws MappingException { + try { + return (Range)g.adapt(domainElement, rangeType); + } catch (DatabaseException e) { + throw new MappingException(e); + } + } + + @Override + public void createDomain(WriteGraph graph, IBackwardMapping mapping, Resource domainElement, Range rangeElement) throws MappingException { + + }; + + @Override + public void createRange(ReadGraph graph, org.simantics.objmap.forward.IForwardMapping mapping, Resource domainElement, Range rangeElement) throws MappingException { + + }; + + @Override + public boolean checkChanges(ReadGraph g, IForwardMapping map, Resource domainElement, Range rangeElement) throws MappingException { + return false; + } + + @Override + public boolean updateDomain(WriteGraph g, IBackwardMapping map, Resource domainElement, Range rangeElement) throws MappingException { + return false; + } + + @Override + public boolean updateRange(ReadGraph g, IForwardMapping map, Resource domainElement, Range rangeElement) throws MappingException { + return false; + } +}