-/*******************************************************************************\r
- * Copyright (c) 2012, 2013 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.objmap.graph.schema;\r
-\r
-//import org.apache.log4j.Logger;\r
-import org.eclipse.core.runtime.IAdaptable;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.exception.DatabaseException;\r
-\r
-import org.simantics.objmap.backward.IBackwardMapping;\r
-import org.simantics.objmap.exceptions.MappingException;\r
-import org.simantics.objmap.forward.IForwardMapping;\r
-\r
-/**\r
- * A link type that is associated with adaptable resource (ReadGraph.getAdapter(Resource,Class)). \r
- * The adapted object must implement IAdaptable interface for returning the original Resource. \r
- * \r
- * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
- *\r
- */\r
-public class AdaptedLinkType<Range> implements ILinkType<Resource,Range> {\r
-\r
- \r
- //static Logger LOGGER = Logger.getLogger("org.simantics.objmap");\r
- \r
- Resource domainType;\r
- Class<?> rangeType;\r
- \r
- \r
- public AdaptedLinkType(Resource domainType, Class<?> rangeType) {\r
- this.domainType = domainType;\r
- this.rangeType = rangeType;\r
- }\r
- \r
- @Override\r
- public Resource createDomainElement(WriteGraph g, Range rangeElement)\r
- throws MappingException {\r
- try {\r
- IAdaptable adaptable = (IAdaptable)rangeElement;\r
- Resource res = (Resource)adaptable.getAdapter(Resource.class);\r
- if (res == null)\r
- throw new NullPointerException();\r
- return res;\r
- } catch (Exception e) {\r
- throw new MappingException("Adapted object must implement IAdaptable interface to return the source Resource.", e);\r
- }\r
- \r
- }\r
- \r
- @SuppressWarnings("unchecked")\r
- @Override\r
- public Range createRangeElement(ReadGraph g, Resource domainElement)\r
- throws MappingException {\r
- try {\r
- return (Range)g.adapt(domainElement, rangeType);\r
- } catch (DatabaseException e) {\r
- throw new MappingException(e);\r
- }\r
- }\r
- \r
- public void createDomain(WriteGraph graph, IBackwardMapping<Resource,Range> mapping, Resource domainElement, Range rangeElement) throws MappingException {\r
- \r
- };\r
- \r
- public void createRange(ReadGraph graph, org.simantics.objmap.forward.IForwardMapping<Resource,Range> mapping, Resource domainElement, Range rangeElement) throws MappingException {\r
- \r
- };\r
- \r
- public boolean updateDomain(WriteGraph g, IBackwardMapping<Resource,Range> map, Resource domainElement, Range rangeElement) throws MappingException {\r
- return false;\r
- }\r
- \r
- public boolean updateRange(ReadGraph g, IForwardMapping<Resource,Range> map, Resource domainElement, Range rangeElement) throws MappingException {\r
- return false;\r
- }\r
-}\r
+/*******************************************************************************
+ * 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 <marko.luukkainen@vtt.fi>
+ *
+ */
+public class AdaptedLinkType<Range> implements ILinkType<Resource,Range> {
+
+
+ //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<Resource,Range> mapping, Resource domainElement, Range rangeElement) throws MappingException {
+
+ };
+
+ public void createRange(ReadGraph graph, org.simantics.objmap.forward.IForwardMapping<Resource,Range> mapping, Resource domainElement, Range rangeElement) throws MappingException {
+
+ };
+
+ public boolean updateDomain(WriteGraph g, IBackwardMapping<Resource,Range> map, Resource domainElement, Range rangeElement) throws MappingException {
+ return false;
+ }
+
+ public boolean updateRange(ReadGraph g, IForwardMapping<Resource,Range> map, Resource domainElement, Range rangeElement) throws MappingException {
+ return false;
+ }
+}