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