1 package org.simantics.document.server.request;
3 import gnu.trove.map.hash.THashMap;
5 import java.util.ArrayList;
6 import java.util.Collection;
7 import java.util.Collections;
11 import org.simantics.db.ReadGraph;
12 import org.simantics.db.exception.DatabaseException;
13 import org.simantics.db.layer0.request.VariableRead;
14 import org.simantics.db.layer0.variable.Variable;
15 import org.simantics.document.base.ontology.DocumentationResource;
16 import org.simantics.document.server.DocumentServerUtils;
17 import org.simantics.structural.stubs.StructuralResource2;
19 class NodeRequestDynamic extends VariableRead<Map<String,Object>> {
21 public NodeRequestDynamic(Variable node) {
26 public Map<String,Object> perform(ReadGraph graph) throws DatabaseException {
28 long s = System.nanoTime();
30 StructuralResource2.getInstance(graph);
31 DocumentationResource DOC = DocumentationResource.getInstance(graph);
33 Collection<Variable> attributes = DocumentServerUtils.getDynamicAttributes(graph, DOC, variable);
34 if(attributes.isEmpty()) return Collections.emptyMap();
36 Map<String,Object> result = new THashMap<String,Object>();
37 for(Variable attrib : attributes) {
38 String name = attrib.getName(graph);
40 Object value = DocumentServerUtils.getValue(graph, attrib);
41 result.put(name, value);
42 } catch (Throwable t) {
43 @SuppressWarnings("unchecked")
44 List<String> errorList = (List<String>) result.get(NodeRequest.ERRORS);
46 errorList = new ArrayList<String>();
48 String errorMessage = NodeRequestUtils.formatErrorMessage(name, t);
50 errorList.add(errorMessage);
51 result.put(NodeRequest.ERRORS, errorList);
56 if(DocumentRequest.PROFILE) {
57 long dura = System.nanoTime()-s;
58 System.err.println("NodeRequestDynamic " + System.identityHashCode(this) + " " + variable.getURI(graph) + " in " + 1e-6*dura + "ms." + result);