package org.simantics.document.server.request; import gnu.trove.map.hash.THashMap; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; import org.simantics.db.ReadGraph; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.request.VariableRead; import org.simantics.db.layer0.variable.Variable; import org.simantics.document.base.ontology.DocumentationResource; import org.simantics.document.server.DocumentServerUtils; import org.simantics.structural.stubs.StructuralResource2; class NodeRequestDynamic extends VariableRead> { public NodeRequestDynamic(Variable node) { super(node); } @Override public Map perform(ReadGraph graph) throws DatabaseException { long s = System.nanoTime(); StructuralResource2.getInstance(graph); DocumentationResource DOC = DocumentationResource.getInstance(graph); Collection attributes = DocumentServerUtils.getDynamicAttributes(graph, DOC, variable); if(attributes.isEmpty()) return Collections.emptyMap(); Map result = new THashMap(); for(Variable attrib : attributes) { String name = attrib.getName(graph); try { Object value = DocumentServerUtils.getValue(graph, attrib); result.put(name, value); } catch (Throwable t) { @SuppressWarnings("unchecked") List errorList = (List) result.get(NodeRequest.ERRORS); if(errorList == null) errorList = new ArrayList(); String errorMessage = NodeRequestUtils.formatErrorMessage(name, t); errorList.add(errorMessage); result.put(NodeRequest.ERRORS, errorList); } } if(DocumentRequest.PROFILE) { long dura = System.nanoTime()-s; System.err.println("NodeRequestDynamic " + System.identityHashCode(this) + " " + variable.getURI(graph) + " in " + 1e-6*dura + "ms." + result); } return result; } }