コード例 #1
0
ファイル: NexusFileWriter.java プロジェクト: nhauser/cdma
  /**
   * writeLink Write both data link or group link depending on the given path.
   *
   * @param pnSrcPath path of node targeted by the link
   * @param prRelPath path of node wearing the link
   * @throws NexusException
   */
  protected void writeLink(PathNexus pnSrcPath, PathNexus prRelPath) throws NexusException {
    PathData pdDestNode;

    // Check the source node is well designed
    if (pnSrcPath.isRelative())
      throw new NexusException("Path is invalid: the targeted path must be absolute!");

    // Ensure the wearing node is a DataItem
    if (prRelPath.getDataItemName() == null) {
      PathGroup pgDest = new PathGroup(prRelPath.clone());
      pdDestNode = new PathData(pgDest, generateDataName((PathGroup) pgDest, DataItem_LINK));
    } else pdDestNode = (PathData) prRelPath;

    // Check the link is valid
    // PathNexus pnTgtPath = checkRelativeLinkTarget(prRelPath, pdDestNode);

    // Open path to get the corresponding NXlink
    openPath(pnSrcPath);
    NXlink nlLink = getNXlink();

    // Create the source path if needed and open it
    createPath(pdDestNode, true);

    // Write the link
    getNexusFile().makenamedlink(pdDestNode.getDataItemName(), nlLink);

    // Update node list buffer
    NexusNode nnNode = pdDestNode.getCurrentNode();
    pushNodeInBuffer(nnNode.getNodeName(), nnNode.getClassName());
  }
コード例 #2
0
ファイル: NexusFileWriter.java プロジェクト: nhauser/cdma
  /**
   * CopyNode make a full copy of the current source node (itself and its descendants) into the
   * currently opened destination path. The copy cares of all nodes' attributes.
   *
   * @param nfrSource handler on the opened source file
   */
  protected void copyNode(NexusFileReader nfrSource) throws NexusException {
    // Keep in buffer current path (used for recursion process)
    PathNexus pnSrcPath = nfrSource.getCurrentRealPath().clone();
    PathNexus pnTgtPath = getCurrentRealPath().clone();
    NexusNode nnCurNode = pnSrcPath.getCurrentNode();

    if (getCurrentRealPath().getCurrentNode() != null
        && !getCurrentRealPath().getCurrentNode().isRealGroup())
      throw new NexusException(
          "Invalid destination path: only a group can contain nodes!\n" + getCurrentRealPath());

    // Check the kind of the node
    if (nnCurNode == null
        || nnCurNode.isGroup()
        || "NXtechnical_data".equals(nnCurNode.getClassName())) {
      // Copy the current group
      PathNexus pnPath = pnTgtPath.clone();
      if (nnCurNode != null) pnPath.pushNode(nnCurNode);
      createPath(pnPath, true);
      copyAllAttr(nfrSource);

      // Copy all its descendants
      ArrayList<NexusNode> nodes = nfrSource.listChildren();
      for (NexusNode node : nodes) {
        nfrSource.openNode(node);
        copyNode(nfrSource);
      }
    } else {
      // Copy the current DataItem
      PathData pdDstPath = new PathData(pnTgtPath.getNodes(), nnCurNode.getNodeName());
      DataItem dsData = nfrSource.getDataItem();
      writeData(dsData, pdDstPath);
    }

    // Return back to the original position in both source and destination files
    closeAll();
    openPath(pnTgtPath);
    nfrSource.closeAll();
    nfrSource.openPath(pnSrcPath.getParentPath());
  }