+
+ private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(Functions.class);
+
+ private static class PrimitivePropertyStatementsProcedure implements AsyncProcedure<DirectStatements> {
+
+ public DirectStatements result;
+
+ @Override
+ public void execute(AsyncReadGraph graph, DirectStatements result) {
+ this.result = result;
+ }
+
+ @Override
+ public void exception(AsyncReadGraph graph, Throwable throwable) {
+ }
+
+ }
+
+ @SCLValue(type = "VariableMap")
+ public static VariableMap primitiveProperties = new VariableMapImpl() {
+ private void storePropertyValueAndExceptions(ReadGraph graph, Variable parent, String name, Variable property, Map<String, Variable> map) {
+ try {
+ Object value = property.getValue(graph);
+ map.put(name, new ConstantPropertyVariable(parent, name, value, null));
+ } catch (DatabaseException e) {
+ Variable propertyExceptions = map.get(NodeRequest.PROPERTY_VALUE_EXCEPTIONS);
+ Map<String, Exception> exceptionMap;
+ if (propertyExceptions == null) {
+ exceptionMap = new TreeMap<String, Exception>();
+ propertyExceptions = new ConstantPropertyVariable(parent, NodeRequest.PROPERTY_VALUE_EXCEPTIONS, exceptionMap, null);
+ map.put(NodeRequest.PROPERTY_VALUE_EXCEPTIONS, propertyExceptions);
+ } else {
+ try {
+ exceptionMap = propertyExceptions.getValue(graph);
+ } catch (DatabaseException e1) {
+ Logger.defaultLogError(e1);
+ return;
+ }
+ }
+ String label = name;
+ try {
+ label = property.getLabel(graph);
+ } catch (DatabaseException e2) {
+
+ }
+ exceptionMap.put(label, e);
+ }
+ }
+
+ @Override
+ public Variable getVariable(ReadGraph graph, Variable context, String name) throws DatabaseException {
+ return All.getStandardPropertyDomainPropertyVariableFromValue(graph, context, name);
+ }
+
+ @Override
+ public Map<String, Variable> getVariables(final ReadGraph graph, Variable context, Map<String, Variable> map) throws DatabaseException {
+
+ if(map == null) map = new HashMap<String,Variable>();
+
+ Variable parent = context.getParent(graph);
+
+ DocumentationResource DOC = DocumentationResource.getInstance(graph);
+
+ if(parent instanceof StandardProceduralChildVariable) {
+
+ StandardProceduralChildVariable procedural = (StandardProceduralChildVariable)parent;
+ for(Variable property : procedural.getProperties(graph/*, DocumentationResource.URIs.Document_AttributeRelation*/)) {
+ if(property instanceof StandardAssertedGraphPropertyVariable) {
+ StandardAssertedGraphPropertyVariable ass = (StandardAssertedGraphPropertyVariable)property;
+ if("dataDefinitions".equals(ass.property.name) || "commands".equals(ass.property.name) || "pollingFunction".equals(ass.property.name)) {
+ storePropertyValueAndExceptions(graph, parent, ass.property.name, property, map);
+ }
+ continue;
+ }
+ Resource predicate = property.getPossiblePredicateResource(graph);
+ if(predicate != null) {
+ PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(predicate));
+ if(info.hasClassification(DocumentationResource.URIs.Document_AttributeRelation)) {
+ Variable prop = parent.getProperty(graph, predicate);
+ storePropertyValueAndExceptions(graph, parent, info.name, prop, map);
+ }
+ }
+ }
+
+ } else {
+
+ Resource parentRes = parent.getRepresents(graph);
+ {
+ Variable prop = new StandardGraphPropertyVariable(graph, parent, DOC.Properties_commands);
+ storePropertyValueAndExceptions(graph, parent, "commands", prop, map);
+ }
+
+ if (graph.getPossibleObject(parentRes, DOC.Properties_dataDefinitions) != null) {
+ Variable prop = new StandardGraphPropertyVariable(graph, parent, DOC.Properties_dataDefinitions);
+ storePropertyValueAndExceptions(graph, parent, "dataDefinitions", prop, map);
+ }
+
+ DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class);
+ PrimitivePropertyStatementsProcedure foo = new PrimitivePropertyStatementsProcedure();
+
+ dqs.forEachDirectPersistentStatement(graph, parentRes, foo);
+
+ for(Statement stm : foo.result) {
+ Resource predicate = stm.getPredicate();
+ PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(predicate));
+
+ if(info.isHasProperty && info.hasClassification(DocumentationResource.URIs.Document_AttributeRelation)) {
+ Variable prop = new StandardGraphPropertyVariable(graph, parent, predicate);
+ storePropertyValueAndExceptions(graph, parent, info.name, prop, map);
+ } else {
+ Resource definition = graph.getPossibleObject(predicate, DOC.Document_definesAttributeRelation);
+ if(definition != null) {
+ PropertyInfo info2 = graph.syncRequest(new PropertyInfoRequest(definition));
+ Variable prop = new StandardGraphPropertyVariable(graph, parent, definition);
+ map.put(info2.name, new PrimitiveValueVariable(parent, info2.name, prop));
+ }
+ }
+ }
+ }
+ return map;
+
+ }
+
+ };
+