1 package org.simantics.sysdyn.modelImport.model.expression;
\r
3 import java.util.ArrayList;
\r
4 import java.util.Arrays;
\r
5 import java.util.List;
\r
7 import org.simantics.databoard.Bindings;
\r
8 import org.simantics.db.ReadGraph;
\r
9 import org.simantics.db.Resource;
\r
10 import org.simantics.db.WriteGraph;
\r
11 import org.simantics.db.common.utils.ListUtils;
\r
12 import org.simantics.db.exception.DatabaseException;
\r
13 import org.simantics.layer0.Layer0;
\r
14 import org.simantics.layer0.utils.direct.GraphUtils;
\r
15 import org.simantics.sysdyn.SysdynResource;
\r
16 import org.simantics.sysdyn.modelImport.model.WriteContext;
\r
18 public class EnumerationExpression extends Expression {
\r
20 private SubscriptSubExpression active;
\r
21 private ArrayList<SubscriptSubExpression> subExpressions;
\r
23 public EnumerationExpression(String[] indices, Expression expression) {
\r
24 active = new SubscriptSubExpression(indices, expression);
\r
25 subExpressions = new ArrayList<SubscriptSubExpression>();
\r
26 subExpressions.add(active);
\r
29 public void addExpression(String[] indices, Expression expression) {
\r
30 subExpressions.add(new SubscriptSubExpression(indices, expression));
\r
33 public List<SubscriptSubExpression> getExpressions() {
\r
34 return subExpressions;
\r
37 public void addExpressions(List<SubscriptSubExpression> expressions) {
\r
38 subExpressions.addAll(expressions);
\r
42 public Resource write(WriteGraph graph, Resource parent, WriteContext context) throws DatabaseException {
\r
43 SysdynResource sr = SysdynResource.getInstance(graph);
\r
45 for (SubscriptSubExpression subexpr : subExpressions) {
\r
46 subexpr.write(graph, parent, context);
\r
49 // write array index list
\r
50 //graph.claim(parent, sr.Variable_arrayIndexesList, ListUtils.create(graph, Arrays.asList()));
\r
52 // set active expression?
\r
54 return active.getResource();
\r
57 private class SubscriptSubExpression extends Expression {
\r
58 private String[] indices;
\r
59 private Expression expression;
\r
61 public SubscriptSubExpression(String[] indices, Expression expression) {
\r
62 this.indices = indices;
\r
63 this.expression = expression;
\r
67 public Resource write(WriteGraph graph, Resource parent, WriteContext context) throws DatabaseException {
\r
68 SysdynResource sr = SysdynResource.getInstance(graph);
\r
70 StringBuilder range = new StringBuilder();
\r
72 for (String index : indices) {
\r
73 if (range.length() > 1)
\r
75 range.append(index);
\r
79 Resource expr = super.write(graph, parent, context);
\r
81 graph.claimLiteral(expr, sr.Expression_arrayRange, range.toString(), Bindings.STRING);
\r
87 public Resource getExpressionType(ReadGraph graph) {
\r
88 return expression.getExpressionType(graph);
\r
94 public Resource getExpressionType(ReadGraph graph) {
\r
95 return active.getExpressionType(graph);
\r