CopyUtil.copyGraph(tempGraph, this.getBaseContextNode().getGraph(), null);
public static Node copyNode(Node node, Graph targetGraph, CopyStrategy copyStrategy) { if (node instanceof ContextNode) { return copyContextNode((ContextNode) node, targetGraph, copyStrategy); } else if (node instanceof LiteralNode) { return copyLiteralNode((LiteralNode) node, targetGraph, copyStrategy); } else { throw new IllegalArgumentException("Invalid node: " + node); } }
/** * Copies a whole graph into a target graph. * @param graph A graph. * @param targetGraph The target graph. * @param copyStrategy The strategy to determine what to copy. */ public static void copyGraph(Graph graph, Graph targetGraph, CopyStrategy copyStrategy) { if (graph == null) throw new NullPointerException(); if (targetGraph == null) throw new NullPointerException(); if (copyStrategy == null) copyStrategy = DEFAULT_COPY_STRATEGY; if (graph == targetGraph) throw new Xdi2RuntimeException("Source and target graph cannot be the same."); copyContextNodeContents(graph.getRootContextNode(true), targetGraph, copyStrategy); }
/** * Copies the contents of a context node (context nodes, relations, and the literal) 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. */ public static void copyContextNodeContents(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; copyContextNodes(contextNode, targetContextNode, copyStrategy); copyRelations(contextNode, targetContextNode, copyStrategy); copyLiteralNode(contextNode, targetContextNode, copyStrategy); }
CopyUtil.copyGraph(feedbackResultGraph, operationResultGraph, null); CopyUtil.copyContextNodeContents(refRepTargetContextNode, tempContextNode, null); CopyUtil.copyGraph(tempGraph, operationResultGraph, null); CopyUtil.copyStatement(refRepRelation.getStatement(), operationResultGraph, null);
private void processPush(Message pushedMessage, Operation operation, Graph operationResultGraph, ExecutionContext executionContext) throws Xdi2MessagingException { if (log.isDebugEnabled()) log.debug("Preparing to process pushed message " + pushedMessage); // TODO: how exactly is the $push message a response, and to what? FullMessagingResponse pushedMessagingResponse = FullMessagingResponse.fromMessageEnvelope(operation.getMessage().getMessageEnvelope()); // TODO: correctly store statements of $set operation? Graph resultGraph = ((TransportMessagingResponse) pushedMessagingResponse).getResultGraph(); if (resultGraph != null) { MessageEnvelope innerMe = MessageEnvelope.fromGraph(operation.getTargetXdiInnerRoot().getInnerGraph()); Message innerM = innerMe == null ? null : innerMe.getMessages().next(); Iterator<SetOperation> innerSOs = innerM == null ? new EmptyIterator<SetOperation> () : innerM.getSetOperations(); SetOperation innerSO = innerSOs.hasNext() ? innerSOs.next() : null; XdiInnerRoot innerIR = innerSO == null ? null : innerSO.getTargetXdiInnerRoot(); if (innerIR != null) { CopyUtil.copyGraph(innerIR.getInnerGraph(), this.getTargetGraph(executionContext), null); } } // TODO: correctly store any contracts we got? // see comment in pushedMessagingResponse.getLinkContracts() if (log.isDebugEnabled()) log.debug("Looking for link contracts from result graph of pushed messaging response " + pushedMessagingResponse.getResultGraph()); for (LinkContract pushedLinkContract : TransportMessagingResponse.getLinkContracts(pushedMessagingResponse)) { if (log.isDebugEnabled()) log.debug("Obtained link contract from result graph of pushed messaging response " + pushedLinkContract); // first delete link contract in target graph if it exists already ContextNode linkContractContextNode = this.getTargetGraph(executionContext).getDeepContextNode(pushedLinkContract.getContextNode().getXDIAddress()); if (linkContractContextNode != null) linkContractContextNode.delete(); // write link contract and index into target graph CopyUtil.copyContextNode(pushedLinkContract.getContextNode(), this.getTargetGraph(executionContext), null); XdiEntityCollection xdiLinkContractIndex = Index.getEntityIndex(this.getTargetGraph(executionContext), XDILinkContractConstants.XDI_ARC_CONTRACT, true); Index.setEntityIndexAggregation(xdiLinkContractIndex, pushedLinkContract.getXdiEntity().getXDIAddress()); } }
/** * Creates a clone of the given context node with the same contents. * @param contextNode The context node to clone. * @return The cloned context node. */ public static ContextNode cloneContextNode(ContextNode contextNode) { Graph newGraph = graphFactory.openGraph(); ContextNode newContextNode = CopyUtil.copyContextNode(contextNode, newGraph, null); return newContextNode; } }
/** * Creates a clone of the given message with the same contents. * @param message The message to clone. * @return The cloned message. */ public static Message cloneMessage(Message message, boolean newId) { MessageCollection clonedMessageCollection = new MessageEnvelope().getMessageCollection(message.getSenderXDIAddress(), true); XdiEntity xdiEntity = message.getXdiEntity(); ContextNode copiedContextNode; if (newId) { if (xdiEntity instanceof XdiEntityInstanceUnordered) { copiedContextNode = clonedMessageCollection.getXdiEntityCollection().setXdiInstanceUnordered(true, false).getContextNode(); CopyUtil.copyContextNodeContents(message.getContextNode(), copiedContextNode, null); } else if (xdiEntity instanceof XdiEntityInstanceOrdered) { copiedContextNode = clonedMessageCollection.getXdiEntityCollection().setXdiInstanceOrdered(false, true).getContextNode(); CopyUtil.copyContextNodeContents(message.getContextNode(), copiedContextNode, null); } else { throw new Xdi2RuntimeException("Unexpected message entity: " + xdiEntity + " (" + xdiEntity.getClass().getSimpleName() + ")"); } } else { copiedContextNode = CopyUtil.copyContextNode(message.getContextNode(), clonedMessageCollection.getContextNode(), null); } XdiEntity clonedXdiEntity = XdiAbstractEntity.fromContextNode(copiedContextNode); Message clonedMessage = Message.fromMessageCollectionAndXdiEntity(clonedMessageCollection, clonedXdiEntity); if (log.isTraceEnabled()) log.trace("Cloned message: " + clonedMessage.getMessageEnvelope()); return clonedMessage; }
@Override public void executeGetOnContextNodeStatement(XDIStatement contextNodeStatement, GetOperation operation, Graph operationResultGraph, ExecutionContext executionContext) throws Xdi2MessagingException { XDIAddress targetXDIAddress = contextNodeStatement.getTargetXDIAddress(); ContextNode contextNode = this.getGraph().getDeepContextNode(targetXDIAddress, false); if (contextNode == null) return; CopyUtil.copyStatement(contextNode.getStatement(), operationResultGraph, null); }
/** * Copies all relations 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 relations in the target graph. */ public static Iterator<Relation> copyRelations(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; for (Iterator<Relation> relations = contextNode.getRelations(); relations.hasNext(); ) { Relation relation = relations.next(); copyRelation(relation, targetContextNode, copyStrategy); } return targetContextNode.getRelations(); }
Node tempNode = tempResultGraph.getDeepNode(tempNodeXDIAddress, true); if (tempNode != null) CopyUtil.copyNode(tempNode, operationResultGraph, null);
/** * 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); }
CopyUtil.copyContextNode(pushLinkContract.getContextNode(), graphMessagingContainer.getGraph(), null); XdiEntityCollection xdiLinkContractIndex = Index.getEntityIndex(graphMessagingContainer.getGraph(), XDILinkContractConstants.XDI_ARC_CONTRACT, true); Index.setEntityIndexAggregation(xdiLinkContractIndex, pushLinkContract.getXdiEntity().getXDIAddress()); CopyUtil.copyContextNode(linkContract.getContextNode(), graphMessagingContainer.getGraph(), null); XdiEntityCollection xdiLinkContractIndex = Index.getEntityIndex(graphMessagingContainer.getGraph(), XDILinkContractConstants.XDI_ARC_CONTRACT, true); Index.setEntityIndexAggregation(xdiLinkContractIndex, linkContract.getXdiEntity().getXDIAddress()); CopyUtil.copyGraph(forwardingMessagingResponse.getGraph(), operationResultGraph, null); } catch (Xdi2ClientException ex) {
/** * Copies all context nodes 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 context nodes in the target graph. */ public static Iterator<ContextNode> copyContextNodes(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; for (Iterator<ContextNode> innerContextNodes = contextNode.getContextNodes(); innerContextNodes.hasNext(); ) { ContextNode innerContextNode = innerContextNodes.next(); copyContextNode(innerContextNode, targetContextNode, copyStrategy); } return targetContextNode.getContextNodes(); }
/** * Copies the contents of a context node (context nodes, relations, and the literal) into a target graph. * @param contextNode A context node from any graph. * @param targetGraph The target graph. * @param copyStrategy The strategy to determine what to copy. */ public static void copyContextNodeContents(ContextNode contextNode, Graph targetGraph, CopyStrategy copyStrategy) { if (contextNode == null) throw new NullPointerException(); if (targetGraph == null) throw new NullPointerException(); if (copyStrategy == null) copyStrategy = DEFAULT_COPY_STRATEGY; copyContextNodes(contextNode, targetGraph.getRootContextNode(false), copyStrategy); copyRelations(contextNode, targetGraph.getRootContextNode(false), copyStrategy); copyLiteralNode(contextNode, targetGraph.getRootContextNode(false), copyStrategy); }
@Override public void executeGetOnRelationStatement(XDIStatement relationStatement, GetOperation operation, Graph operationResultGraph, ExecutionContext executionContext) throws Xdi2MessagingException { XDIAddress contextNodeXDIAddress = relationStatement.getContextNodeXDIAddress(); XDIAddress relationXDIaddress = relationStatement.getRelationXDIAddress(); XDIAddress targetXDIAddress = relationStatement.getTargetXDIAddress(); ContextNode contextNode = this.getGraph().getDeepContextNode(contextNodeXDIAddress); if (contextNode == null) return; if (XDIConstants.XDI_ADD_COMMON_VARIABLE.equals(targetXDIAddress)) { Iterator<Relation> relations; if (XDIConstants.XDI_ADD_COMMON_VARIABLE.equals(relationXDIaddress)) { relations = contextNode.getRelations(); } else { relations = contextNode.getRelations(relationXDIaddress); } while (relations.hasNext()) CopyUtil.copyStatement(relations.next().getStatement(), operationResultGraph, null); } else { Relation relation = contextNode.getRelation(relationXDIaddress, targetXDIAddress); if (relation == null) return; CopyUtil.copyStatement(relation.getStatement(), operationResultGraph, null); } }
/** * Copies a relation into another graph. * @param relation A relation from any graph. * @param targetGraph The target graph. * @param copyStrategy The strategy to determine what to copy. * @return The copied relation in the target graph. */ public static Relation copyRelation(Relation relation, Graph targetGraph, CopyStrategy copyStrategy) { if (relation == null) throw new NullPointerException(); if (targetGraph == null) throw new NullPointerException(); if (copyStrategy == null) copyStrategy = DEFAULT_COPY_STRATEGY; XDIAddress relationContextNodeXDIAddress = relation.getContextNode().getXDIAddress(); ContextNode targetContextNode = targetGraph.setDeepContextNode(relationContextNodeXDIAddress); return copyRelation(relation, targetContextNode, copyStrategy); }
Node tempNode = tempResultGraph.getDeepNode(tempNodeXDIAddress, true); if (tempNode != null) CopyUtil.copyNode(tempNode, operationResultGraph, null);
/** * Copies a literal into another graph. * @param literalNode A literal from any graph. * @param targetGraph The target graph. * @param copyStrategy The strategy to determine what to copy. * @return The copied literal in the target graph. */ public static LiteralNode copyLiteralNode(LiteralNode literalNode, Graph targetGraph, CopyStrategy copyStrategy) { if (literalNode == null) throw new NullPointerException(); if (targetGraph == null) throw new NullPointerException(); if (copyStrategy == null) copyStrategy = DEFAULT_COPY_STRATEGY; XDIAddress literalNodeContextNodeXDIAddress = literalNode.getContextNode().getXDIAddress(); ContextNode targetContextNode = targetGraph.setDeepContextNode(literalNodeContextNodeXDIAddress); return copyLiteralNode(literalNode, targetContextNode, copyStrategy); }
CopyUtil.copyGraph(tempGraph, this.getBaseContextNode().getGraph(), null);