]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/rules/domain/RelatedOrderedSetElementsAccessor.java
c033751e506eb7797e92918257520b8463203d6d
[simantics/platform.git] / bundles / org.simantics.objmap2 / src / org / simantics / objmap / graph / rules / domain / RelatedOrderedSetElementsAccessor.java
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.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.common.utils.OrderedSetUtils;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.objmap.exceptions.MappingException;
23
24 /**
25  * Accesses the set of objects attached to the element by the given relation.
26  * @author Hannu Niemistö
27  */
28 public class RelatedOrderedSetElementsAccessor implements IDomainAccessor<Resource, Collection<Resource>> {
29
30     static Logger LOGGER = Logger.getLogger("org.simantics.objmap");
31     
32         boolean deleteExtraObjects;
33
34         public RelatedOrderedSetElementsAccessor(boolean deleteExtraObjects) {
35         super();
36         this.deleteExtraObjects = deleteExtraObjects;
37     }
38
39     @Override
40         public Collection<Resource> get(ReadGraph g, Resource element) throws MappingException {
41                 try {
42                     LOGGER.info("        RelatedOrderedSetElementsAccessor.get");
43                         return OrderedSetUtils.toList(g, element);
44                 } catch (DatabaseException e) {
45                         throw new MappingException(e);
46                 }
47         }
48         
49         @Override
50         public boolean set(WriteGraph g, Resource element, Collection<Resource> value)
51                         throws MappingException {
52                 try {
53                     LOGGER.info("        RelatedOrderedSetElementsAccessor.set");
54                     return OrderedSetUtils.set(g, element, value);
55                     // FIXME Implement deleteExtraObjects
56                 } catch (DatabaseException e) {
57                         throw new MappingException(e);
58                 }
59                 
60         }
61
62 }