1 package org.simantics.db.layer0.property;
3 import java.util.ArrayList;
4 import java.util.Collections;
6 import org.simantics.databoard.Bindings;
7 import org.simantics.databoard.binding.Binding;
8 import org.simantics.db.ReadGraph;
9 import org.simantics.db.Resource;
10 import org.simantics.db.Statement;
11 import org.simantics.db.exception.DatabaseException;
12 import org.simantics.operation.Layer0X;
15 * @author Antti Villberg
16 * TODO: consider removing since this doesn't seem to be used.
18 public class Properties {
20 public static <T> T getPossibleRelatedValue(ReadGraph graph, Resource resource, Resource relation, Binding binding) throws DatabaseException {
22 T result = graph.getPossibleRelatedValue(resource, relation, binding);
23 if(result != null) return result;
26 Layer0X L0X = Layer0X.getInstance(graph);
27 ArrayList<OrderedResource> order = new ArrayList<OrderedResource>();
28 for(Statement stm : graph.getStatements(resource, L0X.ObtainsProperty)) {
29 Integer position = graph.getRelatedValue(stm.getPredicate(), L0X.NaturalNumberOrderRelation, Bindings.INTEGER);
30 order.add(new OrderedResource(position, stm.getObject()));
32 Collections.sort(order);
33 for(OrderedResource or : order) {
34 result = getPossibleRelatedValue(graph, or.r, relation, binding);
35 if(result != null) return result;
44 public static <T> T getPossibleRelatedAdapter(ReadGraph graph, Resource resource, Resource relation, Class<T> clazz) throws DatabaseException {
46 T result = graph.getPossibleRelatedAdapter(resource, relation, clazz);
47 if(result != null) return result;
50 Layer0X L0X = Layer0X.getInstance(graph);
51 ArrayList<OrderedResource> order = new ArrayList<OrderedResource>();
52 for(Statement stm : graph.getStatements(resource, L0X.ObtainsProperty)) {
53 Integer position = graph.getRelatedValue(stm.getPredicate(), L0X.NaturalNumberOrderRelation, Bindings.INTEGER);
54 order.add(new OrderedResource(position, stm.getObject()));
56 Collections.sort(order);
57 for(OrderedResource or : order) {
58 result = getPossibleRelatedAdapter(graph, or.r, relation, clazz);
59 if(result != null) return result;