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