+ static class DocumentPropertyKeys extends ResourceAsyncRead<List<String>> {
+
+ protected DocumentPropertyKeys(Resource resource) {
+ super(resource);
+ }
+
+ @Override
+ public void perform(AsyncReadGraph graph, final AsyncProcedure<List<String>> procedure) {
+
+ final List<String> result = new ArrayList<>();
+
+ DocumentationResource DOC = DocumentationResource.getInstance(graph);
+
+ try {
+ if(graph.hasStatement(resource, DOC.Properties_commands))
+ result.add("commands");
+ if(graph.hasStatement(resource, DOC.Properties_dataDefinitions))
+ result.add("dataDefinitions");
+ } catch(ServiceException e) {
+ LOGGER.info(e.getMessage(), e);
+ }
+
+ graph.forEachDirectPredicate(resource, new AsyncProcedure<Set<Resource>>() {
+
+ @Override
+ public void execute(AsyncReadGraph graph, Set<Resource> predicates) {
+
+ for(Resource predicate : predicates) {
+
+ try {
+
+ PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(predicate));
+
+ if(info.isHasProperty && info.hasClassification(DocumentationResource.URIs.Document_AttributeRelation)) {
+ result.add(info.name);
+ } else {
+ Resource definition = graph.getPossibleObject(predicate, DOC.Document_definesAttributeRelation);
+ if(definition != null) {
+ PropertyInfo info2 = graph.syncRequest(new PropertyInfoRequest(definition));
+ result.add(info2.name);
+ }
+ }
+
+ } catch (DatabaseException e) {
+ LOGGER.info(e.getMessage(), e);
+ }
+
+ }
+
+ procedure.execute(graph, result);
+
+ }
+
+ @Override
+ public void exception(AsyncReadGraph graph, Throwable throwable) {
+ LOGGER.info(throwable.getMessage(), throwable);
+ procedure.exception(graph, throwable);
+ }
+
+ });
+
+ }
+
+ }
+
+ static class StandardDocumentProperties implements DocumentProperties {
+
+ @Override
+ public Collection<String> getKeys(ReadGraph graph, Variable parent) throws DatabaseException {
+
+ if(parent instanceof StandardProceduralChildVariable) {
+
+ StandardProceduralChildVariable procedural = (StandardProceduralChildVariable)parent;
+ List<String> result = new ArrayList<>();
+ for(Variable property : procedural.getProperties(graph)) {
+ if(property instanceof StandardAssertedGraphPropertyVariable) {
+ StandardAssertedGraphPropertyVariable ass = (StandardAssertedGraphPropertyVariable)property;
+ if("dataDefinitions".equals(ass.property.name) || "commands".equals(ass.property.name) || "pollingFunction".equals(ass.property.name)) {
+ result.add(ass.property.name);
+ continue;
+ }
+ }
+ Resource predicate = property.getPossiblePredicateResource(graph);
+ if(predicate != null) {
+ PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(predicate));
+ if(info.hasClassification(DocumentationResource.URIs.Document_AttributeRelation)) {
+ result.add(info.name);
+ }
+ }
+ }
+
+ return result;
+
+ } else {
+
+ Resource parentRes = parent.getRepresents(graph);
+ return graph.syncRequest(new DocumentPropertyKeys(parentRes), TransientCacheAsyncListener.instance());
+
+ }
+
+ }
+
+ @Override
+ public Object getValue(ReadGraph graph, Variable context, String key) throws DatabaseException {
+ return context.getPropertyValue(graph, key);
+ }
+
+ }
+
+ public static DocumentProperties primitiveProperties() throws DatabaseException {
+ return new StandardDocumentProperties();
+ }
+