@Override public XdiPeerRoot getPeerRoot(XDIArc peerRootXDIArc, boolean create) { if (log.isTraceEnabled()) log.trace("getPeerRoot(" + peerRootXDIArc + "," + create + ")"); ContextNode peerRootContextNode = create ? this.getContextNode().setContextNode(peerRootXDIArc) : this.getContextNode().getContextNode(peerRootXDIArc, false); if (peerRootContextNode == null) return null; return XdiPeerRoot.fromContextNode(peerRootContextNode); }
@Override public XdiInnerRoot getInnerRoot(XDIArc innerRootXDIArc, boolean create) { if (log.isTraceEnabled()) log.trace("getInnerRoot(" + innerRootXDIArc + "," + create + ")"); ContextNode innerRootContextNode = create ? this.getContextNode().setContextNode(innerRootXDIArc) : this.getContextNode().getContextNode(innerRootXDIArc, false); if (innerRootContextNode == null) return null; return XdiInnerRoot.fromContextNode(innerRootContextNode); }
@Override public XdiPeerRoot getPeerRoot(XDIAddress XDIaddress, boolean create) { if (log.isTraceEnabled()) log.trace("getPeerRoot(" + XDIaddress + "," + create + ")"); XDIArc peerRootXDIArc = XdiPeerRoot.createPeerRootXDIArc(XDIaddress); ContextNode peerRootContextNode = create ? this.getContextNode().setContextNode(peerRootXDIArc) : this.getContextNode().getContextNode(peerRootXDIArc, false); if (peerRootContextNode == null) return null; return new XdiPeerRoot(peerRootContextNode); }
@Override public XdiInnerRoot getInnerRoot(XDIAddress subject, XDIAddress predicate, boolean create) { if (log.isTraceEnabled()) log.trace("getInnerRoot(" + subject + "," + predicate + "," + create + ")"); XDIArc innerRootXDIArc = XdiInnerRoot.createInnerRootXDIArc(subject, predicate); ContextNode innerRootContextNode = create ? this.getContextNode().setContextNode(innerRootXDIArc) : this.getContextNode().getContextNode(innerRootXDIArc, false); if (innerRootContextNode == null) return null; return new XdiInnerRoot(innerRootContextNode); }
/** * Sets an XDI instance under this XDI collection. * @return The XDI instance. */ @Override public I setXdiInstance(XDIArc XDIarc) { ContextNode instanceContextNode = this.getContextNode().setContextNode(XDIarc); return XdiAbstractContext.fromContextNode(instanceContextNode, this.getI()); }
/** * Sets an XDI instance under this XDI collection. * @return The XDI instance. */ public O setXdiInstanceOrdered(boolean attribute, boolean immutable, boolean relative, long index) { String literal = index >= 0 ? Long.toString(index) : Long.toString(this.getXdiInstancesOrderedCount()); XDIArc XDIarc = XdiAbstractInstanceOrdered.createXDIArc(attribute, immutable, relative, literal, null); ContextNode contextNode = this.getContextNode().setContextNode(XDIarc); return XdiAbstractContext.fromContextNode(contextNode, this.getO()); }
@Override public XdiEntitySingleton getXdiEntitySingleton(XDIArc XDIarc, boolean create) { ContextNode entitySingletonContextNode = create ? this.getContextNode().setContextNode(XDIarc) : this.getContextNode().getContextNode(XDIarc, false); if (entitySingletonContextNode == null) return null; return XdiEntitySingleton.fromContextNode(entitySingletonContextNode); }
@Override public XdiAttribute getXdiAttribute(XDIArc XDIarc, boolean create) { ContextNode attributeContextNode = create ? this.getContextNode().setContextNode(XDIarc) : this.getContextNode().getContextNode(XDIarc, false); if (attributeContextNode == null) return null; return XdiAbstractAttribute.fromContextNode(attributeContextNode); }
@Override public XdiAttributeCollection getXdiAttributeCollection(XDIArc XDIarc, boolean create) { ContextNode attributeCollectionContextNode = create ? this.getContextNode().setContextNode(XDIarc) : this.getContextNode().getContextNode(XDIarc, false); if (attributeCollectionContextNode == null) return null; return XdiAttributeCollection.fromContextNode(attributeCollectionContextNode); }
@Override public XdiEntityCollection getXdiEntityCollection(XDIArc XDIarc, boolean create) { ContextNode entityCollectionContextNode = create ? this.getContextNode().setContextNode(XDIarc) : this.getContextNode().getContextNode(XDIarc, false); if (entityCollectionContextNode == null) return null; return XdiEntityCollection.fromContextNode(entityCollectionContextNode); }
@Override public XdiEntity getXdiEntity(XDIArc XDIarc, boolean create) { ContextNode entityContextNode = create ? this.getContextNode().setContextNode(XDIarc) : this.getContextNode().getContextNode(XDIarc, false); if (entityContextNode == null) return null; return XdiAbstractEntity.fromContextNode(entityContextNode); }
@Override public XdiAttributeSingleton getXdiAttributeSingleton(XDIArc XDIarc, boolean create) { ContextNode attributeSingletonContextNode = create ? this.getContextNode().setContextNode(XDIarc) : this.getContextNode().getContextNode(XDIarc, false); if (attributeSingletonContextNode == null) return null; return XdiAttributeSingleton.fromContextNode(attributeSingletonContextNode); }
/** * Sets an XDI instance under this XDI collection. * @return The XDI instance. */ public U setXdiInstanceUnordered(boolean attribute, boolean immutable, boolean relative, String literal) { XDIArc XDIarc = XdiAbstractInstanceUnordered.createXDIArc(attribute, immutable, relative, literal, null); ContextNode instanceContextNode = this.getContextNode().setContextNode(XDIarc); return XdiAbstractContext.fromContextNode(instanceContextNode, this.getU()); }
private void writeContextNodeXDIArc(BufferedWriter bufferedWriter, ContextNode contextNode, XDIArc contextNodeXDIArc) throws IOException { if (! XDIConstants.XDI_ADD_ROOT.equals(contextNodeXDIArc)) { contextNode = contextNode.setContextNode(contextNodeXDIArc); } String htmlColorString = null; if (this.isWriteHtml()) { if (XdiAbstractRoot.isValid(contextNode)) htmlColorString = HTML_COLOR_ROOT; if (XdiEntityCollection.isValid(contextNode) || XdiAbstractEntity.isValid(contextNode)) htmlColorString = HTML_COLOR_ENTITY; if (XdiAttributeCollection.isValid(contextNode) || XdiAbstractAttribute.isValid(contextNode)) htmlColorString = HTML_COLOR_ATTRIBUTE; } if (htmlColorString != null) bufferedWriter.write("<span style=\"background-color:" + htmlColorString + "\">"); bufferedWriter.write(contextNodeXDIArc.toString()); if (htmlColorString != null) bufferedWriter.write("</span>"); }
public static XdiEntityCollection getEntityIndex(Graph graph, XDIArc indexXDIArc, boolean create) { XDIArc xdiEntityCollectionXDIArc = XdiEntityCollection.createXDIArc(indexXDIArc); ContextNode contextNode = create ? graph.getRootContextNode().setContextNode(xdiEntityCollectionXDIArc) : graph.getRootContextNode().getContextNode(xdiEntityCollectionXDIArc); if (contextNode == null) return null; return XdiEntityCollection.fromContextNode(contextNode); }
@Override public Node setDeepNode(XDIAddress relativeNodeXDIAddress) { if (relativeNodeXDIAddress == null) return this; if (XDIConstants.XDI_ADD_ROOT.equals(relativeNodeXDIAddress)) return this; ContextNode contextNode = this; for (XDIArc contextNodeXDIArc : relativeNodeXDIAddress.getContextNodeXDIAddress().getXDIArcs()) { contextNode = contextNode.setContextNode(contextNodeXDIArc); } if (relativeNodeXDIAddress.isLiteralNodeXDIAddress()) { return contextNode.setLiteralNode(null); } else { return contextNode; } }
private void writeContextNodeXDIAddress(BufferedWriter bufferedWriter, XDIAddress contextNodeXDIAddress) throws IOException { if (this.isWriteHtml()) { ContextNode contextNode = MemoryGraphFactory.getInstance().openGraph().getRootContextNode(false); for (XDIArc contextNodeXDIArc : contextNodeXDIAddress.getXDIArcs()) { this.writeContextNodeXDIArc(bufferedWriter, contextNode, contextNodeXDIArc); if (! XDIConstants.XDI_ADD_ROOT.equals(contextNodeXDIArc)) { contextNode = contextNode.setContextNode(contextNodeXDIArc); } } } else { bufferedWriter.write(contextNodeXDIAddress.toString()); } }
public void testTimestampsOnContextNode() throws Exception { Graph graph = MemoryGraphFactory.getInstance().openGraph(); ContextNode contextNode = graph.getRootContextNode().setContextNode(XDIArc.create("=markus")); GregorianCalendar calendar = new GregorianCalendar(2010, 11, 22, 11, 22, 33); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); Date timestamp = calendar.getTime(); Timestamps.setTimestamp(XdiAbstractContext.fromContextNode(contextNode), timestamp); assertEquals(timestamp, Timestamps.getTimestamp(XdiAbstractContext.fromContextNode(contextNode))); graph.close(); } }
public void testNoExceptions() throws Exception { Graph graph17 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-17"); graph17.setStatement(XDIStatement.create("=markus<#email>/&/\"Markus Sabadello\"")); graph17.setStatement(XDIStatement.create("=markus/#friend/=neustar=les")); ContextNode root = graph17.getRootContextNode(); ContextNode markus = graph17.getDeepContextNode(XDIAddress.create("=markus")); ContextNode les = graph17.getDeepContextNode(XDIAddress.create("=neustar=les")); root.setContextNode(XDIArc.create("=markus")); markus.setDeepContextNode(XDIAddress.create("<#email>")).setLiteralNode("test"); markus.setRelation(XDIAddress.create("#friend"), les); graph17.close(); }
public void testIllegalarcs() throws Exception { Graph graph20 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-20"); ContextNode markus = graph20.setDeepContextNode(XDIAddress.create("=markus")); try { markus.setContextNode(XDIArc.create("")); fail(); } catch (Xdi2GraphException ex) { } try { markus.setRelation(XDIAddress.create(""), XDIAddress.create("=animesh")); fail(); } catch (Xdi2GraphException ex) { } try { markus.setRelation(XDIAddress.create("&"), XDIAddress.create("=animesh")); fail(); } catch (Xdi2GraphException ex) { } Equivalence.setReferenceContextNode(markus, XDIAddress.create("=!:uuid:1234")); // try { markus.setContextNode(XDIArc.create("<#email>")); fail(); } catch (Xdi2GraphException ex) { } // try { markus.setRelation(XDIAddress.create("#friend"), XDIAddress.create("=animesh")); fail(); } catch (Xdi2GraphException ex) { } // try { markus.setLiteralNode("hello"); fail(); } catch (Xdi2GraphException ex) { } Equivalence.getReferenceContextNode(markus).delete(); markus.setRelation(XDIAddress.create("#friend"), XDIAddress.create("=animesh")); // try { Equivalence.setReferenceContextNode(markus, XDIAddress.create("=!:uuid:1234")); fail(); } catch (Xdi2GraphException ex) { } graph20.close(); }