*/
public class SCLComputationalValue extends ContextualRelatedValue {
+ // TODO: unify and merge CompileValueRequest and CompileResourceValueRequest as one
@Override
public Function1<Object,Object> getFunction(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException {
- if (s != null && p != null && o != null) {
- return CompileValueRequest.compile(graph, s, o, p);
+ if (p != null && o != null) {
+ // we are now at Variable context
+ return CompileValueRequest.compile(graph, o, p);
} else if (o != null) {
+ // we are now at Resource context
return CompileResourceValueRequest.compile(graph, o);
} else {
throw new DatabaseException("Could not compile SCL expression: s=" + s + " p=" + p + " o=" + o);
}
protected final Resource relation;
- protected final Resource component;
protected final Resource literal;
- public CompileValueRequest(Resource component, Resource literal, Resource relation) {
+ public CompileValueRequest(Resource literal, Resource relation) {
this.relation = relation;
- this.component = component;
this.literal = literal;
}
public CompileValueRequest(ReadGraph graph, Variable context) throws DatabaseException {
- this(context.getParent(graph).getRepresents(graph),
- context.getRepresents(graph),
- context.getPredicateResource(graph));
+ this(context.getRepresents(graph), context.getPredicateResource(graph));
}
public static Object compileAndEvaluate(ReadGraph graph, Variable context) throws DatabaseException {
}
}
- public static Function1<Object,Object> compile(ReadGraph graph, Resource component, Resource literal, Resource predicate) throws DatabaseException {
+ public static Function1<Object,Object> compile(ReadGraph graph, Resource literal, Resource predicate) throws DatabaseException {
SCLContext sclContext = SCLContext.getCurrent();
Object oldGraph = sclContext.get("graph");
try {
- Function1<Object,Object> exp = graph.syncRequest(new CompileValueRequest(component, literal, predicate),
- TransientCacheListener.instance());
+ Function1<Object,Object> exp = graph.syncRequest(new CompileValueRequest(literal, predicate), TransientCacheListener.instance());
sclContext.put("graph", graph);
return exp;
} catch (DatabaseException e) {
fillEnvironmentSpecification(environmentSpecification);
Layer0 L0 = Layer0.getInstance(graph);
- Collection<Resource> sclModules = graph.syncRequest(new ObjectsWithType(parameter, L0.ConsistsOf, L0.SCLModule));
- for (Resource sclModule : sclModules)
- environmentSpecification.importModule(graph.getURI(sclModule), "");
+ if (parameter != null) {
+ Collection<Resource> sclModules = graph.syncRequest(new ObjectsWithType(parameter, L0.ConsistsOf, L0.SCLModule));
+ for (Resource sclModule : sclModules) {
+ environmentSpecification.importModule(graph.getURI(sclModule), "");
+ }
+ } else {
+ // `parameter` is optional and can be null for e.g. procedural user components
+ }
Resource mainModule = Layer0Utils.getPossibleChild(graph, parameter2, "SCLMain");
if(mainModule != null)
package org.simantics.document.server.request;
+import java.util.Collections;
import java.util.Map;
import org.simantics.databoard.Bindings;
}
public ServerSCLValueRequest(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException {
- this(getComponentTypeAndRoot(graph, s), o, resolveExpectedValueType(graph, p));
+ this(getComponentTypeAndRoot(graph, s, o), o, resolveExpectedValueType(graph, p));
}
private static Pair<Resource,Resource> getComponentTypeAndRoot(ReadGraph graph, Variable property) throws DatabaseException {
return Pair.make(parent.getType(graph), root);
}
- private static Pair<Resource,Resource> getComponentTypeAndRoot(ReadGraph graph, Resource component) throws DatabaseException {
+ private static Pair<Resource,Resource> getComponentTypeAndRoot(ReadGraph graph, Resource component, Resource literal) throws DatabaseException {
if(component != null) {
Resource type = graph.syncRequest(new FindPossibleComponentTypeRequest(component));
if(type != null) {
return Pair.make(null, root);
}
}
- }
- throw new IllegalStateException();
+ // TODO: For Antti to consider and fix later
+ // Introduced to handle procedural user components where component == null
+ } else if (literal != null) {
+ Resource root = graph.syncRequest(new IndexRoot(literal));
+ return Pair.make(null, root);
+ } else {
+ throw new DatabaseException("Couldn't resolve component type and root for component == null && literal == null");
+ }
}
public static Object compileAndEvaluate(ReadGraph graph, Variable context) throws DatabaseException {
public CompilationContext perform(ReadGraph graph)
throws DatabaseException {
RuntimeEnvironment runtimeEnvironment = graph.syncRequest(getRuntimeEnvironmentRequest(parameter.first, parameter.second));
- Map<String, ComponentTypeProperty> propertyMap =
+ Map<String, ComponentTypeProperty> propertyMap;
+ if (parameter.first != null) {
+ propertyMap =
graph.syncRequest(new ReadComponentTypeInterfaceRequest(parameter.first, runtimeEnvironment.getEnvironment()),
TransientCacheListener.<Map<String, ComponentTypeProperty>>instance());
+ } else {
+ // TODO: Antti to consider
+ // To handle procedural user components
+ propertyMap = Collections.emptyMap();
+ }
return new CompilationContext(runtimeEnvironment, propertyMap);
}
});
import gnu.trove.map.hash.THashMap;
+import java.util.Collections;
import java.util.Map;
import org.simantics.databoard.Bindings;
@Override
public Map<String, ComponentTypeProperty> perform(ReadGraph graph)
throws DatabaseException {
-
+ if (resource == null)
+ return Collections.emptyMap();
+
THashMap<String, ComponentTypeProperty> result =
new THashMap<String, ComponentTypeProperty>();
- collect(graph, resource, result);
+ // TODO: For Antti to consider
+ // resource == null with procedural user components
+ if (resource != null)
+ collect(graph, resource, result);
//for(Resource t : graph.getSupertypes(resource)) collect(graph, t, result);
return result;
for (Pair<String, Resource> cp : cps) {
Variable component = cp.first == null ? procedural : procedural.getChild(graph, cp.first);
Variable cp2 = component.getPossibleProperty(graph, cp.second);
- if (cp2 != null)
+ if (cp2 != null) {
for (VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second,
relationType)) {
result.add(desc.getURI(graph));
}
- else
- LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
+ } else {
+ logWarn(graph, cp, component, procedural);
+ }
}
return result;
}
@Override
public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph,
Resource relationType) throws DatabaseException {
- Set<VariableConnectionPointDescriptor> result = new THashSet<VariableConnectionPointDescriptor>();
+ Set<VariableConnectionPointDescriptor> result = new THashSet<>();
for (Pair<String, Resource> cp : cps) {
Variable component = cp.first == null ? procedural : procedural.getChild(graph, cp.first);
Variable cp2 = component.getPossibleProperty(graph, cp.second);
- if (cp2 != null)
+ if (cp2 != null) {
result.addAll(ConnectionBrowser.flatten(graph, component, cp.second, relationType));
- else
- LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
+ } else {
+ logWarn(graph, cp, component, procedural);
+ }
}
return result;
}
@Override
public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph,
Variable component, Resource relationType) throws DatabaseException {
- Set<VariableConnectionPointDescriptor> result = new THashSet<VariableConnectionPointDescriptor>();
+ Set<VariableConnectionPointDescriptor> result = new THashSet<>();
+ Variable procedural = component.getParent(graph);
for (Pair<String, Resource> cp : cps) {
- Variable base = cp.first == null ? component.getParent(graph) : component;
+ Variable base = cp.first == null ? procedural : procedural.getChild(graph, cp.first);
Variable cp2 = base.getPossibleProperty(graph, cp.second);
- if (cp2 != null)
+ if (cp2 != null) {
result.addAll(ConnectionBrowser.flatten(graph, base, cp.second, relationType));
- else
- LOGGER.warn("no cp " + cp.first + " for " + base.getURI(graph));
+ } else {
+ logWarn(graph, cp, base, procedural);
+ }
}
return result;
}
@Override
public Collection<Variable> getConnectionPoints(ReadGraph graph, Variable component, Resource relationType)
throws DatabaseException {
- Set<Variable> result = new THashSet<Variable>();
+ Set<Variable> result = new THashSet<>();
+ Variable procedural = component.getParent(graph);
for (Pair<String, Resource> cp : cps) {
- Variable base = cp.first == null ? component.getParent(graph) : component;
+ Variable base = cp.first == null ? procedural : procedural.getChild(graph, cp.first);
Variable cp2 = base.getPossibleProperty(graph, cp.second);
- if (cp2 != null)
+ if (cp2 != null) {
for (VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, base, cp.second,
relationType)) {
result.add(desc.getVariable(graph));
}
- else
- LOGGER.warn("no cp " + cp.first + " for " + base.getURI(graph));
+ } else {
+ logWarn(graph, cp, base, procedural);
+ }
}
return result;
}
@Override
public Collection<String> getConnectionPointURIs(ReadGraph graph, Variable component, Resource relationType)
throws DatabaseException {
- Set<String> result = new THashSet<String>();
+ Set<String> result = new THashSet<>();
+ Variable procedural = component.getParent(graph);
for (Pair<String, Resource> cp : cps) {
- Variable base = cp.first == null ? component.getParent(graph) : component;
+ Variable base = cp.first == null ? procedural : procedural.getChild(graph, cp.first);
Variable cp2 = base.getPossibleProperty(graph, cp.second);
- if (cp2 != null)
+ if (cp2 != null) {
for (VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, base, cp.second,
relationType)) {
result.add(desc.getURI(graph));
}
- else
- LOGGER.warn("no cp " + cp.first + " for " + base.getURI(graph));
+ } else {
+ logWarn(graph, cp, base, procedural);
+ }
}
return result;
}
return this;
}
+ private static void logWarn(ReadGraph graph, Pair<String, Resource> cp, Variable base, Variable procedural) throws DatabaseException {
+ LOGGER.warn("no cp " + cp.first + " for " + base.getURI(graph));
+ LOGGER.warn(" proc: " + procedural.getURI(graph));
+ LOGGER.warn(" rel: " + graph.getURI(cp.second));
+ LOGGER.warn(" base: " + base.getURI(graph));
+ }
+
}
\ No newline at end of file