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

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

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

Graph.getDeepContextNode介绍

暂无

代码示例

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

@Override
public ContextNode getContextNode(XDIAddress nodeXDIAddress) {
  Graph resolvedGraph = this.resolveGraph(nodeXDIAddress);
  XDIAddress resolvedcontextNodeXDIAddress = this.resolveXDIAddress(nodeXDIAddress);
  ContextNode resolvedContextNode = resolvedGraph.getDeepContextNode(resolvedcontextNodeXDIAddress, false);
  if (log.isTraceEnabled()) log.trace("getContextNode(" + nodeXDIAddress + ") --> " + resolvedcontextNodeXDIAddress + " --> " + resolvedContextNode);
  return resolvedContextNode;
}

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

@Override
public ContextNode getContextNode(XDIAddress XDIaddress) {
  if (XDIaddress.isLiteralNodeXDIAddress()) {
    return this.getGraph().getDeepContextNode(XDIaddress.getContextNodeXDIAddress());
  } else {
    return this.getGraph().getDeepContextNode(XDIaddress);
  }
}

代码示例来源: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

@Override
public void executeSetOnLiteralStatement(XDIStatement literalStatement, SetOperation operation, Graph operationResultGraph, ExecutionContext executionContext) throws Xdi2MessagingException {
  XDIAddress contextNodeXDIAddress = literalStatement.getContextNodeXDIAddress();
  Object literalData = literalStatement.getLiteralData();
  ContextNode contextNode = this.getGraph().getDeepContextNode(contextNodeXDIAddress);
  if (contextNode == null) return;
  contextNode.setLiteralNode(literalData);
}

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

@Override
public void executeGetOnContextNodeStatement(XDIStatement contextNodeStatement, GetOperation operation, Graph operationResultGraph, ExecutionContext executionContext) throws Xdi2MessagingException {
  XDIAddress targetXDIAddress = contextNodeStatement.getTargetXDIAddress();
  ContextNode contextNode = this.getGraph().getDeepContextNode(targetXDIAddress, false);
  if (contextNode == null) return;
  CopyUtil.copyStatement(contextNode.getStatement(), operationResultGraph, null);
}

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

@Override
  public void executeDelOnLiteralStatement(XDIStatement literalStatement, DelOperation operation, Graph operationResultGraph, ExecutionContext executionContext) throws Xdi2MessagingException {

    XDIAddress contextNodeXDIAddress = literalStatement.getContextNodeXDIAddress();
    Object literalData = literalStatement.getLiteralData();

    ContextNode contextNode = this.getGraph().getDeepContextNode(contextNodeXDIAddress);
    if (contextNode == null) return;

    LiteralNode literalNode = contextNode.getLiteralNode(literalData);
    if (literalNode == null) return;

    literalNode.delete();
  }
}

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

@Override
public void executeGetOnLiteralStatement(XDIStatement literalStatement, GetOperation operation, Graph operationResultGraph, ExecutionContext executionContext) throws Xdi2MessagingException {
  XDIAddress contextNodeXDIAddress = literalStatement.getContextNodeXDIAddress();
  Object literalData = literalStatement.getLiteralData();
  ContextNode contextNode = this.getGraph().getDeepContextNode(contextNodeXDIAddress);
  if (contextNode == null) return;
  LiteralNode literalNode = contextNode.getLiteralNode(literalData);
  if (literalNode == null) return;
  CopyUtil.copyStatement(literalNode.getStatement(), operationResultGraph, null);
}

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

@Test
  public void testDuplicateDatatypes() throws Exception {

    StringBuilder buffer = new StringBuilder();

    buffer.append("=markus<#age>/&/\"33\"\n");
    buffer.append("=markus<#age>/$is#/+$xsd$int\n");
    buffer.append("=markus<#age>/$is#/+$json$number\n");
    String xdiString = buffer.toString();

    try {

      Graph graph = (new MemoryGraphFactory()).parseGraph(xdiString);
      DataTypes.setDataType(graph.getDeepContextNode(XDIAddress.create("=markus<#age>")), XDIAddress.create("+$json$number"));

      fail();
      
      graph.close();
    } catch (Exception ex) { }
  }
}

代码示例来源: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 testDatatypes() throws Exception {
  StringBuilder buffer = new StringBuilder();
  buffer.append("=markus<#age>/&/\"33\"\n");
  buffer.append("=markus<#age>/$is#/$xsd$int\n");
  buffer.append("=markus<#age>/$is#/$json$number\n");
  String xdiString = buffer.toString();
  Graph graph = (new MemoryGraphFactory()).parseGraph(xdiString, "XDI DISPLAY", null);
  DataTypes.setDataType(graph.getDeepContextNode(XDIAddress.create("=markus<#age>")), XDIAddress.create("$mime$image$png"));
  List<XDIAddress> dataTypes = DataTypes.getDataTypes(graph.getDeepContextNode(XDIAddress.create("=markus<#age>")));
  assertNotNull(dataTypes);
  for (XDIAddress dataType : dataTypes) {
    if (dataType.toString().contains("json")) {
      assertEquals("number", DataTypes.jsonTypeFromDataTypeXDIAddress(dataType).toString());
    } else if (dataType.toString().contains("xsd")) {
      assertEquals("xsd:int", DataTypes.xsdTypeFromDataTypeXDIAddress(dataType).toString());
    } else if (dataType.toString().contains("mime")) {
      assertEquals("image/png", DataTypes.mimeTypeFromDataTypeXDIAddress(dataType).toString());
    }
  }
  
  graph.close();
}

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

@Override
public void executeDelOnRelationStatement(XDIStatement relationStatement, DelOperation operation, Graph operationResultGraph, ExecutionContext executionContext) throws Xdi2MessagingException {
  XDIAddress contextNodeXDIAddress = relationStatement.getContextNodeXDIAddress();
  XDIAddress relationXDIaddress = relationStatement.getRelationXDIAddress();
  XDIAddress targetXDIAddress = relationStatement.getTargetXDIAddress();
  ContextNode contextNode = this.getGraph().getDeepContextNode(contextNodeXDIAddress, false);
  if (contextNode == null) return;
  if (XDIConstants.XDI_ADD_COMMON_VARIABLE.equals(targetXDIAddress)) {
    if (XDIConstants.XDI_ADD_COMMON_VARIABLE.equals(relationXDIaddress)) {
      contextNode.delRelations();
    } else {
      contextNode.delRelations(relationXDIaddress);
    }
  } else {
    contextNode.delRelation(relationXDIaddress, targetXDIAddress);
  }
}

代码示例来源: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 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();
}

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

@Override
public void executeDelOnAddress(XDIAddress targetXDIAddress, DelOperation operation, Graph operationResultGraph, ExecutionContext executionContext) throws Xdi2MessagingException {
  if (XDIConstants.XDI_ADD_ROOT.equals(targetXDIAddress)) {
    this.getGraph().clear();
  } else if (targetXDIAddress.getNumXDIArcs() == 1) {
    this.getGraph().getRootContextNode(false).delContextNode(targetXDIAddress.getFirstXDIArc());
  } else {
    XDIAddress parentContextNodeXDIAddress = XDIAddressUtil.parentXDIAddress(targetXDIAddress, -1);
    XDIArc XDIarc = targetXDIAddress.getLastXDIArc();
    ContextNode parentContextNode = this.getGraph().getDeepContextNode(parentContextNodeXDIAddress, false);
    if (parentContextNode == null) return;
    if (XDIConstants.XDI_ARC_LITERAL.equals(XDIarc)) {
      parentContextNode.delLiteralNode();
    } else {
      parentContextNode.delContextNode(XDIarc);
    }
  }
}

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

public void testDeleteCyclicRelation() throws Exception {
  Graph graph31 = this.getGraphFactory().openGraph(this.getClass().getName() + "-graph-31");
  graph31.setStatement(XDIStatement.create("=a=b=c=d=e/+x/=a=b=c"));
  graph31.setStatement(XDIStatement.create("=m=n=o/+y/=a=b=c=d"));
  graph31.getDeepContextNode(XDIAddress.create("=a=b")).delete();
  assertEquals(graph31.getRootContextNode().getAllContextNodeCount(), 4);
  assertEquals(graph31.getRootContextNode().getAllRelationCount(), 0);
  assertEquals(graph31.getRootContextNode().getAllStatementCount(), 4);
  graph31.close();
}

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

public void testNormalizedSerialization() throws Exception {

    Graph graph = MemoryGraphFactory.getInstance().openGraph();
    graph.setStatement(XDIStatement.create("=markus<#email>/&/\"markus@projectdanube.org\""));
    graph.setStatement(XDIStatement.create("=markus/#friend/=animesh"));

    ContextNode contextNode = graph.getDeepContextNode(XDIAddress.create("=markus"));

    String normalizedSerialization = "{\"/\":[\"=animesh\",\"=markus\"],\"=markus/\":[\"<#email>\"],\"=markus/#friend\":[\"=animesh\"],\"=markus<#email>/&\":\"markus@projectdanube.org\"}";

    assertEquals(Normalization.serialize(contextNode, null), normalizedSerialization);

    graph.close();
  }
}

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

public void testSignAndValidateKeyPair() throws Exception {
  KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA");
  keyPairGen.initialize(1024);
  KeyPair keyPair = keyPairGen.generateKeyPair();
  RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
  RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
  Graph graph = MemoryGraphFactory.getInstance().openGraph();
  graph.setStatement(XDIStatement.create("=markus<#email>/&/\"markus@projectdanube.org\""));
  graph.setStatement(XDIStatement.create("=markus/#friend/=animesh"));
  ContextNode contextNode = graph.getDeepContextNode(XDIAddress.create("=markus"));
  RSASignature signature = new RSAStaticPrivateKeySignatureCreator(privateKey).createSignature(contextNode);
  signature = (RSASignature) Signatures.getSignatures(contextNode).next();
  assertEquals(signature.getDigestAlgorithm(), RSASignature.DIGEST_ALGORITHM_SHA);
  assertEquals(signature.getDigestVersion(), Integer.valueOf(256));
  assertEquals(signature.getKeyAlgorithm(), RSASignature.KEY_ALGORITHM_RSA);
  assertEquals(signature.getKeyLength(), Integer.valueOf(1024));
  assertEquals(signature.getJCEAlgorithm(), "SHA256withRSA");
  assertEquals(signature.getBaseContextNode(), contextNode);
  assertTrue(new RSAStaticPublicKeySignatureValidator(publicKey).validateSignature(signature));
  contextNode.setRelation(XDIAddress.create("#friend"), XDIAddress.create("=joseph"));
  assertFalse(new RSAStaticPublicKeySignatureValidator(publicKey).validateSignature(signature));
  graph.close();
}

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

public void testMessageEnvelope() throws Exception {
  Graph graph = this.openGraph(this.getClass().getName() + "-graph-me-1"); 
  GraphMessagingContainer graphMessagingContainer = new GraphMessagingContainer(); graphMessagingContainer.setGraph(graph);
  graphMessagingContainer.init();
  MessageEnvelope messageEnvelope1 = MessageEnvelope.fromOperationXDIAddressAndTargetXDIStatements(XDIMessagingConstants.XDI_ADD_SET, new SingleItemIterator<XDIStatement> (XDIStatement.create("=markus/#friend/=giovanni")));
  ExecutionContext executionContext1 = ExecutionContext.createExecutionContext();
  ExecutionResult executionResult1 = ExecutionResult.createExecutionResult(messageEnvelope1);
  graphMessagingContainer.execute(messageEnvelope1, executionContext1, executionResult1);
  MessageEnvelope messageEnvelope2 = MessageEnvelope.fromOperationXDIAddressAndTargetXDIAddress(XDIMessagingConstants.XDI_ADD_GET, XDIAddress.create("=markus"));
  ExecutionContext executionContext2 = ExecutionContext.createExecutionContext();
  ExecutionResult executionResult2 = ExecutionResult.createExecutionResult(messageEnvelope2);
  graphMessagingContainer.execute(messageEnvelope2, executionContext2, executionResult2);
  assertEquals(executionResult2.makeLightMessagingResponse().getResultGraph().getDeepContextNode(XDIAddress.create("=markus")).getRelation(XDIAddress.create("#friend")).getTargetXDIAddress(), XDIAddress.create("=giovanni"));
  graphMessagingContainer.shutdown();
}

代码示例来源: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();
}

相关文章