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.graph.compiler.ExternalFileLoader;
\r
9 import org.simantics.graph.compiler.internal.store.LocationStore;
\r
10 import org.simantics.graph.compiler.internal.store.PreValueStore;
\r
11 import org.simantics.graph.query.IGraph;
\r
12 import org.simantics.graph.store.GraphStore;
\r
13 import org.simantics.ltk.Location;
\r
14 import org.simantics.ltk.Problem;
\r
16 public enum LoadBytesTemplate implements ITemplate {
\r
20 public void apply(IGraph graph, GraphStore store,
\r
21 int[] parameters, ExternalFileLoader fileLoader, Collection<Problem> problems) {
\r
22 String fileName = store.getStore(PreValueStore.class).getStringValue(parameters[1]);
\r
23 if(fileName == null) {
\r
24 Location location = store.getStore(LocationStore.class)
\r
25 .getLocation(parameters[1]);
\r
26 problems.add(new Problem(
\r
27 location, "Expected a string"));
\r
30 byte[] data = fileLoader.load(fileName);
\r
31 store.values.setValue(parameters[0],
\r
32 new Variant(Bindings.BYTE_ARRAY, data)
\r
34 } catch (IOException e) {
\r
35 Location location = store.getStore(LocationStore.class)
\r
36 .getLocation(parameters[1]);
\r
37 problems.add(new Problem(
\r
38 location, e.getMessage()));
\r