]> gerrit.simantics Code Review - simantics/platform.git/blob
a272b4f0bc4dd0786688d6ff25719089ee1545f0
[simantics/platform.git] /
1 /*******************************************************************************
2  * Copyright (c) 2007, 2013 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.objmap.graph.rules.domain;
13
14 import java.util.Collection;
15
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.WriteGraph;
21 import org.simantics.db.common.utils.OrderedSetUtils;
22 import org.simantics.db.exception.DatabaseException;
23 import org.simantics.objmap.exceptions.MappingException;
24
25 /**
26  * Accesses the set of objects attached to the element by the given relation.
27  * @author Hannu Niemistö
28  */
29 public class RelatedOrderedSetElementsAccessor implements IDomainAccessor<Resource, Collection<Resource>> {
30
31     static Logger LOGGER = LoggerFactory.getLogger(RelatedOrderedSetElementsAccessor.class);
32     
33         boolean deleteExtraObjects;
34
35         public RelatedOrderedSetElementsAccessor(boolean deleteExtraObjects) {
36         super();
37         this.deleteExtraObjects = deleteExtraObjects;
38     }
39
40     @Override
41         public Collection<Resource> get(ReadGraph g, Resource element) throws MappingException {
42                 try {
43                     LOGGER.info("        RelatedOrderedSetElementsAccessor.get");
44                         return OrderedSetUtils.toList(g, element);
45                 } catch (DatabaseException e) {
46                         throw new MappingException(e);
47                 }
48         }
49         
50         @Override
51         public boolean set(WriteGraph g, Resource element, Collection<Resource> value)
52                         throws MappingException {
53                 try {
54                     LOGGER.info("        RelatedOrderedSetElementsAccessor.set");
55                     return OrderedSetUtils.set(g, element, value);
56                     // FIXME Implement deleteExtraObjects
57                 } catch (DatabaseException e) {
58                         throw new MappingException(e);
59                 }
60                 
61         }
62
63 }