package org.simantics.structural2.variables;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.set.hash.THashSet;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.Statement;
-import org.simantics.db.common.utils.Logger;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.exception.NoSingleResultException;
import org.simantics.db.layer0.function.All;
import org.simantics.utils.datastructures.Pair;
import org.slf4j.LoggerFactory;
+import gnu.trove.map.hash.THashMap;
+
public class StandardProceduralChildVariable extends AbstractChildVariable {
- private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(StandardProceduralChildVariable.class);
+ private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(StandardProceduralChildVariable.class);
+
/*
* Extension points
*
final private Map<String, Variable> properties;
final private List<Object> propertyIdentity;
- public static class FixedConnection implements org.simantics.structural2.variables.Connection {
-
- final public Collection<Pair<String,Resource>> cps = new ArrayList<Pair<String,Resource>>();
-
- final private Variable parent;
-
- public FixedConnection(Variable parent) {
- this.parent = parent;
- }
-
- @Override
- public Collection<Variable> getConnectionPoints(ReadGraph graph, Resource relationType) throws DatabaseException {
-
- Set<Variable> result = new THashSet<Variable>();
- for(Pair<String,Resource> cp : cps) {
- Variable component = cp.first == null ? parent : parent.getChild(graph, cp.first);
- Variable cp2 = component.getPossibleProperty(graph, cp.second);
- if(cp2 != null)
- for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second, relationType)) {
- result.add(desc.getVariable(graph));
- }
- else
- LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
- }
- return result;
-
- }
-
- @Override
- public Collection<String> getConnectionPointURIs(ReadGraph graph, Resource relationType) throws DatabaseException {
-
- Set<String> result = new THashSet<String>();
- for(Pair<String,Resource> cp : cps) {
- Variable component = cp.first == null ? parent : parent.getChild(graph, cp.first);
- Variable cp2 = component.getPossibleProperty(graph, cp.second);
- 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));
- }
- return result;
-
- }
-
- @Override
- public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph, Resource relationType) throws DatabaseException {
-
- Set<VariableConnectionPointDescriptor> result = new THashSet<VariableConnectionPointDescriptor>();
- for(Pair<String,Resource> cp : cps) {
- Variable component = cp.first == null ? parent : parent.getChild(graph, cp.first);
- Variable cp2 = component.getPossibleProperty(graph, cp.second);
- if(cp2 != null)
- result.addAll(ConnectionBrowser.flatten(graph, component, cp.second, relationType));
- else
- LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
- }
- return result;
-
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((cps == null) ? 0 : cps.hashCode());
- result = prime * result
- + ((parent == null) ? 0 : parent.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- FixedConnection other = (FixedConnection) obj;
- if (cps == null) {
- if (other.cps != null)
- return false;
- } else if (!cps.equals(other.cps))
- return false;
- if (parent == null) {
- if (other.parent != null)
- return false;
- } else if (!parent.equals(other.parent))
- return false;
- return true;
- }
-
- }
-
public StandardProceduralChildVariable(ReadGraph graph, Variable parent, VariableNode node, String name, Resource type, List<Property> properties, Collection<Connection> conns) throws DatabaseException {
super(node);
assert name != null;
for(Property p : properties) {
String pn = graph.getRelatedValue(p.relation, L0.HasName, Bindings.STRING);
if(p.value == null) {
- Logger.defaultLogError("StandardProceduralChildVariable " + getURI(graph) + ": null value for property " + pn);
+ LOGGER.error("StandardProceduralChildVariable " + getURI(graph) + ": null value for property " + pn);
} else if (p.value instanceof Expression) {
Expression expression = (Expression)p.value;
this.properties.put(pn, new StructuralProceduralExpressionPropertyVariable(graph, this, p.relation, expression.text) );
fc = new FixedConnection(parent);
map.put(p, fc);
}
- fc.cps.addAll(cps);
+ fc.addAll(cps);
}
}
for(Map.Entry<Resource, FixedConnection> entry : map.entrySet()) {
public Resource getType(ReadGraph graph, Resource baseType) throws DatabaseException {
if (graph.isInheritedFrom(type, baseType))
return type;
- throw new NoSingleResultException("variable " + getPossibleURI(graph) + " has no type");
+ throw new NoSingleResultException("variable " + getPossibleURI(graph) + " has no type", -1);
}
@Override