private void putContextNodeIntoJsonObject(ContextNode contextNode, JsonObject jsonObject) { JsonArray contextNodeJsonArray = jsonObject.getAsJsonArray("//"); if (contextNodeJsonArray == null) { contextNodeJsonArray = new JsonArray(); jsonObject.add("//", contextNodeJsonArray); } contextNodeJsonArray.add(new JsonPrimitive(contextNode.getXDIArc().toString())); }
static XDIAddress fromComponents(String string, List<XDIArc> XDIarcs) { if (string == null) { StringBuffer buffer = new StringBuffer(); for (XDIArc XDIarc : XDIarcs) buffer.append(XDIarc.toString()); string = buffer.toString(); } return new XDIAddress(string, XDIarcs); }
public static XDIAddress fromComponent(XDIArc XDIarc) { return new XDIAddress(XDIarc.toString(), Collections.singletonList(XDIarc)); }
@Override public InterceptorResult after(Operation operation, Graph operationResultGraph, ExecutionContext executionContext) throws Xdi2MessagingException { // add $is statements for all the substituted variables for (Entry<XDIArc, XDIArc> entry : getVariablesPerOperation(executionContext).entrySet()) { XDIAddress subject = XDIAddress.create(entry.getKey().toString()); XDIAddress predicate = XDIDictionaryConstants.XDI_ADD_IS; XDIAddress object = XDIAddress.create(entry.getValue().toString()); XDIStatement statement = XDIStatement.fromComponents(subject, predicate, object); operationResultGraph.setStatement(statement); } // done return InterceptorResult.DEFAULT; }
@Override public boolean containsContextNode(XDIArc XDIarc) { String contextNodesKey = this.getContextNodesKey(); return this.keyValueStore.contains(contextNodesKey, XDIarc.toString()); }
public String getValue() { if (this.XDIarc != null) return this.XDIarc.toString(); if (this.partialSubject != null && this.partialPredicate != null) return this.partialSubject.toString() + "/" + this.partialPredicate.toString(); if (this.iri != null) return this.iri; if (this.literal != null) return this.literal; return null; } }
public boolean isRelationStatement() { if (! (this.getPredicate() instanceof XDIAddress)) return false; if (XDIConstants.STRING_CONTEXT.equals(this.getPredicate().toString())) return false; if (XDIConstants.XDI_ARC_LITERAL.toString().equals(this.getPredicate().toString())) return false; if (! (this.getObject() instanceof XDIAddress)) return false; return true; }
public static CloudName fromPeerRootXDIArc(XDIArc peerRootXDIArc) { if (! isValid(peerRootXDIArc)) return null; peerRootXDIArc = XDIArc.create(peerRootXDIArc.toString().toLowerCase()); XDIAddress XDIaddress = XdiPeerRoot.getXDIAddressOfPeerRootXDIArc(peerRootXDIArc); return new CloudName(XDIaddress, peerRootXDIArc); }
@Override public void delLiteralNode() { ((JSONGraph) this.getGraph()).jsonDeleteFromObject(this.getXDIAddress().toString(), XDIConstants.XDI_ARC_LITERAL.toString()); } }
@Override public LiteralNode getLiteralNode() { JsonObject jsonObject = ((JSONGraph) this.getGraph()).jsonLoad(this.getXDIAddress().toString()); if (! jsonObject.has(XDIConstants.XDI_ARC_LITERAL.toString())) return null; return new JSONLiteralNode(this); }
/** * Checks if a context node can be created. * Throws an exception, if the context node cannot be created. */ protected void setContextNodeCheckValid(XDIArc XDIarc) throws Xdi2GraphException { if (XDIarc == null) throw new NullPointerException(); if (XDIConstants.XDI_ADD_ROOT.toString().equals(XDIarc.toString())) throw new Xdi2GraphException("Invalid context node arc: " + XDIarc); /* if (this.containsRelations(XDIDictionaryConstants.XDI_ADD_REF)) throw new Xdi2GraphException("Cannot add " + XDIarc + " context node to context node " + this.getXDIAddress() + " containing a " + XDIDictionaryConstants.XDI_ADD_REF + " relation."); if (this.containsRelations(XDIDictionaryConstants.XDI_ADD_REP)) throw new Xdi2GraphException("Cannot add " + XDIarc + " context node to context node " + this.getXDIAddress() + " containing a " + XDIDictionaryConstants.XDI_ADD_REP + " relation.");*/ ContextNode tempContextNode = new DummyContextNode(this.getGraph(), this, XDIarc, null, null, null); if (! XdiAbstractContext.isValid(tempContextNode)) throw new Xdi2GraphException("Invalid subgraph: " + XDIarc + " under subgraph " + this.getXDIAddress()); }
@Override public Object getLiteralData() { JSONContextNode jsonContextNode = (JSONContextNode) this.getContextNode(); JsonObject jsonObject = ((JSONGraph) this.getGraph()).jsonLoad(jsonContextNode.getXDIAddress().toString()); JsonElement jsonElement = jsonObject.get(XDIConstants.XDI_ARC_LITERAL.toString()); if (jsonElement == null) { log.warn("In literal node " + this.getContextNode() + " found non-existent value."); return null; } return AbstractLiteralNode.jsonElementToLiteralData(jsonElement); }
@Override public ContextNode getContextNode(XDIArc XDIarc, boolean subgraph) { String contextNodesKey = this.getContextNodesKey(); String contextNodeKey = this.getContextNodeKey(XDIarc); if (! this.keyValueStore.contains(contextNodesKey, XDIarc.toString())) return null; return new KeyValueContextNode((KeyValueGraph) this.getGraph(), this, this.keyValueStore, contextNodeKey, XDIarc); }
@Override public synchronized void delContextNode(XDIArc XDIarc) { ContextNode contextNode = this.getContextNode(XDIarc, true); if (contextNode == null) return; // delete all relations and incoming relations ((KeyValueContextNode) contextNode).delContextNodeDelAllInnerRoots(); ((KeyValueContextNode) contextNode).delContextNodeDelAllIncomingRelations(); // delete this context node String contextNodesKey = this.getContextNodesKey(); this.keyValueStore.delete(contextNodesKey, XDIarc.toString()); }
static XDIStatement fromContextNodeComponents(String string, XDIAddress contextNodeXDIAddress, XDIArc contextNodeXDIArc) { if (string == null) string = contextNodeXDIAddress.toString() + "/" + XDIConstants.STRING_CONTEXT + "/" + contextNodeXDIArc.toString(); if (contextNodeXDIAddress.isLiteralNodeXDIAddress()) throw new ParserException("Cannot have literal node address " + contextNodeXDIAddress + " as subject of a contextual statement: " + string); if (contextNodeXDIArc.isLiteralNodeXDIArc()) throw new ParserException("Cannot have literal node arc " + contextNodeXDIArc + " as object of a contextual statement: " + string); return new XDIStatement(string, contextNodeXDIAddress, XDIConstants.STRING_CONTEXT, contextNodeXDIArc); }
@Override public void setLiteralData(Object literalData) { JSONContextNode jsonContextNode = (JSONContextNode) this.getContextNode(); ((JSONGraph) this.getGraph()).jsonSaveToObject(jsonContextNode.getXDIAddress().toString(), XDIConstants.XDI_ARC_LITERAL.toString(), AbstractLiteralNode.literalDataToJsonElement(literalData)); } }
@Override public ContextNode getContextNode(XDIArc XDIarc, boolean subgraph) { JsonObject jsonObject; if (subgraph) jsonObject = ((JSONGraph) this.getGraph()).jsonLoadWithPrefix(this.getXDIAddress().toString()).get(this.getXDIAddress().toString()); else jsonObject = ((JSONGraph) this.getGraph()).jsonLoad(this.getXDIAddress().toString()); if (jsonObject == null) return null; final JsonArray jsonArrayContexts = jsonObject.getAsJsonArray(XDIConstants.STRING_CONTEXT); if (jsonArrayContexts == null) return null; if (jsonArrayContexts.size() < 1) return null; if (! new IteratorContains<JsonElement> (jsonArrayContexts.iterator(), new JsonPrimitive(XDIarc.toString())).contains()) return null; XDIAddress XDIaddress = XDIAddressUtil.concatXDIAddresses(this.getXDIAddress(), XDIarc); return new JSONContextNode((JSONGraph) JSONContextNode.this.getGraph(), JSONContextNode.this, XDIarc, XDIaddress); }
@Override public LiteralNode setLiteralNode(Object literalData) { // check validity this.setLiteralCheckValid(literalData); // set the literal ((JSONGraph) this.getGraph()).jsonSaveToObject(this.getXDIAddress().toString(), XDIConstants.XDI_ARC_LITERAL.toString(), AbstractLiteralNode.literalDataToJsonElement(literalData)); JSONLiteralNode literalNode = new JSONLiteralNode(this); // done return literalNode; }
@Override public void delContextNode(XDIArc XDIarc) { ContextNode contextNode = this.getContextNode(XDIarc, true); if (contextNode == null) return; // delete all relations and incoming relations ((JSONContextNode) contextNode).delContextNodeDelAllRelations(); ((JSONContextNode) contextNode).delContextNodeDelAllIncomingRelations(); // delete this context node ((JSONGraph) this.getGraph()).jsonDelete(contextNode.getXDIAddress().toString()); ((JSONGraph) this.getGraph()).jsonDeleteFromArray(this.getXDIAddress().toString(), XDIConstants.STRING_CONTEXT, new JsonPrimitive(XDIarc.toString())); }
@Override public ContextNode setContextNode(XDIArc XDIarc) { // check validity this.setContextNodeCheckValid(XDIarc); // set the context node ((JSONGraph) this.getGraph()).jsonSaveToArray(this.getXDIAddress().toString(), XDIConstants.STRING_CONTEXT, new JsonPrimitive(XDIarc.toString())); XDIAddress XDIaddress = XDIAddressUtil.concatXDIAddresses(this.getXDIAddress(), XDIarc); JSONContextNode contextNode = new JSONContextNode((JSONGraph) this.getGraph(), this, XDIarc, XDIaddress); // set inner root this.setContextNodeSetInnerRoot(XDIarc, contextNode); // done return contextNode; }