X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.graph.compiler%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Fcompiler%2Finternal%2Ftemplates%2FLoadBytesTemplate.java;fp=bundles%2Forg.simantics.graph.compiler%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Fcompiler%2Finternal%2Ftemplates%2FLoadBytesTemplate.java;h=a9e3dd62823c18fe45fa3604917ba7b8de1330dd;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/templates/LoadBytesTemplate.java b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/templates/LoadBytesTemplate.java new file mode 100644 index 000000000..a9e3dd628 --- /dev/null +++ b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/templates/LoadBytesTemplate.java @@ -0,0 +1,42 @@ +package org.simantics.graph.compiler.internal.templates; + +import java.io.IOException; +import java.util.Collection; + +import org.simantics.databoard.Bindings; +import org.simantics.databoard.binding.mutable.Variant; +import org.simantics.graph.compiler.ExternalFileLoader; +import org.simantics.graph.compiler.internal.store.LocationStore; +import org.simantics.graph.compiler.internal.store.PreValueStore; +import org.simantics.graph.query.IGraph; +import org.simantics.graph.store.GraphStore; +import org.simantics.ltk.Location; +import org.simantics.ltk.Problem; + +public enum LoadBytesTemplate implements ITemplate { + INSTANCE; + + @Override + public void apply(IGraph graph, GraphStore store, + int[] parameters, ExternalFileLoader fileLoader, Collection problems) { + String fileName = store.getStore(PreValueStore.class).getStringValue(parameters[1]); + if(fileName == null) { + Location location = store.getStore(LocationStore.class) + .getLocation(parameters[1]); + problems.add(new Problem( + location, "Expected a string")); + } + try { + byte[] data = fileLoader.load(fileName); + store.values.setValue(parameters[0], + new Variant(Bindings.BYTE_ARRAY, data) + ); + } catch (IOException e) { + Location location = store.getStore(LocationStore.class) + .getLocation(parameters[1]); + problems.add(new Problem( + location, e.getMessage())); + } + } + +}