本文整理汇总了Java中xdi2.core.Graph.getRootContextNode方法的典型用法代码示例。如果您正苦于以下问题:Java Graph.getRootContextNode方法的具体用法?Java Graph.getRootContextNode怎么用?Java Graph.getRootContextNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xdi2.core.Graph
的用法示例。
在下文中一共展示了Graph.getRootContextNode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: geAllCollections
import xdi2.core.Graph; //导入方法依赖的package包/类
public ArrayList<PCAttributeCollection> geAllCollections() {
Graph g = this.getWholeGraph();
ContextNode root = g.getRootContextNode();
ReadOnlyIterator<Literal> allLiterals = root.getAllLiterals();
while (allLiterals.hasNext()) {
Literal lit = allLiterals.next();
String value = lit.getLiteralData().toString();
String name = lit.getContextNode().toString();
}
return null;
}
示例2: main
import xdi2.core.Graph; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// create a simple graph with context nodes, a relation, and a literal
Graph graph = MemoryGraphFactory.getInstance().openGraph();
ContextNode root = graph.getRootContextNode();
ContextNode markus = root.setContextNode(XDIArc.create("=markus"));
ContextNode animesh = root.setContextNode(XDIArc.create("=animesh"));
ContextNode name = markus.setContextNode(XDIArc.create("<#name>"));
Relation relation = markus.setRelation(XDIAddress.create("#friend"), animesh);
LiteralNode literalNode = name.setLiteralNode("Markus Sabadello");
// write some statements from our graph
System.out.println("Statement associated with a context node: " + markus.getStatement());
System.out.println("Statement associated with a relation: " + relation.getStatement());
System.out.println("Statement associated with a literal: " + literalNode.getStatement());
System.out.println();
// we can also add a whole new statement to the graph
graph.setStatement(XDIStatement.create("=alice/#friend/=bob"));
// write the whole graph in different serialization formats
System.out.println("Serialization in XDI/JSON: \n");
XDIWriterRegistry.forFormat("XDI/JSON", null).write(graph, System.out);
System.out.println();
System.out.println();
System.out.println("Serialization in XDI statements:\n");
XDIWriterRegistry.forFormat("XDI DISPLAY", null).write(graph, System.out);
// close the graph
graph.close();
}
示例3: linkContractExists
import xdi2.core.Graph; //导入方法依赖的package包/类
public boolean linkContractExists(String connectRequest) {
System.out.println("\nChecking if a link contract exists\n");
boolean result = false;
MemoryJSONGraphFactory graphFactory = new MemoryJSONGraphFactory();
String templateOwnerInumber = null;
try {
Graph g = graphFactory.parseGraph(connectRequest);
// get remote cloud number
XDIWriterRegistry.forFormat("XDI DISPLAY", null).write(g,
System.out);
ContextNode c = g.getRootContextNode();
ReadOnlyIterator<ContextNode> allCNodes = c.getAllContextNodes();
for (ContextNode ci : allCNodes) {
if (ci.containsContextNode(XDI3SubSegment.create("[$msg]"))) {
templateOwnerInumber = ci.toString();
System.out.println(templateOwnerInumber);
break;
}
}
if (templateOwnerInumber == null) {
System.out
.println("No cloudnumber for requestor/template owner");
return result;
}
// get the address of the link contract template
// $set{$do}
String lcTemplateAddress = null;
ReadOnlyIterator<Relation> allRelations = c.getAllRelations(); // g.getDeepRelations(XDI3Segment.create(templateOwnerInumber),XDI3Segment.create("$get"));
for (Relation r : allRelations) {
if (r.getArcXri().toString().equals("$set{$do}")) {
lcTemplateAddress = r.getTargetContextNodeXri().toString();
System.out.println(r.getTargetContextNodeXri());
}
}
if (lcTemplateAddress == null) {
System.out.println("No LC template address provided");
return result;
}
} catch (Exception io) {
io.printStackTrace();
return result;
}
String isPlusstmt = new String();
isPlusstmt += this.cloudNumber;
isPlusstmt += "$to";
isPlusstmt += templateOwnerInumber;
isPlusstmt += "$from";
isPlusstmt += templateOwnerInumber;
isPlusstmt += "+registration$do";
ArrayList<XDI3Segment> querySegments = new ArrayList<XDI3Segment>();
querySegments.add(XDI3Segment.create(isPlusstmt));
MessageResult responseFromRemoteCloud = this.sendQueries(querySegments,
null, false);
Graph responseGraph = responseFromRemoteCloud.getGraph();
ContextNode responseRootContext = responseGraph.getRootContextNode();
System.out.println("\n\nLink Contract exists check\n\n"
+ responseGraph.toString());
if (responseRootContext.getContextNodeCount() > 1) {
result = true;
}
return result;
}