1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.objmap.rules.domain;
\r
14 import java.util.Collection;
\r
15 import java.util.Collections;
\r
17 import org.apache.log4j.Logger;
\r
18 import org.simantics.db.ReadGraph;
\r
19 import org.simantics.db.Resource;
\r
20 import org.simantics.db.WriteGraph;
\r
21 import org.simantics.db.common.utils.OrderedSetUtils;
\r
22 import org.simantics.db.exception.DatabaseException;
\r
23 import org.simantics.objmap.MappingException;
\r
26 * Accesses the set of objects attached to the element by the given relation.
\r
27 * @author Hannu Niemistö
\r
29 public class RelatedOrderedSetElementsAccessor implements IDomainAccessor<Collection<Resource>> {
\r
31 static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
\r
33 boolean deleteExtraObjects;
\r
35 public RelatedOrderedSetElementsAccessor(boolean deleteExtraObjects) {
\r
37 this.deleteExtraObjects = deleteExtraObjects;
\r
41 public Collection<Resource> get(ReadGraph g, Resource element) throws MappingException {
\r
43 LOGGER.info(" RelatedOrderedSetElementsAccessor.get");
\r
44 if(g.hasStatement(element))
\r
45 return OrderedSetUtils.toList(g, element);
\r
47 return Collections.emptyList();
\r
48 } catch (DatabaseException e) {
\r
49 throw new MappingException(e);
\r
54 public boolean set(WriteGraph g, Resource element, Collection<Resource> value)
\r
55 throws MappingException {
\r
57 LOGGER.info(" RelatedOrderedSetElementsAccessor.set");
\r
58 return OrderedSetUtils.set(g, element, value);
\r
59 // FIXME Implement deleteExtraObjects
\r
60 } catch (DatabaseException e) {
\r
61 throw new MappingException(e);
\r