@Override public LiteralNode getLiteralNode() { return this.getContextNode().getLiteralNode(); }
@Override public LiteralNode getLiteralNode(Object literalData) { return this.getContextNode().getLiteralNode(literalData); }
/** * Copies a literal of a context node into a target context node. * @param contextNode A context node from any graph. * @param targetContextNode The target context node. * @param copyStrategy The strategy to determine what to copy. * @return The copied literal in the target graph. */ public static LiteralNode copyLiteralNode(ContextNode contextNode, ContextNode targetContextNode, CopyStrategy copyStrategy) { if (contextNode == null) throw new NullPointerException(); if (targetContextNode == null) throw new NullPointerException(); if (copyStrategy == null) copyStrategy = DEFAULT_COPY_STRATEGY; LiteralNode literalNode = contextNode.getLiteralNode(); if (literalNode == null) return null; return copyLiteralNode(literalNode, targetContextNode, copyStrategy); }
@Override public Node follow() { XDIAddress targetXDIAddress = this.getTargetXDIAddress(); ContextNode targetContextNode = (ContextNode) this.getGraph().getDeepNode(targetXDIAddress.getContextNodeXDIAddress(), false); if (targetContextNode == null) { if (log.isWarnEnabled()) log.warn("Relation points to non-existent target node " + targetXDIAddress); return null; } if (targetXDIAddress.isLiteralNodeXDIAddress()) { return targetContextNode.getLiteralNode(); } else { return targetContextNode; } }
@Override public boolean evaluateInternal(PolicyEvaluationContext policyEvaluationContext) { ContextNode subject = policyEvaluationContext.getContextNode(this.getXDIStatement().getSubject()); ContextNode object = policyEvaluationContext.getContextNode((XDIAddress) this.getXDIStatement().getObject()); if (subject == null || object == null) return false; if (subject.containsLiteralNode()) { if (! (object.containsLiteralNode())) return false; Object subjectLiteralData = subject.getLiteralNode().getLiteralData(); Object objectLiteralData = object.getLiteralNode().getLiteralData(); if (subjectLiteralData == null || objectLiteralData == null) return false; return AbstractLiteralNode.LITERALDATACOMPARATOR.compare(subjectLiteralData, objectLiteralData) > 0; } return false; } }
@Override public boolean evaluateInternal(PolicyEvaluationContext policyEvaluationContext) { ContextNode subject = policyEvaluationContext.getContextNode(this.getXDIStatement().getSubject()); ContextNode object = policyEvaluationContext.getContextNode((XDIAddress) this.getXDIStatement().getObject()); if (subject == null || object == null) return false; if (subject.containsLiteralNode()) { if (! (object.containsLiteralNode())) return false; Object subjectLiteralData = subject.getLiteralNode().getLiteralData(); Object objectLiteralData = object.getLiteralNode().getLiteralData(); if (subjectLiteralData == null || objectLiteralData == null) return false; return AbstractLiteralNode.LITERALDATACOMPARATOR.compare(subjectLiteralData, objectLiteralData) < 0; } return false; } }
@Override public boolean evaluateInternal(PolicyEvaluationContext policyEvaluationContext) { ContextNode subject = policyEvaluationContext.getContextNode(this.getXDIStatement().getSubject()); ContextNode object = policyEvaluationContext.getContextNode((XDIAddress) this.getXDIStatement().getObject()); if (subject == null || object == null) return false; if (subject.containsLiteralNode()) { if (! (object.containsLiteralNode())) return false; String subjectLiteralData = subject.getLiteralNode().getLiteralDataString(); String objectLiteralData = object.getLiteralNode().getLiteralDataString(); if (subjectLiteralData == null || objectLiteralData == null) return false; return Pattern.matches(objectLiteralData, subjectLiteralData); } return false; } }
@Override public void executeDelOnLiteralStatement(XDIStatement literalStatement, DelOperation operation, Graph operationResultGraph, ExecutionContext executionContext) throws Xdi2MessagingException { XDIAddress contextNodeXDIAddress = literalStatement.getContextNodeXDIAddress(); Object literalData = literalStatement.getLiteralData(); ContextNode contextNode = this.getGraph().getDeepContextNode(contextNodeXDIAddress); if (contextNode == null) return; LiteralNode literalNode = contextNode.getLiteralNode(literalData); if (literalNode == null) return; literalNode.delete(); } }
@Override public Node getDeepNode(XDIAddress relativeNodeXDIAddress, boolean subgraph) { if (XDIConstants.XDI_ADD_ROOT.equals(relativeNodeXDIAddress)) return this; ContextNode contextNode = this; for (XDIArc contextNodeXDIArc : relativeNodeXDIAddress.getContextNodeXDIAddress().getXDIArcs()) { contextNode = contextNode.getContextNode(contextNodeXDIArc, subgraph); if (contextNode == null) return null; } if (relativeNodeXDIAddress.isLiteralNodeXDIAddress()) { return contextNode.getLiteralNode(); } else { return contextNode; } }
json.add(XDIConstants.CS_LITERAL.toString(), AbstractLiteralNode.literalDataToJsonElement(innerContextNode.getLiteralNode().getLiteralData())); } else {
@Override public void executeGetOnLiteralStatement(XDIStatement literalStatement, GetOperation operation, Graph operationResultGraph, ExecutionContext executionContext) throws Xdi2MessagingException { XDIAddress contextNodeXDIAddress = literalStatement.getContextNodeXDIAddress(); Object literalData = literalStatement.getLiteralData(); ContextNode contextNode = this.getGraph().getDeepContextNode(contextNodeXDIAddress); if (contextNode == null) return; LiteralNode literalNode = contextNode.getLiteralNode(literalData); if (literalNode == null) return; CopyUtil.copyStatement(literalNode.getStatement(), operationResultGraph, null); }
@Override public boolean evaluateInternal(PolicyEvaluationContext policyEvaluationContext) { ContextNode subject = policyEvaluationContext.getContextNode(this.getXDIStatement().getSubject()); ContextNode object = policyEvaluationContext.getContextNode((XDIAddress) this.getXDIStatement().getObject()); if (subject == null || object == null) return false; if (subject.containsLiteralNode()) { if (! (object.containsLiteralNode())) return false; Object subjectLiteralData = subject.getLiteralNode().getLiteralData(); Object objectLiteralData = object.getLiteralNode().getLiteralData(); if (subjectLiteralData == null || objectLiteralData == null) return false; return AbstractLiteralNode.isLiteralDataEqual(subjectLiteralData, objectLiteralData); } return false; } }
private void putAttributeIntoEntityJsonObject(ContextNode attributeContextNode, JsonObject entityJsonObject, XDIAddress parentXDIAddress) throws IOException { XDIAddress XDIaddress = attributeContextNode.getXDIAddress(); XDIAddress localXDIAddress = XDIAddressUtil.localXDIAddress(XDIaddress, - parentXDIAddress.getNumXDIArcs()); // set up attribute JsonObject attributeJsonObject = new JsonObject(); entityJsonObject.add(localXDIAddress.toString(), attributeJsonObject); // context nodes for (ContextNode contextNode : attributeContextNode.getContextNodes()) { if (XdiAbstractAttribute.isValid(contextNode) || XdiAttributeCollection.isValid(contextNode)) { this.putAttributeIntoEntityJsonObject(contextNode, entityJsonObject, parentXDIAddress); continue; } throw new Xdi2RuntimeException("Unexpected context node: " + contextNode + " on attribute context node: " + attributeContextNode); } // relations for (Relation relation : attributeContextNode.getRelations()) { this.putRelationIntoJsonObject(relation, attributeJsonObject); } // literal node if (attributeContextNode.containsLiteralNode()) { LiteralNode literalNode = attributeContextNode.getLiteralNode(); this.putLiteralNodeIntoAttributeJsonObject(literalNode, attributeJsonObject, XDIaddress); } // finish attribute if (attributeJsonObject.entrySet().isEmpty() && ! attributeContextNode.isEmpty()) { if (! this.isWriteImplied()) entityJsonObject.remove(localXDIAddress.toString()); } }
jsonObject.add(mapLiteralNode(localXDIAddress, mapping), AbstractLiteralNode.literalDataToJsonElement(contextNode.getLiteralNode().getLiteralData())); return; LiteralNode literalNode = contextNode.getLiteralNode();
LiteralNode literalNode = attributeContextNode.getLiteralNode();
@Override public Statement getStatement(XDIStatement statement) { ContextNode baseContextNode = this.getDeepContextNode(statement.getSubject(), false); if (baseContextNode == null) return null; if (statement.isContextNodeStatement()) { ContextNode contextNode = baseContextNode.getContextNode(statement.getContextNodeXDIArc(), false); return contextNode == null ? null : contextNode.getStatement(); } else if (statement.isRelationStatement()) { Relation relation = baseContextNode.getRelation(statement.getRelationXDIAddress(), statement.getTargetXDIAddress()); return relation == null ? null : relation.getStatement(); } else if (statement.isLiteralStatement()) { LiteralNode literalNode = baseContextNode.getLiteralNode(statement.getLiteralData()); return literalNode == null ? null : literalNode.getStatement(); } return null; }
public void testSimple() throws Exception { Graph graph0 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-0"); ContextNode markus = graph0.getRootContextNode().setContextNode(XDIArc.create("=markus")); ContextNode email = markus.setContextNode(XDIArc.create("<#email>")); email.setLiteralNode("abc@gmail.com"); markus.setRelation(XDIAddress.create("#friend"), XDIAddress.create("=drummond")); markus = graph0.getRootContextNode().getContextNode(XDIArc.create("=markus")); assertNotNull(markus); assertFalse(markus.isRootContextNode()); assertFalse(markus.isEmpty()); assertFalse(markus.isLeafContextNode()); assertTrue(markus.containsRelations()); assertFalse(markus.containsLiteralNode()); assertTrue(email.isLeafContextNode()); assertTrue(email.containsLiteralNode()); ContextNode drummond = graph0.getRootContextNode().getContextNode(XDIArc.create("=drummond")); assertNotNull(drummond); assertTrue(drummond.isEmpty()); assertTrue(drummond.isLeafContextNode()); email.setLiteralNode("xyz@gmail.com"); assertEquals(graph0.getDeepLiteralNode(XDIAddress.create("=markus<#email>&")).getLiteralData(), "xyz@gmail.com"); assertEquals(graph0.getDeepContextNode(XDIAddress.create("=markus<#email>")).getLiteralNode().getLiteralData(), "xyz@gmail.com"); graph0.close(); }
assertNull(markus.getLiteralNode()); assertFalse(markus.getContextNodes().hasNext()); try { markus.getContextNodes().next(); fail(); } catch (NoSuchElementException ex) { } assertEquals(markus.getAllRelationCount(), 0); assertNull(markus.getLiteralNode()); assertNull(markus.getDeepLiteralNode(XDIAddress.create("<*!not>&"))); assertEquals(markus.getAllLiteralCount(), 0);
public void testDelete() throws Exception { Graph graph26 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-26"); ContextNode root = graph26.getRootContextNode(); root.setContextNode(XDIArc.create("+a")); assertTrue(root.containsContextNode(XDIArc.create("+a"))); assertNotNull(root.getContextNode(XDIArc.create("+a"))); root.delContextNode(XDIArc.create("+a")); assertFalse(graph26.getRootContextNode().containsContextNode(XDIArc.create("+a"))); assertFalse(root.containsContextNode(XDIArc.create("+a"))); assertNull(graph26.getRootContextNode().getContextNode(XDIArc.create("+a"))); assertNull(root.getContextNode(XDIArc.create("+a"))); root.setRelation(XDIAddress.create("+a"), XDIAddress.create("#b")); assertTrue(root.containsRelation(XDIAddress.create("+a"), XDIAddress.create("#b"))); assertNotNull(root.getRelation(XDIAddress.create("+a"), XDIAddress.create("#b"))); root.delRelation(XDIAddress.create("+a"), XDIAddress.create("#b")); assertFalse(root.containsRelation(XDIAddress.create("+a"), XDIAddress.create("#b"))); assertNull(root.getRelation(XDIAddress.create("+a"), XDIAddress.create("#b"))); root.setDeepContextNode(XDIAddress.create("<#a>")).setLiteralNode("a"); assertTrue(root.getDeepContextNode(XDIAddress.create("<#a>")).containsLiteralNode("a")); assertNotNull(root.getDeepContextNode(XDIAddress.create("<#a>")).getLiteralNode("a")); assertNotNull(root.getDeepLiteralNode(XDIAddress.create("<#a>&"))); root.getDeepContextNode(XDIAddress.create("<#a>")).delLiteralNode(); assertFalse(root.getDeepContextNode(XDIAddress.create("<#a>")).containsLiteralNode("a")); assertNull(root.getDeepContextNode(XDIAddress.create("<#a>")).getLiteralNode("a")); assertNull(root.getDeepLiteralNode(XDIAddress.create("<#a>&"))); root.getContextNode(XDIArc.create("#b")).delete(); root.getDeepContextNode(XDIAddress.create("<#a>")).delete(); assertTrue(root.isEmpty()); graph26.close(); }
assertNotNull(graph22.getDeepContextNode(XDIAddress.create("=markus")).getRelation(XDIAddress.create("#friend"))); assertNotNull(graph22.getDeepContextNode(XDIAddress.create("=markus")).getRelation(XDIAddress.create("#friend"), XDIAddress.create("=neustar=les"))); assertNotNull(graph22.getDeepContextNode(XDIAddress.create("=markus<#email>")).getLiteralNode()); assertNotNull(graph22.getDeepContextNode(XDIAddress.create("=markus<#email>")).getLiteralNode("markus@projectdanube.org")); assertNotNull(graph23.getDeepContextNode(XDIAddress.create("=markus")).getRelation(XDIAddress.create("#friend"))); assertNotNull(graph23.getDeepContextNode(XDIAddress.create("=markus")).getRelation(XDIAddress.create("#friend"), XDIAddress.create("=neustar=les"))); assertNotNull(graph23.getDeepContextNode(XDIAddress.create("=markus<#email>")).getLiteralNode()); assertNotNull(graph23.getDeepContextNode(XDIAddress.create("=markus<#email>")).getLiteralNode("markus@projectdanube.org"));