1 package org.simantics.sysdyn.modelImport.model.support;
\r
3 import java.util.Arrays;
\r
4 import java.util.HashSet;
\r
5 import java.util.Set;
\r
7 import org.simantics.db.Resource;
\r
8 import org.simantics.db.WriteGraph;
\r
9 import org.simantics.db.common.utils.ListUtils;
\r
10 import org.simantics.db.exception.DatabaseException;
\r
11 import org.simantics.layer0.Layer0;
\r
12 import org.simantics.layer0.utils.direct.GraphUtils;
\r
13 import org.simantics.sysdyn.SysdynResource;
\r
14 import org.simantics.sysdyn.modelImport.model.IWriteableObject;
\r
15 import org.simantics.sysdyn.modelImport.model.WriteContext;
\r
17 public class Enumeration implements IWriteableObject {
\r
19 private String name;
\r
20 private Set<String> values;
\r
21 private boolean copy;
\r
23 private Resource enumeration;
\r
25 public Enumeration(String name, String...values) {
\r
27 this.values = new HashSet<String>(Arrays.asList(values));
\r
32 public Enumeration(String name, Enumeration other) {
\r
34 this.values = other.getValues();
\r
39 public String getName() {
\r
43 public Set<String> getValues() {
\r
48 public Resource write(WriteGraph graph, Resource parent, WriteContext context)
\r
49 throws DatabaseException {
\r
50 Layer0 l0 = Layer0.getInstance(graph);
\r
51 SysdynResource sr = SysdynResource.getInstance(graph);
\r
53 enumeration = GraphUtils.create2(graph, sr.Enumeration,
\r
57 Set<Resource> indices = new HashSet<Resource>();
\r
58 for (String index : values) {
\r
59 indices.add(GraphUtils.create2(graph, sr.EnumerationIndex,
\r
60 l0.HasName, index));
\r
63 graph.claim(enumeration, sr.Enumeration_enumerationIndexList, ListUtils.create(graph, indices));
\r
65 // register this enumeration with the context
\r
66 context.registerEnumeration(this, copy);
\r
72 public Resource getResource() {
\r