]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
4bac0c810b3fc88e020861a6f3a7bd4d4454102f
[simantics/sysdyn.git] /
1 package org.simantics.sysdyn.modelImport.model.expression;\r
2 \r
3 import java.util.Arrays;\r
4 \r
5 import org.simantics.db.ReadGraph;\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 abstract class Expression implements IWriteableObject {\r
17 \r
18         private Resource expr;\r
19 \r
20         @Override\r
21         public Resource write(WriteGraph graph, Resource parent, WriteContext context) throws DatabaseException {\r
22                 Layer0 l0 = Layer0.getInstance(graph);\r
23                 SysdynResource sr = SysdynResource.getInstance(graph);\r
24                 \r
25                 expr = GraphUtils.create2(graph, getExpressionType(graph),\r
26                                 l0.PartOf, parent);\r
27 \r
28                 // insert the expression into the expression list of the variable \r
29                 // (necessary because of enumeration expressions)\r
30                 Resource list = graph.getPossibleObject(parent, sr.Variable_expressionList);\r
31                 if (list != null)\r
32                         ListUtils.insertBack(graph, list, Arrays.asList(expr));\r
33                 else\r
34                         graph.claim(parent, sr.Variable_expressionList, ListUtils.create(graph, Arrays.asList(expr)));\r
35 \r
36                 return expr;\r
37         }\r
38         \r
39         public abstract Resource getExpressionType(ReadGraph graph);\r
40 \r
41         @Override\r
42         public Resource getResource() {\r
43                 return expr;\r
44         }\r
45 }\r