1 package org.simantics.graph.compiler.internal.procedures;
3 import gnu.trove.list.array.TIntArrayList;
4 import gnu.trove.map.hash.TIntObjectHashMap;
6 import java.util.Collection;
8 import org.simantics.databoard.Bindings;
9 import org.simantics.databoard.binding.Binding;
10 import org.simantics.databoard.type.Datatype;
11 import org.simantics.graph.compiler.internal.store.PreValueStore;
12 import org.simantics.graph.query.IDataTypeQuery;
13 import org.simantics.graph.query.IGraph;
14 import org.simantics.graph.query.Paths;
15 import org.simantics.graph.store.GraphStore;
16 import org.simantics.graph.store.StatementStore;
17 import org.simantics.graph.store.ValueStore;
18 import org.simantics.ltk.Problem;
20 public class ConvertPreValues implements Runnable {
24 Collection<Problem> problems;
26 public ConvertPreValues(IGraph cg, GraphStore store,
27 Collection<Problem> problems) {
30 this.problems = problems;
35 PreValueStore preValues = store.getStore(PreValueStore.class);
36 preValues.convertPreValues(store.values, new IDataTypeQuery() {
38 Paths paths = cg.getPaths();
39 StatementStore statements = store.statements;
40 ValueStore values = store.values;
41 int HasDatatype = store.identities.createPathToId(paths.HasDatatype);
42 int InstanceOf = store.identities.createPathToId(paths.InstanceOf);
45 public Binding getDataType(int id) {
46 TIntArrayList objects = statements.getObjects(id, HasDatatype);
47 if(objects.isEmpty()) {
48 objects = statements.getObjects(id, InstanceOf);
49 for(int i=0;i<objects.size();++i) {
50 int type = objects.getQuick(i);
51 Binding binding = getDatatypeForType(type);
58 Datatype dt = values.getDatatypeValue(objects.getQuick(0));
62 return Bindings.getBinding(dt);
66 TIntObjectHashMap<Binding> typeBindingCache = new TIntObjectHashMap<Binding>();
67 private Binding getDatatypeForType(int type) {
68 if(typeBindingCache.containsKey(type))
69 return typeBindingCache.get(type);
71 Datatype dt = cg.getAssertedDatatype(store.idToRes(type));
72 Binding binding = dt == null ? null : Bindings.getBinding(dt);
73 typeBindingCache.put(type, binding);