X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.common%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fcommon%2Frequest%2FAdaptValue.java;fp=bundles%2Forg.simantics.db.common%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fcommon%2Frequest%2FAdaptValue.java;h=02877596b00d4423fac8387a31bdc73cdde76e87;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=82b6bf965ee0dc94f59a5eec005ada2b3c178dfb;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/request/AdaptValue.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/request/AdaptValue.java index 82b6bf965..02877596b 100644 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/request/AdaptValue.java +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/request/AdaptValue.java @@ -1,47 +1,47 @@ -package org.simantics.db.common.request; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.utils.Functions; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.exception.RuntimeDatabaseException; -import org.simantics.layer0.Layer0; -import org.simantics.scl.reflection.ReflectionUtils; -import org.simantics.scl.reflection.ValueNotFoundException; -import org.simantics.scl.runtime.function.FunctionImpl3; - -/** - * Adapts a resource to (SCL) value. - * @author Hannu Niemistö - */ -public class AdaptValue extends ResourceRead { - - public AdaptValue(Resource resource) { - super(resource); - } - - private static final FunctionImpl3 functionApplication = new FunctionImpl3() { - - @Override - public Object apply(ReadGraph graph, Resource resource, Object context) { - try { - return Functions.exec(graph, resource, graph, resource, context); - } catch (DatabaseException e) { - throw new RuntimeDatabaseException(e); - } - } - - }; - - @Override - public Object perform(ReadGraph graph) throws DatabaseException { - String uri = graph.getURI(resource); - try { - if(Layer0.URIs.Functions_functionApplication.equals(uri)) return functionApplication; - return ReflectionUtils.getValue(uri).getValue(); - } catch (ValueNotFoundException e) { - throw new DatabaseException("Couldn't adapt the value " + uri, e); - } - } - -} +package org.simantics.db.common.request; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.Functions; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.RuntimeDatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.scl.reflection.ReflectionUtils; +import org.simantics.scl.reflection.ValueNotFoundException; +import org.simantics.scl.runtime.function.FunctionImpl3; + +/** + * Adapts a resource to (SCL) value. + * @author Hannu Niemistö + */ +public class AdaptValue extends ResourceRead { + + public AdaptValue(Resource resource) { + super(resource); + } + + private static final FunctionImpl3 functionApplication = new FunctionImpl3() { + + @Override + public Object apply(ReadGraph graph, Resource resource, Object context) { + try { + return Functions.exec(graph, resource, graph, resource, context); + } catch (DatabaseException e) { + throw new RuntimeDatabaseException(e); + } + } + + }; + + @Override + public Object perform(ReadGraph graph) throws DatabaseException { + String uri = graph.getURI(resource); + try { + if(Layer0.URIs.Functions_functionApplication.equals(uri)) return functionApplication; + return ReflectionUtils.getValue(uri).getValue(); + } catch (ValueNotFoundException e) { + throw new DatabaseException("Couldn't adapt the value " + uri, e); + } + } + +}