]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableBean.java
possibleObjectForType utility
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / variable / VariableBean.java
1 package org.simantics.db.layer0.variable;
2
3 import org.simantics.databoard.util.Bean;
4 import org.simantics.db.ReadGraph;
5 import org.simantics.db.Resource;
6 import org.simantics.db.exception.DatabaseException;
7 import org.simantics.db.service.SerialisationSupport;
8
9 public class VariableBean extends Bean {
10
11         final public long context;
12         final public String rvi;
13         final transient public Variable variable;
14         
15         public VariableBean(ReadGraph graph, Variable variable) throws DatabaseException {
16                 
17                 Variable context = Variables.getPossibleContext(graph, variable);
18                 if(context != null) {
19                         RVI rvi = variable.getRVI(graph);
20                         Resource contextResource = context.getRepresents(graph);
21                         this.context = contextResource.getResourceId();
22                         this.rvi = rvi.toString();
23                 } else {
24                         this.context = 0;
25                         this.rvi = variable.getURI(graph);
26                 }
27
28                 this.variable = variable;
29
30         }
31         
32         public Variable getVariable(ReadGraph graph) throws DatabaseException {
33                 if(context != 0) {
34                         Resource contextResource = graph.getService(SerialisationSupport.class).getResource(context);
35                         Variable context = Variables.getVariable(graph, contextResource);
36                         RVI rvi = RVI.fromResourceFormat(graph, this.rvi);
37                         return rvi.resolve(graph, context);
38                 } else {
39                         return Variables.getVariable(graph, rvi);
40                 }
41         }
42         
43         public Variable getVariable() {
44                 return variable;
45         }
46         
47 }