1 /*******************************************************************************
2 * Copyright (c) 2007, 2013 Association for Decentralized Information Management
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.rules.domain;
14 import java.util.Collection;
16 import org.apache.log4j.Logger;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.WriteGraph;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.objmap.exceptions.MappingException;
24 * Accesses the set of objects attached to the element by the given relation.
25 * @author Hannu Niemistö
27 public class RelatedObjectsAccessor implements IDomainAccessor<Resource,Collection<Resource>> {
29 static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
32 boolean deleteExtraObjects;
34 public RelatedObjectsAccessor(Resource relation, boolean deleteExtraObjects) {
36 this.relation = relation;
37 this.deleteExtraObjects = deleteExtraObjects;
41 public Collection<Resource> get(ReadGraph g, Resource element) throws MappingException {
43 LOGGER.info(" RelatedObjectsAccessor.get");
44 return g.getObjects(element, relation);
45 } catch (DatabaseException e) {
46 throw new MappingException(e);
51 public boolean set(WriteGraph g, Resource element, Collection<Resource> value)
52 throws MappingException {
54 LOGGER.info(" RelatedObjectsAccessor.set");
55 return MappingUtils.synchronizeStatements(g, element, relation,
56 value.toArray(new Resource[value.size()]), deleteExtraObjects);
57 } catch (DatabaseException e) {
58 throw new MappingException(e);