@Override public ContextNode map(Relation relation) { return relation.followContextNode(); } }
public static ContextNode getReplacementContextNode(ContextNode contextNode) { Relation relation = getReplacementRelation(contextNode); if (relation == null) return null; return relation.followContextNode(); }
@Override public XdiInnerRoot map(Relation relation) { ContextNode contextNode = relation.followContextNode(); if (contextNode == null) return null; return XdiInnerRoot.fromContextNode(contextNode); } });
public static ContextNode getReferenceContextNode(ContextNode contextNode) { Relation relation = getReferenceRelation(contextNode); if (relation == null) return null; return relation.followContextNode(); }
private static boolean includeInnerRoot(Relation relation) { if (! allStatementsImplied(relation.followContextNode())) return true; return false; }
public static ContextNode getAggregationContextNode(ContextNode contextNode) { Relation relation = contextNode.getRelation(XDIDictionaryConstants.XDI_ADD_HAS); return relation == null ? null : relation.followContextNode(); }
public static ContextNode getIdentityContextNode(ContextNode contextNode) { Relation relation = contextNode.getRelation(XDIDictionaryConstants.XDI_ADD_IS); return relation == null ? null : relation.followContextNode(); }
/** * Factory method that creates an XDI inner root bound to a given relation. * @param relation The relation that points to an XDI inner root. * @return The XDI inner root. */ public static XdiInnerRoot fromRelation(Relation relation) { if (relation == null) throw new NullPointerException(); ContextNode contextNode = relation.followContextNode(); if (contextNode == null) return null; XdiInnerRoot xdiInnerRoot = XdiInnerRoot.fromContextNode(contextNode); if (xdiInnerRoot == null) return null; if (! xdiInnerRoot.getPredicateRelation().equals(relation)) return null; return xdiInnerRoot; }
private void putInnerRootIntoJsonObject(Relation relation, JsonObject jsonObject, JXDMapping mapping) { // include it? if (! includeInnerRoot(relation)) return; // determine key String key = mapInnerRoot(relation.getXDIAddress(), mapping); // determine child JSON object JsonElement childJsonElement = jsonObject.get(key); JsonObject childJsonObject; if (childJsonElement == null) { childJsonObject = new JsonObject(); jsonObject.add(key, childJsonObject); } else if (childJsonElement instanceof JsonArray) { childJsonObject = new JsonObject(); ((JsonArray) childJsonElement).add(childJsonElement); } else { throw new Xdi2RuntimeException("Unexpected JSON element for inner root at key " + key + ": " + childJsonElement); } // type information for child JSON object childJsonObject.add(JXDConstants.JXD_TYPE, new JsonPrimitive(JXDConstants.JXD_GRAPH)); // fill child JSON object for (ContextNode childContextNode : relation.followContextNode().getContextNodes()) { this.putContextNodeIntoJsonObject(childContextNode, childJsonObject, mapping, false); } }
public XdiPeerRoot getSelfPeerRoot() { Relation relation = this.getContextNode().getRelation(XDIDictionaryConstants.XDI_ADD_IS_REF); if (relation == null) return null; ContextNode targetContextNode = relation.followContextNode(); if (targetContextNode == null) return null; return XdiPeerRoot.fromContextNode(targetContextNode); } }
private static List<RelationshipLinkContract> findPushLinkContracts(Graph pushLinkContractsGraph, XDIAddress XDIaddress) { List<RelationshipLinkContract> pushLinkContracts = new ArrayList<RelationshipLinkContract> (); while (true) { ContextNode contextNode = pushLinkContractsGraph.getDeepContextNode(XDIaddress); if (contextNode != null) { if (log.isDebugEnabled()) log.debug("Trying to find push link contracts for context node " + contextNode); for (Relation pushLinkContractRelation : contextNode.getRelations(XDILinkContractConstants.XDI_ADD_IS_PUSH)) { if (log.isDebugEnabled()) log.debug("Trying to find push link contract for relation " + pushLinkContractRelation); ContextNode pushLinkContractContextNode = pushLinkContractRelation.followContextNode(); if (pushLinkContractContextNode == null) continue; XdiEntity pushLinkContractXdiEntity = XdiAbstractEntity.fromContextNode(pushLinkContractContextNode); if (pushLinkContractXdiEntity == null) continue; RelationshipLinkContract pushLinkContract = RelationshipLinkContract.fromXdiEntity(pushLinkContractXdiEntity); if (pushLinkContract == null) continue; for (XDIAddress pushTargetXDIAddress : pushLinkContract.getPermissionTargetXDIAddresses(XDILinkContractConstants.XDI_ADD_PUSH)) { if (log.isDebugEnabled()) log.debug("Found push link contract to address " + pushTargetXDIAddress + " for address " + XDIaddress); if (XDIAddressUtil.startsWithXDIAddress(XDIaddress, pushTargetXDIAddress) != null) { pushLinkContracts.add(pushLinkContract); break; } } } } if (XDIaddress.getNumXDIArcs() == 0) break; XDIaddress = XDIAddressUtil.parentXDIAddress(XDIaddress, -1); } // done if (log.isDebugEnabled()) log.debug("Found " + pushLinkContracts.size() + " push link contracts: " + pushLinkContracts); return pushLinkContracts; }
public static void setReplacementContextNode(ContextNode contextNode, XDIAddress replacementContextNodeXDIAddress, boolean inverse) { contextNode.delRelations(XDIDictionaryConstants.XDI_ADD_REF); contextNode.delRelations(XDIDictionaryConstants.XDI_ADD_REP); Relation relation = contextNode.setRelation(XDIDictionaryConstants.XDI_ADD_REP, replacementContextNodeXDIAddress); if (inverse) relation.followContextNode().setRelation(XDIDictionaryConstants.XDI_ADD_IS_REP, relation.getContextNode()); }
public static void setReferenceContextNode(ContextNode contextNode, XDIAddress referencecontextNodeXDIAddress, boolean inverse) { contextNode.delRelations(XDIDictionaryConstants.XDI_ADD_REF); contextNode.delRelations(XDIDictionaryConstants.XDI_ADD_REP); Relation relation = contextNode.setRelation(XDIDictionaryConstants.XDI_ADD_REF, referencecontextNodeXDIAddress); if (inverse) relation.followContextNode().setRelation(XDIDictionaryConstants.XDI_ADD_IS_REF, relation.getContextNode()); }
public static void setReplacementContextNode(ContextNode contextNode, ContextNode replacementContextNode, boolean inverse) { contextNode.delRelations(XDIDictionaryConstants.XDI_ADD_REF); contextNode.delRelations(XDIDictionaryConstants.XDI_ADD_REP); Relation relation = contextNode.setRelation(XDIDictionaryConstants.XDI_ADD_REP, replacementContextNode); if (inverse) relation.followContextNode().setRelation(XDIDictionaryConstants.XDI_ADD_IS_REP, relation.getContextNode()); }
public void setupPushPermissionInverseRelations() { ReadOnlyIterator<Relation> pushPermissionRelations = this.getPermissionsContextNode().getRelations(XDILinkContractConstants.XDI_ADD_PUSH); for (Relation pushPermissionRelation : pushPermissionRelations) { pushPermissionRelation.followContextNode().setRelation(XDILinkContractConstants.XDI_ADD_IS_PUSH, this.getContextNode().getXDIAddress()); } }
public static void setReferenceContextNode(ContextNode contextNode, ContextNode referenceContextNode, boolean inverse) { contextNode.delRelations(XDIDictionaryConstants.XDI_ADD_REF); contextNode.delRelations(XDIDictionaryConstants.XDI_ADD_REP); Relation relation = contextNode.setRelation(XDIDictionaryConstants.XDI_ADD_REF, referenceContextNode); if (inverse) relation.followContextNode().setRelation(XDIDictionaryConstants.XDI_ADD_IS_REF, relation.getContextNode()); }
@Override public boolean isImplied() { if (this instanceof ContextNodeStatement) { ContextNode contextNode = ((ContextNodeStatement) this).getContextNode(); if (contextNode == null) return false; if (! contextNode.isEmpty()) return true; if (contextNode.containsIncomingRelations()) return true; } if (this instanceof RelationStatement) { Relation relation = ((RelationStatement) this).getRelation(); if (relation == null) return false; ContextNode targetContextNode = relation.followContextNode(); if (targetContextNode == null) return false; XdiInnerRoot innerRoot = XdiInnerRoot.fromContextNode(targetContextNode); if (innerRoot != null && relation.equals(innerRoot.getPredicateRelation()) && ! innerRoot.getContextNode().isEmpty()) return true; } return false; }
/** * Returns the target inner root of the operation. * @return The target inner root of the operation. */ public XdiInnerRoot getTargetXdiInnerRoot() { ContextNode targetContextNode = this.getRelation().followContextNode(); if (targetContextNode == null) return null; XdiInnerRoot xdiInnerRoot = XdiInnerRoot.fromContextNode(targetContextNode); if (xdiInnerRoot == null) return null; if (! xdiInnerRoot.getSubjectOfInnerRoot().equals(this.getRelation().getContextNode().getXDIAddress())) return null; if (! xdiInnerRoot.getPredicateOfInnerRoot().equals(this.getRelation().getXDIAddress())) return null; return xdiInnerRoot; }
copyContextNodeContents(copyRelation.followContextNode(), targetRelation.followContextNode(), copyStrategy); } else {
ContextNode contextNode = this.getRelation().followContextNode();