1 /*******************************************************************************
2 * Copyright (c) 2019 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 * Semantum oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.objmap.graph.rules.domain;
14 import java.util.ArrayList;
15 import java.util.Collection;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.WriteGraph;
20 import org.simantics.db.common.utils.ListUtils;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.objmap.exceptions.MappingException;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * Accesses the set of objects attached to the element by the given relation.
28 * @author Hannu Niemistö
30 public class LinkedListAccessor implements IDomainAccessor<Resource,Collection<Resource>> {
32 static Logger LOGGER = LoggerFactory.getLogger(LinkedListAccessor.class);
36 boolean deleteExtraObjects;
38 public LinkedListAccessor(Resource relation, Resource listType, boolean deleteExtraObjects) {
40 this.relation = relation;
41 this.listType = listType;
42 this.deleteExtraObjects = deleteExtraObjects;
46 public Collection<Resource> get(ReadGraph g, Resource element) throws MappingException {
48 LOGGER.trace(" LinkdedListAccessor.get");
49 return ListUtils.toList(g, g.getPossibleObject(element, relation));
50 } catch (DatabaseException e) {
51 throw new MappingException(e);
56 public boolean set(WriteGraph g, Resource element, Collection<Resource> value)
57 throws MappingException {
59 LOGGER.trace(" LinkdedListAccessor.set");
60 return MappingUtils.synchronizeList(g, element, relation, listType, new ArrayList<Resource>(value), deleteExtraObjects);
61 } catch (DatabaseException e) {
62 throw new MappingException(e);