]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractChildVariable.java
Index tokenized lowercase versions of name and types for UI searches
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / variable / AbstractChildVariable.java
1 package org.simantics.db.layer0.variable;
2
3 import java.util.Collection;
4 import java.util.Collections;
5 import java.util.Map;
6 import java.util.Set;
7
8 import org.simantics.databoard.binding.Binding;
9 import org.simantics.db.ReadGraph;
10 import org.simantics.db.Resource;
11 import org.simantics.db.WriteGraph;
12 import org.simantics.db.common.uri.UnescapedChildMapOfResource;
13 import org.simantics.db.exception.DatabaseException;
14 import org.simantics.db.layer0.exception.MissingVariableValueException;
15 import org.simantics.db.layer0.variable.RVI.RVIPart;
16 import org.simantics.db.layer0.variable.RVI.StringRVIPart;
17 import org.simantics.db.layer0.variable.Variables.Role;
18
19 public abstract class AbstractChildVariable extends AbstractVariable {
20         
21         public AbstractChildVariable() {
22                 this(null);
23         }
24         
25         public AbstractChildVariable(VariableNode node) {
26                 super(node);
27         }
28
29     @Override
30     public Role getRole(ReadGraph graph) throws DatabaseException {
31         return Role.CHILD;
32     }
33     
34     @Override
35     public <T> T getValue(ReadGraph graph) throws DatabaseException {
36         throw new MissingVariableValueException("No value in child variable.");
37     }
38     
39     @Override
40     public <T> T getValue(ReadGraph graph, Binding binding) throws DatabaseException {
41         throw new MissingVariableValueException("No value in child variable.");
42     }
43     
44     @Override
45     public void setValue(WriteGraph graph, Object value, Binding binding)
46             throws DatabaseException {
47         throw new DatabaseException("Cannot write value to a child variable.");
48     }
49
50     
51     @Override
52     public Resource getRepresents(ReadGraph graph) throws DatabaseException {
53         Variable parent = getParent(graph);
54         if(!(parent instanceof AbstractChildVariable))
55             return null;
56         Resource parentRepresents = 
57             ((AbstractChildVariable)parent).getRepresentsForBrowsingChildResources(graph);
58         if(parentRepresents == null)
59             return null;
60         Resource result = graph.syncRequest(new UnescapedChildMapOfResource(parentRepresents))
61                 .get(getName(graph)); 
62 //      System.err.println("getRepresents " + getURI(graph) + " -> parent " + parentRepresents + " " + this + " => " + result + " " + getName(graph));
63         return result; 
64     }
65     
66     public Resource getRepresentsForBrowsingChildResources(ReadGraph graph) throws DatabaseException {
67         return getRepresents(graph);
68     }
69     
70     @Override
71     public Variable getPossibleExtraProperty(ReadGraph graph, String name) throws DatabaseException {
72         return null;
73     }
74     
75     @Override
76     public void collectExtraProperties(ReadGraph graph, Map<String, Variable> properties) throws DatabaseException {
77     }
78     
79     @Override
80     protected Variable getPossibleDomainProperty(ReadGraph graph, String name) throws DatabaseException {
81         return null;
82     }
83     
84     @Override
85     public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException {
86         return null;
87     }
88     
89     @Override
90     public Map<String, Variable> collectDomainProperties(ReadGraph graph, Map<String, Variable> map) throws DatabaseException {
91         return map;
92     }
93     
94     @Override
95     public Collection<Variable> getChildren(ReadGraph graph) throws DatabaseException {
96         return Collections.emptyList();
97     }
98     
99     @Override
100     public RVIPart getRVIPart(ReadGraph graph) throws DatabaseException {
101         return new StringRVIPart(Role.CHILD, getName(graph));
102     }
103
104     @Override
105     public Set<String> getClassifications(ReadGraph graph) throws DatabaseException {
106         return Collections.emptySet();
107     }
108
109 }