/** * 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(); }
/** * 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); }
/** * Creates a clone of the given operation with the same contents. * @param operation The operation to clone. * @return The cloned operation. */ public static Operation cloneOperation(Operation operation, boolean newId) { Message clonedMessage = cloneMessage(operation.getMessage(), newId); clonedMessage.deleteOperations(); CopyUtil.copyRelation(operation.getRelation(), clonedMessage.getMessageEnvelope().getGraph(), null); Operation clonedOperation = clonedMessage.getOperations().next(); if (log.isTraceEnabled()) log.trace("Cloned operation: " + clonedOperation.getMessage().getMessageEnvelope()); return clonedOperation; } }