X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Fproperty%2FProperties.java;fp=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Fproperty%2FProperties.java;h=5d5a1183b2794dd8986ee871b6f63f9d02b7e156;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/property/Properties.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/property/Properties.java new file mode 100644 index 000000000..5d5a1183b --- /dev/null +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/property/Properties.java @@ -0,0 +1,68 @@ +package org.simantics.db.layer0.property; + +import java.util.ArrayList; +import java.util.Collections; + +import org.simantics.databoard.Bindings; +import org.simantics.databoard.binding.Binding; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Statement; +import org.simantics.db.exception.DatabaseException; +import org.simantics.operation.Layer0X; + +/** + * @author Antti Villberg + * TODO: consider removing since this doesn't seem to be used. + */ +public class Properties { + + public static T getPossibleRelatedValue(ReadGraph graph, Resource resource, Resource relation, Binding binding) throws DatabaseException { + + T result = graph.getPossibleRelatedValue(resource, relation, binding); + if(result != null) return result; + else { + + Layer0X L0X = Layer0X.getInstance(graph); + ArrayList order = new ArrayList(); + for(Statement stm : graph.getStatements(resource, L0X.ObtainsProperty)) { + Integer position = graph.getRelatedValue(stm.getPredicate(), L0X.NaturalNumberOrderRelation, Bindings.INTEGER); + order.add(new OrderedResource(position, stm.getObject())); + } + Collections.sort(order); + for(OrderedResource or : order) { + result = getPossibleRelatedValue(graph, or.r, relation, binding); + if(result != null) return result; + } + + return null; + + } + + } + + public static T getPossibleRelatedAdapter(ReadGraph graph, Resource resource, Resource relation, Class clazz) throws DatabaseException { + + T result = graph.getPossibleRelatedAdapter(resource, relation, clazz); + if(result != null) return result; + else { + + Layer0X L0X = Layer0X.getInstance(graph); + ArrayList order = new ArrayList(); + for(Statement stm : graph.getStatements(resource, L0X.ObtainsProperty)) { + Integer position = graph.getRelatedValue(stm.getPredicate(), L0X.NaturalNumberOrderRelation, Bindings.INTEGER); + order.add(new OrderedResource(position, stm.getObject())); + } + Collections.sort(order); + for(OrderedResource or : order) { + result = getPossibleRelatedAdapter(graph, or.r, relation, clazz); + if(result != null) return result; + } + + return null; + + } + + } + +}