]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.document.server/src/org/simantics/document/server/VariableStructuralContext.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.document.server / src / org / simantics / document / server / VariableStructuralContext.java
1 package org.simantics.document.server;
2
3 import java.util.List;
4 import java.util.Map;
5
6 import org.simantics.databoard.adapter.AdaptException;
7 import org.simantics.databoard.binding.Binding;
8 import org.simantics.db.ReadGraph;
9 import org.simantics.db.Resource;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.db.layer0.request.VariableRead;
12 import org.simantics.db.layer0.variable.Variable;
13 import org.simantics.db.service.CollectionSupport;
14 import org.simantics.document.base.ontology.DocumentationResource;
15 import org.simantics.structural2.scl.StructuralComponent;
16
17 public class VariableStructuralContext extends StructuralComponent<Variable> {
18
19         final private Variable selfVariable;
20         final private Variable variable;
21         final private DocumentationResource DOC;
22         
23         public VariableStructuralContext(ReadGraph graph, Variable selfVariable) throws DatabaseException {
24                 this.selfVariable = selfVariable;
25                 this.variable = selfVariable.getParent(graph).getParent(graph);
26                 this.DOC = DocumentationResource.getInstance(graph);
27         }
28         
29         @Override
30         public Resource getType(ReadGraph g) throws DatabaseException {
31                 throw new UnsupportedOperationException();
32         }
33         
34         static class MapRequest extends VariableRead<Map<Resource,Variable>> {
35
36                 public MapRequest(Variable component) {
37                         super(component);
38                 }
39
40                 @Override
41                 public Map<Resource, Variable> perform(ReadGraph graph) throws DatabaseException {
42                         
43                         CollectionSupport cs = graph.getService(CollectionSupport.class);
44                         Map<Resource, Variable> result = cs.createMap(Variable.class);
45                         for(Variable property : variable.getProperties(graph)) {
46                                 Resource predicate = property.getPossiblePredicateResource(graph);
47                                 if(predicate != null)
48                                         result.put(predicate, property);
49                         }
50                         return result;
51                         
52                 }
53                 
54         }
55
56         @Override
57         public Object getValue(ReadGraph g, Resource attribute, Binding binding) throws DatabaseException, AdaptException {
58                 
59                 Map<Resource,Variable> map = g.syncRequest(new MapRequest(variable));
60                 Variable p = map.get(attribute);
61                 if(p != null) {
62                         if(binding != null)
63                                 return p.getValue(g, binding);
64                         else
65                                 return p.getValue(g);
66                 }
67                 
68                 return null;
69                 
70         }
71
72         @Override
73         public boolean isParametrized(ReadGraph g) throws DatabaseException {
74                 throw new UnsupportedOperationException();
75         }
76
77         @Override
78         public Variable getConnection(ReadGraph g, Resource connectionPoint) throws DatabaseException {
79                 throw new UnsupportedOperationException();
80         }
81
82         @SuppressWarnings({ "unchecked", "rawtypes" })
83         @Override
84         public List getConnections(ReadGraph g, Resource connectionPoint) throws DatabaseException {
85                 throw new UnsupportedOperationException();
86         }
87
88         @Override
89         public Resource getResource() {
90                 throw new UnsupportedOperationException();
91         }
92
93     @Override
94     public StructuralComponent<Variable> getContext() {
95         return null;
96     }
97
98 }