]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
8b571f815c99bc6dfe80a31d3e2caff1b61b240a
[simantics/sysdyn.git] /
1 package org.simantics.sysdyn.modelImport.model.support;\r
2 \r
3 import java.util.HashSet;\r
4 import java.util.Set;\r
5 \r
6 import org.simantics.db.Resource;\r
7 import org.simantics.db.WriteGraph;\r
8 import org.simantics.db.common.utils.ListUtils;\r
9 import org.simantics.db.exception.DatabaseException;\r
10 import org.simantics.layer0.Layer0;\r
11 import org.simantics.layer0.utils.direct.GraphUtils;\r
12 import org.simantics.sysdyn.SysdynResource;\r
13 import org.simantics.sysdyn.modelImport.model.IWriteableObject;\r
14 import org.simantics.sysdyn.modelImport.model.WriteContext;\r
15 \r
16 public class Enumeration implements IWriteableObject {\r
17         \r
18         private String name;\r
19         private Set<String> values;\r
20         \r
21         private Resource enumeration;\r
22         \r
23         public Enumeration(String name, Set<String> values) {\r
24                 this.name = name;\r
25                 this.values = values;\r
26         }\r
27         \r
28         public String getName() {\r
29                 return name;\r
30         }\r
31         \r
32         public Set<String> getValues() {\r
33                 return values;\r
34         }\r
35 \r
36         @Override\r
37         public Resource write(WriteGraph graph, Resource parent, WriteContext context)\r
38                         throws DatabaseException {\r
39                 Layer0 l0 = Layer0.getInstance(graph);\r
40                 SysdynResource sr = SysdynResource.getInstance(graph);\r
41                 \r
42                 enumeration = GraphUtils.create2(graph, sr.Enumeration,\r
43                                 l0.HasName, name,\r
44                                 l0.PartOf, parent);\r
45                 \r
46                 Set<Resource> indices = new HashSet<Resource>();\r
47                 for (String index : values) {\r
48                         indices.add(GraphUtils.create2(graph, sr.EnumerationIndex,\r
49                                         l0.HasName, index));\r
50                 }\r
51                 \r
52                 graph.claim(enumeration, sr.Enumeration_enumerationIndexList, ListUtils.create(graph, indices));\r
53                 \r
54                 return enumeration;\r
55         }\r
56         \r
57         @Override\r
58         public Resource getResource() {\r
59                 return enumeration;\r
60         }\r
61 \r
62 }\r