import org.simantics.db.Resource;
import org.simantics.db.WriteGraph;
import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.function.All;
import org.simantics.utils.ObjectUtils;
public class ConstantPropertyVariable extends AbstractPropertyVariable {
final Object value;
final Binding binding;
final Map<String, Variable> properties;
+ final private Resource predicate;
- public ConstantPropertyVariable(Variable parent, String name, Object value, Binding binding, Collection<ConstantPropertyVariableBuilder> propertyBuilders, Set<String> classifications) {
+ public ConstantPropertyVariable(Variable parent, String name, Object value, Binding binding, Resource predicate, Collection<ConstantPropertyVariableBuilder> propertyBuilders, Set<String> classifications) {
assert parent != null;
assert name != null;
this.parent = parent;
this.name = name;
this.value = value;
this.binding = binding;
+ this.predicate = predicate;
this.properties = new HashMap<String, Variable>(propertyBuilders.size());
for(ConstantPropertyVariableBuilder builder : propertyBuilders) {
- properties.put(builder.getName(), builder.build(this));
+ properties.put(builder.getName(), builder.build(this));
}
if(!classifications.isEmpty())
- properties.put(Variables.CLASSIFICATIONS, new ConstantPropertyVariable(this, Variables.CLASSIFICATIONS, classifications, null));
+ properties.put(Variables.CLASSIFICATIONS, new ConstantPropertyVariable(this, Variables.CLASSIFICATIONS, classifications, null));
}
- public ConstantPropertyVariable(Variable parent, String name, Object value, Binding binding) {
- this(parent, name, value, binding, Collections.<ConstantPropertyVariableBuilder>emptyList(), Collections.<String>emptySet());
+ public ConstantPropertyVariable(Variable parent, String name, Object value, Binding binding, Collection<ConstantPropertyVariableBuilder> propertyBuilders, Set<String> classifications) {
+ this(parent, name, value, binding, null, Collections.<ConstantPropertyVariableBuilder>emptyList(), Collections.<String>emptySet());
}
+ public ConstantPropertyVariable(Variable parent, String name, Object value, Binding binding) {
+ this(parent, name, value, binding, Collections.<ConstantPropertyVariableBuilder>emptyList(), Collections.<String>emptySet());
+ }
+
@Override
public <T> T getValue(ReadGraph graph) throws DatabaseException {
return (T)value;
@Override
public Resource getPropertyResource(ReadGraph graph) throws DatabaseException {
- return null;
+ return predicate;
}
@Override
@Override
protected Variable getPossibleDomainProperty(ReadGraph graph, String name)
throws DatabaseException {
- return properties.get(name);
+ Variable result = properties.get(name);
+ if(result != null) return result;
+ if(predicate != null) {
+ HashMap<String,Variable> ps = new HashMap<String,Variable>();
+ All.collectPropertiesFromContext(graph, this, predicate, ps);
+ return ps.get(name);
+ }
+ return null;
}
@Override
if(properties == null) properties = new HashMap<String,Variable>(this.properties.size());
properties.putAll(this.properties);
}
+ if(predicate != null) All.collectPropertiesFromContext(graph, this, predicate, properties);
return properties;
}