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