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); } }
public static Node copyNode(Node node, ContextNode targetContextNode, CopyStrategy copyStrategy) { if (node instanceof ContextNode) { return copyContextNode((ContextNode) node, targetContextNode, copyStrategy); } else if (node instanceof LiteralNode) { return copyLiteralNode((LiteralNode) node, targetContextNode, copyStrategy); } else { throw new IllegalArgumentException("Invalid node: " + node); } }
/** * 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); }
/** * 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); }
/** * 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); }
@Override public void executeGetOnAddress(XDIAddress targetXDIAddress, GetOperation operation, Graph operationResultGraph, ExecutionContext executionContext) throws Xdi2MessagingException { Node node = this.getGraph().getDeepNode(targetXDIAddress, true); if (node == null) return; if (node instanceof ContextNode) { CopyUtil.copyContextNode((ContextNode) node, operationResultGraph, null); } else if (node instanceof LiteralNode) { CopyUtil.copyLiteralNode((LiteralNode) node, operationResultGraph, null); } }
/** * 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); }