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 org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16 import org.simantics.db.ReadGraph;
17 import org.simantics.db.Resource;
18 import org.simantics.db.WriteGraph;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.objmap.exceptions.MappingException;
23 * Accesses a resource attached to the element by given functional relation.
24 * @author Hannu Niemistö
26 public class RelatedObjectAccessor implements IDomainAccessor<Resource,Resource> {
28 static Logger LOGGER = LoggerFactory.getLogger(RelatedObjectAccessor.class);
32 public RelatedObjectAccessor(Resource relation) {
33 this.relation = relation;
37 public Resource get(ReadGraph g, Resource element) throws MappingException {
39 LOGGER.info(" RelatedObjectAccessor.get");
40 return g.getPossibleObject(element, relation);
41 } catch (DatabaseException e) {
42 throw new MappingException(e);
47 public boolean set(WriteGraph g, Resource element, Resource value)
48 throws MappingException {
50 LOGGER.info(" RelatedObjectAccessor.set");
51 Resource resource = g.getPossibleObject(element, relation);
52 if(resource == null) {
55 g.claim(element, relation, value);
58 else if(resource.equals(value))
61 g.deny(element, relation);
63 g.claim(element, relation, value);
66 } catch (DatabaseException e) {
67 throw new MappingException(e);