xdi2.core.Graph.setDeepContextNode()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(18.2k)|赞(0)|评价(0)|浏览(130)

本文整理了Java中xdi2.core.Graph.setDeepContextNode()方法的一些代码示例,展示了Graph.setDeepContextNode()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graph.setDeepContextNode()方法的具体详情如下:
包路径:xdi2.core.Graph
类名称:Graph
方法名:setDeepContextNode

Graph.setDeepContextNode介绍

暂无

代码示例

代码示例来源:origin: projectdanube/xdi2

/**
 * Creates a context node from its components.
 * @param contextNodeXDIAddress The address of the context node.
 * @return A context node.
 */
public static ContextNode contextNodeFromComponents(XDIAddress contextNodeXDIAddress) {
  Graph graph = MemoryGraphFactory.getInstance().openGraph();
  return graph.setDeepContextNode(contextNodeXDIAddress);
}

代码示例来源:origin: projectdanube/xdi2

/**
 * 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);
}

代码示例来源:origin: projectdanube/xdi2

/**
 * 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);
}

代码示例来源:origin: projectdanube/xdi2

/**
 * Creates a relation from its components.
 * @param contextNodeXDIAddress The address of the context node containing the relation.
 * @param XDIaddress The address of the relation.
 * @param targetXDIAddress The target context node address of the relation.
 * @return A relation.
 */
public static Relation relationFromComponents(XDIAddress contextNodeXDIAddress, XDIAddress XDIaddress, XDIAddress targetXDIAddress) {
  Graph graph = MemoryGraphFactory.getInstance().openGraph();
  return graph.setDeepContextNode(contextNodeXDIAddress).setRelation(XDIaddress, targetXDIAddress);
}

代码示例来源:origin: projectdanube/xdi2

/**
 * Creates a literal from its components.
 * @param contextNodeXDIAddress The address of the context node containing the literal.
 * @param literalData The literal data of the literal.
 * @return A literal.
 */
public static LiteralNode literalFromComponents(XDIAddress contextNodeXDIAddress, Object literalData) {
  Graph graph = MemoryGraphFactory.getInstance().openGraph();
  return graph.setDeepContextNode(contextNodeXDIAddress).setLiteralNode(literalData);
}

代码示例来源:origin: projectdanube/xdi2

/**
 * Factory method that finds or creates an XDI relationship link contract for a graph.
 * @return The XDI relationship link contract.
 */
public static RelationshipLinkContract findRelationshipLinkContract(Graph graph, XDIAddress authorizingAuthority, XDIAddress requestingAuthority, XDIAddress templateAuthorityAndId, XDIArc instanceXDIArc, boolean create) {
  XDIAddress relationshipLinkContractXDIAddress = createRelationshipLinkContractXDIAddress(authorizingAuthority, requestingAuthority, templateAuthorityAndId, instanceXDIArc);
  ContextNode relationshipLinkContractContextNode = create ? graph.setDeepContextNode(relationshipLinkContractXDIAddress) : graph.getDeepContextNode(relationshipLinkContractXDIAddress, true);
  if (relationshipLinkContractContextNode == null) return null;
  return new RelationshipLinkContract(XdiAbstractEntity.fromContextNode(relationshipLinkContractContextNode));
}

代码示例来源:origin: projectdanube/xdi2

/**
 * Copies a context node 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.
 * @return The copied context node in the target graph.
 */
public static ContextNode copyContextNode(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;
  ContextNode targetContextNode;
  XDIAddress contextNodeXDIAddress = contextNode.getXDIAddress();
  if (contextNode.isRootContextNode()) {
    targetContextNode = targetGraph.getRootContextNode(false);
    copyContextNodeContents(contextNode, targetContextNode, copyStrategy);
  } else {
    targetContextNode = targetGraph.setDeepContextNode(contextNodeXDIAddress);
    copyContextNodeContents(contextNode, targetContextNode, copyStrategy);
  }
  return targetContextNode;
}

代码示例来源:origin: projectdanube/xdi2

@Override
public void executeSetOnRelationStatement(XDIStatement relationStatement, SetOperation operation, Graph operationResultGraph, ExecutionContext executionContext) throws Xdi2MessagingException {
  XDIAddress contextNodeXDIAddress = relationStatement.getContextNodeXDIAddress();
  XDIAddress relationXDIaddress = relationStatement.getRelationXDIAddress();
  XDIAddress targetXDIAddress = relationStatement.getTargetXDIAddress();
  this.getGraph().setDeepContextNode(contextNodeXDIAddress).setRelation(relationXDIaddress, targetXDIAddress);
}

代码示例来源:origin: projectdanube/xdi2

@Override
public ContributorResult executeDoOnLiteralStatement(XDIAddress[] contributorAddresses, XDIAddress contributorsAddress, XDIStatement relativeTargetStatement, DoOperation operation, Graph operationResultGraph, ExecutionContext executionContext) throws Xdi2MessagingException {
  Object literalData = relativeTargetStatement.getLiteralData();
  // check parameters
  if (! (literalData instanceof String)) return ContributorResult.SKIP_MESSAGING_CONTAINER;
  String secretToken = (String) literalData;
  // generate local salt and digest secret token
  String localSaltAndDigestSecretToken;
  try {
    localSaltAndDigestSecretToken = SecretTokens.localSaltAndDigestSecretToken(secretToken, this.getGlobalSalt());
  } catch (Exception ex) {
    throw new Xdi2MessagingException("Problem while creating digest secret token: " + ex.getMessage(), ex, executionContext);
  }
  if (log.isDebugEnabled()) log.debug("Created digest secret token: " + localSaltAndDigestSecretToken);
  // add it to the graph
  ContextNode contextNode = this.getTargetGraph().setDeepContextNode(contributorsAddress);
  if (! XdiAbstractAttribute.isValid(contextNode)) throw new Xdi2MessagingException("Can only create a digest secret token on an attribute.", null, executionContext);
  XdiAttribute localSaltAndDigestSecretTokenXdiAttribute = XdiAbstractAttribute.fromContextNode(contextNode);
  localSaltAndDigestSecretTokenXdiAttribute.setLiteralString(localSaltAndDigestSecretToken);
  // done
  return ContributorResult.SKIP_MESSAGING_CONTAINER;
}

代码示例来源:origin: projectdanube/xdi2

/**
 * Returns an existing XDI message collection in this XDI message envelope, or creates a new one.
 * @param senderXDIAddress The sender.
 * @param create Whether to create an XDI message collection if it does not exist.
 * @return The existing or newly created XDI message collection.
 */
public MessageCollection getMessageCollection(XDIAddress senderXDIAddress, boolean create) {
  if (senderXDIAddress == null) senderXDIAddress = XDIMessagingConstants.XDI_ADD_ANONYMOUS;
  XDIAddress messageCollectionXDIAddress = XDIAddress.create(senderXDIAddress.toString() + XdiEntityCollection.createXDIArc(XDIMessagingConstants.XDI_ARC_MSG));
  ContextNode contextNode = create ? this.getGraph().setDeepContextNode(messageCollectionXDIAddress) : this.getGraph().getDeepContextNode(messageCollectionXDIAddress, true);
  if (contextNode == null) return null;
  XdiEntityCollection xdiEntityCollection = XdiEntityCollection.fromContextNode(contextNode);
  return new MessageCollection(this, xdiEntityCollection);
}

代码示例来源:origin: projectdanube/xdi2

public void setDID(DID did) {
  if (did.equals(this.getDID())) return;
  ContextNode newContextNode = this.getContextNode().getGraph().setDeepContextNode(did.getXDIAddress());
  CopyUtil.copyContextNodeContents(this.getContextNode(), newContextNode, null);
  this.getContextNode().delete();
  this.xdiEntity = XdiAbstractEntity.fromContextNode(newContextNode);
}

代码示例来源:origin: projectdanube/xdi2

public void testDeleteDeep() throws Exception {
  Graph graph12 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-12");
  assertEquals(graph12.getRootContextNode(), graph12.getDeepContextNode(XDIConstants.XDI_ADD_ROOT));
  assertEquals(graph12.getRootContextNode().getXDIAddress(), XDIConstants.XDI_ADD_ROOT);
  graph12.setDeepContextNode(XDIAddress.create("=markus")).setRelation(XDIAddress.create("#friend"), XDIAddress.create("=someone"));
  graph12.getDeepContextNode(XDIAddress.create("=markus")).delete();
  graph12.setDeepContextNode(XDIAddress.create("=markus"));
  assertNull(graph12.getDeepContextNode(XDIAddress.create("=markus")).getRelation(XDIAddress.create("#friend")));
  graph12.close();
}

代码示例来源:origin: projectdanube/xdi2

public void testLinkContracts() throws Exception {
  Graph graph = MemoryGraphFactory.getInstance().openGraph();
  ContextNode contextNode1 = graph.setDeepContextNode(XDIAddress.create("(=alice/$public)$contract"));
  ContextNode contextNode2 = graph.setDeepContextNode(XDIAddress.create("(=alice/=alice)$contract"));
  assertTrue(LinkContract.isValid(XdiAbstractEntity.fromContextNode(contextNode1)));
  assertTrue(LinkContract.isValid(XdiAbstractEntity.fromContextNode(contextNode2)));
  LinkContract linkContract1 = LinkContract.fromXdiEntity(XdiAbstractEntity.fromContextNode(contextNode1));
  LinkContract linkContract2 = LinkContract.fromXdiEntity(XdiAbstractEntity.fromContextNode(contextNode2));
  assertTrue(new IteratorContains<LinkContract> (LinkContracts.getAllLinkContracts(graph), linkContract1).contains());
  assertTrue(new IteratorContains<LinkContract> (LinkContracts.getAllLinkContracts(graph), linkContract2).contains());
  graph.close();
}

代码示例来源:origin: projectdanube/xdi2

public void testImplied() throws Exception {
  Graph graph21 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-21");
  ContextNode webmarkus = graph21.setDeepContextNode(XDIAddress.create("=web=markus"));
  ContextNode animesh = graph21.setDeepContextNode(XDIAddress.create("=animesh"));
  Relation friend = webmarkus.setRelation(XDIAddress.create("#friend"), animesh);
  ContextNode value = webmarkus.setContextNode(XDIArc.create("<#name>"));
  LiteralNode name = value.setLiteralNode("Markus Sabadello");
  ContextNode web = webmarkus.getContextNode();
  assertTrue(webmarkus.getStatement().isImplied());
  assertTrue(animesh.getStatement().isImplied());
  assertFalse(friend.getStatement().isImplied());
  assertTrue(value.getStatement().isImplied());
  assertFalse(name.getStatement().isImplied());
  assertTrue(web.getStatement().isImplied());
  graph21.close();
}

代码示例来源:origin: projectdanube/xdi2

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();
  }

代码示例来源:origin: projectdanube/xdi2

public void testCreate() throws Exception {
  Graph graph24 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-24");
  ContextNode root = graph24.getRootContextNode();
  root.setContextNode(XDIArc.create("+a"));
  assertNotNull(root.getContextNode(XDIArc.create("+a")));
  assertNotNull(root.getDeepContextNode(XDIAddress.create("+a")));
  assertNotNull(graph24.getDeepContextNode(XDIAddress.create("+a")));
  root.setContextNode(XDIArc.create("+a"));
  root.setDeepContextNode(XDIAddress.create("+a"));
  graph24.setDeepContextNode(XDIAddress.create("+a"));
  root.setDeepContextNode(XDIAddress.create("+a+b"));
  assertNotNull(root.getContextNode(XDIArc.create("+a")).getContextNode(XDIArc.create("+b")));
  assertNotNull(root.getDeepContextNode(XDIAddress.create("+a+b")));
  assertNotNull(graph24.getDeepContextNode(XDIAddress.create("+a+b")));
  root.setContextNode(XDIArc.create("+a"));
  root.setDeepContextNode(XDIAddress.create("+a"));
  root.setDeepContextNode(XDIAddress.create("+a+b"));
  graph24.setDeepContextNode(XDIAddress.create("+a"));
  graph24.setDeepContextNode(XDIAddress.create("+a+b"));
  graph24.close();
}

代码示例来源:origin: projectdanube/xdi2

public void testSet() throws Exception {
  Graph graph25 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-25");
  ContextNode root = graph25.getRootContextNode();
  root.setContextNode(XDIArc.create("+a"));
  assertNotNull(root.getContextNode(XDIArc.create("+a")));
  assertNotNull(root.getDeepContextNode(XDIAddress.create("+a")));
  assertNotNull(graph25.getDeepContextNode(XDIAddress.create("+a")));
  root.setContextNode(XDIArc.create("+a"));
  root.setDeepContextNode(XDIAddress.create("+a"));
  graph25.setDeepContextNode(XDIAddress.create("+a"));
  root.setDeepContextNode(XDIAddress.create("+a+b"));
  assertNotNull(root.getContextNode(XDIArc.create("+a")).getContextNode(XDIArc.create("+b")));
  assertNotNull(root.getDeepContextNode(XDIAddress.create("+a+b")));
  assertNotNull(graph25.getDeepContextNode(XDIAddress.create("+a+b")));
  root.setContextNode(XDIArc.create("+a"));
  root.setDeepContextNode(XDIAddress.create("+a"));
  root.setDeepContextNode(XDIAddress.create("+a+b"));
  graph25.setDeepContextNode(XDIAddress.create("+a"));
  graph25.setDeepContextNode(XDIAddress.create("+a+b"));
  graph25.close();
}

代码示例来源:origin: projectdanube/xdi2

public void testNestedRelationshipLinkContract() throws Exception {
  Graph graph = MemoryGraphFactory.getInstance().openGraph();
  ContextNode c1 = graph.setDeepContextNode(XDIAddress.create("(=bob[$msg]*!:uuid:1234/$connect$push)(=bob/=alice)$defer$push$contract"));
  RelationshipLinkContract l1 = (RelationshipLinkContract) LinkContract.fromXdiEntity(XdiAbstractEntity.fromContextNode(c1));
  assertNotNull(l1);
  assertEquals(l1.getAuthorizingAuthority(), XDIAddress.create("=bob"));
  assertEquals(l1.getRequestingAuthority(), XDIAddress.create("=alice"));
  assertEquals(l1.getTemplateAuthorityAndId(), XDIAddress.create("$defer$push"));
  ContextNode c2 = graph.setDeepContextNode(XDIAddress.create("(=bob[$msg]*!:uuid:1234/$connect$push)(=bob/=alice)$defer$push[$contract]*!:uuid:1234"));
  RelationshipLinkContract l2 = (RelationshipLinkContract) LinkContract.fromXdiEntity(XdiAbstractEntity.fromContextNode(c2));
  assertNotNull(l2);
  assertEquals(l2.getAuthorizingAuthority(), XDIAddress.create("=bob"));
  assertEquals(l2.getRequestingAuthority(), XDIAddress.create("=alice"));
  assertEquals(l2.getTemplateAuthorityAndId(), XDIAddress.create("$defer$push"));
  graph.close();
}

代码示例来源:origin: projectdanube/xdi2

public void testLinkContractTemplate() throws Exception {
  XDIAddress XDIaddress = XDIAddress.create("=markus#registration{$contract}");
  Graph graph = MemoryGraphFactory.getInstance().openGraph();
  ContextNode contextNode = graph.setDeepContextNode(XDIaddress);
  LinkContractTemplate l1 = LinkContractTemplate.findLinkContractTemplate(graph, XDIAddress.create("=markus#registration"), false);
  assertNotNull(l1);
  assertEquals(l1.getTemplateAuthorityAndId(), XDIAddress.create("=markus#registration"));
  LinkContractTemplate l2 = LinkContractTemplate.fromXdiEntitySingletonVariable(XdiEntitySingleton.Variable.fromContextNode(contextNode));
  assertNotNull(l2);
  assertEquals(l2.getTemplateAuthorityAndId(), XDIAddress.create("=markus#registration"));
  assertEquals(l1, l2);
  graph.close();
}

代码示例来源:origin: projectdanube/xdi2

public void testDoubleSet() throws Exception {
  Graph graph29 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-29");
  ContextNode c = graph29.setDeepContextNode(XDIAddress.create("=markus"));
  ContextNode a = graph29.setDeepContextNode(XDIAddress.create("=animesh"));
  c.setContextNode(XDIArc.create("<#email>"));
  c.setContextNode(XDIArc.create("<#email>"));
  c.setRelation(XDIAddress.create("#friend"), a);
  c.setRelation(XDIAddress.create("#friend"), a);
  c.setRelation(XDIAddress.create("#friend"), XDIAddress.create("=animesh"));
  c.setRelation(XDIAddress.create("#friend"), XDIAddress.create("=animesh"));
  assertEquals(c.getContextNodeCount(), 1);
  assertEquals(c.getAllContextNodeCount(), 1);
  assertEquals(c.getRelationCount(XDIAddress.create("#friend")), 1);
  assertEquals(c.getRelationCount(), 1);
  assertEquals(c.getAllRelationCount(), 1);
  c.delContextNode(XDIArc.create("<#email>"));
  c.delRelation(XDIAddress.create("#friend"), XDIAddress.create("=animesh"));
  assertEquals(c.getContextNodeCount(), 0);
  assertEquals(c.getAllContextNodeCount(), 0);
  assertEquals(c.getRelationCount(XDIAddress.create("#friend")), 0);
  assertEquals(c.getRelationCount(), 0);
  assertEquals(c.getAllRelationCount(), 0);
  graph29.close();
}

相关文章