import java.io.PrintStream;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
-import java.nio.BufferUnderflowException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import org.simantics.db.exception.ResourceNotFoundException;
import org.simantics.db.exception.ServiceException;
import org.simantics.db.exception.ValidationException;
-import org.simantics.db.impl.BlockingAsyncProcedure;
import org.simantics.db.impl.RelationContextImpl;
import org.simantics.db.impl.ResourceImpl;
import org.simantics.db.impl.internal.RandomAccessValueSupport;
assert (subject != null);
+ byte[] bytes = null;
try {
- byte[] bytes = processor.getValue(this, subject);
+ bytes = processor.getValue(this, subject);
if (bytes == null) throw new DoesNotContainValueException("No value for resource " + subject);
Serializer serializer = getSerializer(binding);
throw new DoesNotContainValueException(e);
- } catch (IOException e) {
-
- throw new ServiceException(e);
-
- } catch (DatabaseException e) {
-
- throw new ServiceException(e);
-
- } catch (BufferUnderflowException e) {
- // This is sometimes thrown when deserialize fails because wrong format.
- // For callers of this method this is just an service exception.
- throw new ServiceException(e);
- }
-
+ } catch (Throwable t) {
+ throw new ServiceException("Could not getValue for subject " + debugString(subject) + " and binding " + String.valueOf(binding) + " with bytes " + safeArrayToString(bytes), t);
+ }
}
@Override
// else
procedure.execute(graph, (T) obj);
- } catch (IOException e) {
- procedure.exception(graph, e);
- } catch (BufferUnderflowException e) {
- procedure.exception(graph, e);
} catch (Throwable t) {
- procedure.exception(graph, t);
+ procedure.exception(graph, new ServiceException("Could not forValue for subject " + debugString(resource) + " and binding " + String.valueOf(binding) + " with bytes " + safeArrayToString(result), t));
}
-
}
@Override
});
}
+
+ private static String safeArrayToString(byte[] a) {
+ if (a == null)
+ return "null";
+ int iMax = a.length - 1;
+ if (iMax == -1)
+ return "[]";
+
+ StringBuilder b = new StringBuilder();
+ b.append('[');
+ for (int i = 0; i < 100; i++) { // limit to first 100 items
+ b.append(a[i]);
+ if (i == iMax)
+ return b.append(']').toString();
+ b.append(", ");
+ }
+ return b.append(", ... (" + a.length + ")]").toString();
+ }
@Override
public <T> void forValue(Resource subject, Binding binding,
else
procedure.execute(graph, (T) obj);
- } catch (IOException e) {
- procedure.exception(graph, e);
- } catch (BufferUnderflowException e) {
- procedure.exception(graph, e);
} catch (Throwable t) {
- procedure.exception(graph, t);
+ procedure.exception(graph, new ServiceException("Could not forValue for subject " + debugString(resource) + " and binding " + String.valueOf(binding) + " with bytes " + safeArrayToString(result), t));
}
-
}
@Override
public RuntimeEnvironmentRequest(Resource parameter) {
super(parameter);
}
-
+
protected void fillEnvironmentSpecification(EnvironmentSpecification environmentSpecification) {
}
static class UpdateListenerImpl extends UpdateListener {
-
- final EnvironmentSpecification environmentSpecification;
- final Listener<RuntimeEnvironment> callback;
-
- UpdateListenerImpl(EnvironmentSpecification environmentSpecification, Listener<RuntimeEnvironment> callback) {
- this.environmentSpecification = environmentSpecification;
- this.callback = callback;
- }
+
+ final EnvironmentSpecification environmentSpecification;
+ final Listener<RuntimeEnvironment> callback;
+
+ UpdateListenerImpl(EnvironmentSpecification environmentSpecification, Listener<RuntimeEnvironment> callback) {
+ this.environmentSpecification = environmentSpecification;
+ this.callback = callback;
+ }
@Override
public void notifyAboutUpdate() {
- if(callback.isDisposed()) {
- stopListening();
- return;
- }
- getRuntimeEnvironment(environmentSpecification, callback, this);
+ if(callback.isDisposed()) {
+ stopListening();
+ return;
+ }
+ getRuntimeEnvironment(environmentSpecification, callback, this);
}
- };
+ };
public static void getRuntimeEnvironment(EnvironmentSpecification environmentSpecification, Listener<RuntimeEnvironment> callback, UpdateListenerImpl listener) {
try {
-
+
SCLContext context = SCLContext.getCurrent();
-
+
RuntimeEnvironment env;
Object graph = context.get("graph");
if(graph == null)
env = SimanticsInternal.getSession().syncRequest(new Read<RuntimeEnvironment>() {
@Override
public RuntimeEnvironment perform(ReadGraph graph) throws DatabaseException {
-
+
SCLContext sclContext = SCLContext.getCurrent();
Object oldGraph = sclContext.get("graph");
try {
}
}
-
+
@Override
public RuntimeEnvironment perform(ReadGraph graph)
throws DatabaseException {
"StandardLibrary", "",
"Simantics/All", "");
fillEnvironmentSpecification(environmentSpecification);
+
Resource mainModule = Layer0Utils.getPossibleChild(graph, parameter, "SCLMain");
String mainModuleUri;
if(mainModule != null) {
}
else
mainModuleUri = graph.getURI(parameter) + "/#"; // Add something dummy to the model uri that cannot be in a real URI
-
- return graph.syncRequest(new ParametrizedPrimitiveRead<String, RuntimeEnvironment>(mainModuleUri) {
-
- UpdateListenerImpl sclListener;
-
- @Override
- public void register(ReadGraph graph, Listener<RuntimeEnvironment> procedure) {
-
- SCLContext context = SCLContext.getCurrent();
- Object oldGraph = context.put("graph", graph);
- try {
-
- if(procedure.isDisposed()) {
- getRuntimeEnvironment(environmentSpecification, procedure, null);
- } else {
- sclListener = new UpdateListenerImpl(environmentSpecification, procedure);
- sclListener.notifyAboutUpdate();
- }
-
- } finally {
- context.put("graph", oldGraph);
- }
-
- }
-
- @Override
- public void unregistered() {
- if(sclListener != null)
- sclListener.stopListening();
+
+ return graph.syncRequest(new ParametrizedPrimitiveRead<String, RuntimeEnvironment>(mainModuleUri) {
+
+ UpdateListenerImpl sclListener;
+
+ @Override
+ public void register(ReadGraph graph, Listener<RuntimeEnvironment> procedure) {
+
+ SCLContext context = SCLContext.getCurrent();
+ Object oldGraph = context.put("graph", graph);
+ try {
+
+ if(procedure.isDisposed()) {
+ getRuntimeEnvironment(environmentSpecification, procedure, null);
+ } else {
+ sclListener = new UpdateListenerImpl(environmentSpecification, procedure);
+ sclListener.notifyAboutUpdate();
+ }
+
+ } finally {
+ context.put("graph", oldGraph);
}
-
- });
+
+ }
+
+ @Override
+ public void unregistered() {
+ if(sclListener != null)
+ sclListener.stopListening();
+ }
+
+ });
}
-
+
@Override
public int hashCode() {
return 31*getClass().hashCode() + super.hashCode();
package org.simantics.db.layer0.util;
import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
*
* @author Hannu Niemistö
* @author Antti Villberg
+ *
+ * Difference between this class and {@code RuntimeEnvironmentRequest} is an additional parameter
+ * that is typically some component type. All modules under this resource are added to the environment
+ * in addition to the SCLMain of the root resource.
*/
public class RuntimeEnvironmentRequest2 extends BinaryRead<Resource, Resource, RuntimeEnvironment> {
- public RuntimeEnvironmentRequest2(Resource parameter, Resource parameter2) {
- super(parameter, parameter2);
+ public RuntimeEnvironmentRequest2(Resource componentType, Resource indexRoot) {
+ super(componentType, indexRoot);
}
-
+
protected void fillEnvironmentSpecification(EnvironmentSpecification environmentSpecification) {
}
}
};
- final public static void getRuntimeEnvironment(EnvironmentSpecification environmentSpecification, Listener<RuntimeEnvironment> callback, UpdateListenerImpl listener) {
+ public static void getRuntimeEnvironment(EnvironmentSpecification environmentSpecification, Listener<RuntimeEnvironment> callback, UpdateListenerImpl listener) {
try {
environmentSpecification.importModule(graph.getURI(mainModule), "");
return graph.syncRequest(new ParametrizedPrimitiveRead<EnvironmentSpecification, RuntimeEnvironment>(environmentSpecification) {
+
UpdateListenerImpl sclListener;
+
@Override
public void register(ReadGraph graph, Listener<RuntimeEnvironment> procedure) {
return 31*getClass().hashCode() + super.hashCode();
}
-}
\ No newline at end of file
+}
import java.util.List;
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
+import org.simantics.scl.compiler.environment.Environments;
import org.simantics.scl.compiler.errors.Locations;
import org.simantics.scl.compiler.internal.parsing.exceptions.SCLSyntaxErrorException;
import org.simantics.scl.compiler.internal.parsing.parser.SCLParserImpl;
return effect;
}
+ /**
+ * Use {@link Environments#getType(org.simantics.scl.compiler.environment.Environment, String)} instead.
+ */
+ @Deprecated
public static Type parseType(ITypeEnvironment environment, String text) throws SCLTypeParseException {
return parseType(new TypeElaborationContext(environment), text);
}
+ /**
+ * This method uses DUMMY_TYPE_ENVIRONMENT that almost does anything useful. Use
+ * {@link Environments#getType(org.simantics.scl.compiler.environment.Environment, String)} instead.
+ */
+ @Deprecated
public static Type parseType(String text) throws SCLTypeParseException {
return parseType(new TypeElaborationContext(DUMMY_TYPE_ENVIRONMENT), text);
}
-
+
+ /**
+ * Use {@link Environments#getType(org.simantics.scl.compiler.environment.Environment, String)} instead.
+ */
+ @Deprecated
private static Type parseType(TypeElaborationContext context, String text) throws SCLTypeParseException {
SCLParserImpl parser = new SCLParserImpl(new StringReader(text));
try {