1 package org.simantics.graph.compiler.internal.templates;
3 import java.io.IOException;
4 import java.util.Collection;
6 import org.simantics.databoard.Bindings;
7 import org.simantics.databoard.binding.mutable.Variant;
8 import org.simantics.databoard.serialization.Serializer;
9 import org.simantics.graph.compiler.ExternalFileLoader;
10 import org.simantics.graph.compiler.internal.store.LocationStore;
11 import org.simantics.graph.compiler.internal.store.PreValueStore;
12 import org.simantics.graph.query.IGraph;
13 import org.simantics.graph.store.GraphStore;
14 import org.simantics.ltk.Location;
15 import org.simantics.ltk.Problem;
17 public enum LoadDataValueTemplate implements ITemplate {
21 public void apply(IGraph graph, GraphStore store,
22 int[] parameters, ExternalFileLoader fileLoader, Collection<Problem> problems) {
23 String fileName = store.getStore(PreValueStore.class).getStringValue(parameters[1]);
24 if(fileName == null) {
25 Location location = store.getStore(LocationStore.class)
26 .getLocation(parameters[1]);
27 problems.add(new Problem(
28 location, "Expected a string"));
31 byte[] bytes = fileLoader.load(fileName);
32 Serializer variantSerializer = Bindings.getSerializerUnchecked(Bindings.VARIANT);
33 Variant value = (Variant)variantSerializer.deserialize(bytes);
34 store.values.setValue(parameters[0], value);
35 } catch (IOException e) {
36 Location location = store.getStore(LocationStore.class)
37 .getLocation(parameters[1]);
38 problems.add(new Problem(
39 location, e.getMessage()));