--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2013 Association for Decentralized Information Management\r
+ * in 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.rules.domain;\r
+\r
+import java.util.Collection;\r
+\r
+import org.apache.log4j.Logger;\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
+import org.simantics.objmap.exceptions.MappingException;\r
+\r
+/**\r
+ * Accesses the set of objects attached to the element by the given relation.\r
+ * @author Hannu Niemistö\r
+ */\r
+public class RelatedObjectsAccessor implements IDomainAccessor<Resource,Collection<Resource>> {\r
+\r
+ static Logger LOGGER = Logger.getLogger("org.simantics.objmap");\r
+ \r
+ Resource relation;\r
+ boolean deleteExtraObjects;\r
+\r
+ public RelatedObjectsAccessor(Resource relation, boolean deleteExtraObjects) {\r
+ super();\r
+ this.relation = relation;\r
+ this.deleteExtraObjects = deleteExtraObjects;\r
+ }\r
+\r
+ @Override\r
+ public Collection<Resource> get(ReadGraph g, Resource element) throws MappingException {\r
+ try {\r
+ LOGGER.info(" RelatedObjectsAccessor.get");\r
+ return g.getObjects(element, relation);\r
+ } catch (DatabaseException e) {\r
+ throw new MappingException(e);\r
+ }\r
+ }\r
+ \r
+ @Override\r
+ public boolean set(WriteGraph g, Resource element, Collection<Resource> value)\r
+ throws MappingException {\r
+ try {\r
+ LOGGER.info(" RelatedObjectsAccessor.set");\r
+ return MappingUtils.synchronizeStatements(g, element, relation, \r
+ value.toArray(new Resource[value.size()]), deleteExtraObjects);\r
+ } catch (DatabaseException e) {\r
+ throw new MappingException(e);\r
+ }\r
+ \r
+ }\r
+\r
+}\r