Exemplo n.º 1
0
  /**
   * 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());
  }
Exemplo n.º 2
0
  /**
   * createDataItem Create all groups defined into the path, then create a DataItem matching type,
   * dimensions sizes of the given DataItem item. When the creation process is done it close if
   * asked all node to rturn bacxk to document's root.
   *
   * @param dsData DataItem item which created DataItem will match
   * @param paPath Path into which the given DataItem will be created
   * @param bKeepOpen boolean telling if the path should be keep opened after work
   * @return true if the node was existing yet , false if the process created a node. The purpose of
   *     this return is to tell whether data compatibility should be checked before writing it
   */
  protected boolean createDataItem(DataItem dsData, PathNexus pnPath, boolean bKeepOpen)
      throws NexusException {
    // Checking path contains a DataItem name
    String sDataItemName = pnPath.getDataItemName();
    if (sDataItemName == null)
      throw new NexusException("Path is invalid: no DataItem name specified to store data!");

    // Open path (or create it if needed)
    createPath(pnPath, true);

    // Open DataItem (or create it if needed)
    boolean bCheckData;
    try {
      openData(sDataItemName);
      bCheckData = true;
    } catch (NexusException ne) {
      makeData(sDataItemName, dsData);
      openData(sDataItemName);
      bCheckData = false;
    }

    if (!bKeepOpen) closeAll();

    return bCheckData;
  }
Exemplo n.º 3
0
  protected void createPath(PathNexus paPath, boolean bKeepOpen) throws NexusException {
    String sCurClass = ""; // Class name of the group we are processing
    String sCurName = ""; // Name of the group we are processing
    NexusNode nCurStep = null; // Currently opened node name in the NexusFile
    int iCurDepth = 0; // Current depth in the path
    int iPathDepth = paPath.getDepth();

    // Return to root node
    closeAll();

    // Create each group
    NexusNode nnNode;
    while (iCurDepth < iPathDepth) {
      // Determine group and class names
      nnNode = paPath.getNode(iCurDepth);
      sCurName = nnNode.getNodeName();
      sCurClass = nnNode.getClassName();

      // Create appropriate group and open it
      nCurStep = getCurrentRealPath().getCurrentNode();
      if (nnNode.isGroup() || "NXtechnical_data".equals(nnNode.getClassName())) {
        try {
          openGroup(sCurName, sCurClass);
        } catch (NexusException ne) {
          // Ensure we are still in the expected group
          if (nCurStep != null && !nCurStep.equals(getCurrentRealPath().getCurrentNode()))
            closeGroup();

          // Create the requested group
          getNexusFile().makegroup(sCurName, sCurClass);

          // Force the buffer node list to be updated
          pushNodeInBuffer(sCurName, sCurClass);

          // Open created group
          openGroup(sCurName, sCurClass);
        }
      }
      // Go one step forward in path
      iCurDepth++;
    }

    // Return to root node if necessary
    if (!bKeepOpen) closeAll();
  }
Exemplo n.º 4
0
  /**
   * 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());
  }
Exemplo n.º 5
0
  /**
   * checkLinkTarget open the target file and check if pointed data is a DataItem. Returns a string
   * array of two elements. The first is the attribute to distinguish if a DataItem or nxgroup is
   * pointed, the seconds is the full sibling path (completed by missing class or names).
   *
   * @param prTgtPath pointed node by the link
   * @param paSrcPath path of the starting node for the relative link
   * @return the corresponding absolute path if found, else return null
   */
  protected PathNexus checkRelativeLinkTarget(PathNexus prTgtPath, PathData paSrcPath) {
    PathNexus pnTarget = null;
    if (paSrcPath.isRelative()) return null;

    // Construct an absolute path using the source and the target
    if (!prTgtPath.isRelative()) pnTarget = prTgtPath;

    // Try to open the requested absolute path
    try {
      if (pnTarget == null) {
        PathRelative prRelTgtPath = new PathRelative(prTgtPath);
        pnTarget = prRelTgtPath.generateAbsolutePath((PathNexus) paSrcPath);
      }

      openPath(pnTarget);
      pnTarget = getCurrentPath().clone();
      closeAll();
      return pnTarget;
    } catch (NexusException ne) {
      return null;
    }
  }