package org.simantics.db.layer0.request; import java.util.Collection; import java.util.Map; import java.util.Set; import org.simantics.databoard.Bindings; import org.simantics.databoard.accessor.reference.ChildReference; import org.simantics.databoard.binding.Binding; import org.simantics.databoard.type.Datatype; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.variable.ValueAccessor; import org.simantics.db.layer0.variable.VariableBuilder; import org.simantics.layer0.Layer0; import org.simantics.utils.datastructures.Pair; public class PropertyInfo { public final Resource predicate; public final String name; public final boolean isHasProperty; public final Set classifications; public final VariableBuilder builder; public final Resource literalRange; public final Datatype requiredDatatype; public final String requiredValueType; public final String definedUnit; public final Binding defaultBinding; public final Map> subliteralPredicates; public final ValueAccessor valueAccessor; public final boolean hasEnumerationRange; public PropertyInfo(Resource predicate, String name, boolean isHasProperty, Set classifications, VariableBuilder builder, Resource literalRange, Datatype requiredDatatype, String definedUnit, String requiredValueType, Binding defaultBinding, Map> subliteralPredicates, ValueAccessor valueAccessor, boolean hasEnumerationRange) { this.predicate = predicate; this.name = name; this.isHasProperty = isHasProperty; this.classifications = classifications; this.builder = builder; this.literalRange = literalRange; this.requiredDatatype = requiredDatatype; this.definedUnit = definedUnit; this.requiredValueType = requiredValueType; this.defaultBinding = defaultBinding; this.subliteralPredicates = subliteralPredicates; this.valueAccessor = valueAccessor; this.hasEnumerationRange = hasEnumerationRange; } public static PropertyInfo make(ReadGraph graph, Resource predicate, String name, boolean isHasProperty, Set classifications, VariableBuilder builder, Resource literalRange, Datatype requiredDatatype, String definedUnit, String requiredValueType, Map> subliteralPredicates, ValueAccessor valueAccessor, boolean hasEnumerationRange) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); if(literalRange != null) { Collection dts = graph.getAssertedObjects(literalRange, L0.HasDataType); if(dts.size() == 1) { Datatype dt = graph.getPossibleValue(dts.iterator().next(), Bindings.DATATYPE); if(requiredDatatype == null) requiredDatatype = dt; } } Binding defaultBinding = requiredDatatype != null ? Bindings.getBinding(requiredDatatype) : null; return new PropertyInfo(predicate, name, isHasProperty, classifications, builder, literalRange, requiredDatatype, definedUnit, requiredValueType, defaultBinding, subliteralPredicates, valueAccessor, hasEnumerationRange); } public boolean hasClassification(String classification) { return classifications.contains(classification); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("PropertyInfo [") .append(name) .append(" : ") .append(requiredDatatype) .append(" :: ") .append(requiredValueType) .append(", predicate=") .append(predicate) .append(", isHasProperty=") .append(isHasProperty) .append(", hasEnumerationRange=") .append(hasEnumerationRange) .append(", definedUnit=") .append(definedUnit != null ? definedUnit : "") .append(", defaultBinding=") .append(defaultBinding) .append(", valueAccessor=") .append(valueAccessor) .append("]"); return sb.toString(); } }