Exemple #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());
  }
Exemple #2
0
  protected DataItem getDataItem(int[] iStartPos, int[] iShape) throws NexusException {
    DataItem dsData = readDataInfo();

    NexusNode nnNode = getCurrentPath().getCurrentNode();
    String sNodeClass = nnNode.getClassName();
    if (!sNodeClass.equals("NXtechnical_data")) {
      dsData.setStart(iStartPos);
      dsData.setSlabSize(iShape);

      int[] iDataInf = new int[] {dsData.getSize().length, dsData.getType()};

      // We want a iNbDim dimension array of data, so dimensions are the
      // iNbDim last ones of the opened DataItem
      int[] length = {1};

      for (int iDim : iShape) {
        length[0] *= iDim;
      }

      // Prepare an array data
      Object oOutput;
      Object oInput = defineArrayObject(iDataInf[1], length);

      // Set data into temporary array having a single raw shape
      openFile();
      getNexusFile().getslab(iStartPos, iShape, oInput);
      closeFile();

      if (m_bResultAsSingleRaw) {
        oOutput = oInput;
      } else {
        // Changing the array into matrix (having iDimSize dimensions'
        // sizes) instead of single row
        oOutput = defineArrayObject(iDataInf[1], iShape);
      }

      // Converting byte[] to string in case of NX_CHAR data
      if (iDataInf[1] == NexusFile.NX_CHAR) {
        oOutput = new String((byte[]) oOutput).toCharArray();
      }

      // Setting DataItem's data
      if (iDataInf[1] == NexusFile.NX_BOOLEAN) {
        oOutput = convertArray(new DataItem(oOutput));
      }

      dsData.setData(new SoftReference<Object>(oOutput));
    }
    dsData.isSingleRawArray(m_bResultAsSingleRaw);
    return dsData;
  }
Exemple #3
0
  /** getDescendantsDatas Read all DataItems that are descendants of the currently opened group */
  protected Stack<DataItem> getDescendantsDatas() throws NexusException {
    Stack<DataItem> sDatas = new Stack<DataItem>();

    // Get all direct descendants' datas
    sDatas.addAll(getChildrenDatas());

    // Get all direct descendants group
    ArrayList<NexusNode> nodes = listChildren();

    // Start recursion
    for (NexusNode node : nodes) {
      if (node.isGroup()) {
        openNode(node);
        sDatas.addAll(getDescendantsDatas());
        closeGroup();
      }
    }

    return sDatas;
  }
Exemple #4
0
  /**
   * getChildrenDatas Scan currently opened group, to get all direct descendants' DataItem and
   * instrument informations (such as NXtechnical_data). Then return a list of DataItem.
   *
   * @throws NexusException
   */
  @SuppressWarnings("unchecked")
  protected Stack<DataItem> getChildrenDatas() throws NexusException {
    // Defining variables
    NexusNode node;
    ArrayList<NexusNode> alNodeList;
    Stack<DataItem> alDataItem = new Stack<DataItem>();

    // Parse children
    alNodeList = (ArrayList<NexusNode>) listChildren().clone();
    for (int iIndex = 0; iIndex < alNodeList.size(); iIndex++) {
      node = alNodeList.get(iIndex);
      if (!node.isGroup()) {
        openData(node.getNodeName());
        alDataItem.push(getDataItem());
        closeData();
      }
    }
    alDataItem.trimToSize();
    return alDataItem;
  }
Exemple #5
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());
  }
Exemple #6
0
  protected DataItem getDataItem(int iRank) throws NexusException {
    DataItem dataItem;
    NexusNode nnNode = getCurrentPath().getCurrentNode();
    String sNodeName = nnNode.getNodeName();
    String sNodeClass = nnNode.getClassName();

    // If encountered a DataItem get its datas
    if (!nnNode.isGroup() && !sNodeClass.equals("NXtechnical_data")) {
      dataItem = readDataItem(iRank);
      dataItem.setNodeName(sNodeName);

      return dataItem;
    }
    // else if we encountered a NXtechnical_data group: we get its "data"
    // and "description"
    else if (!nnNode.isGroup() && sNodeClass.equals("NXtechnical_data")) {
      // Get the "data" node
      openData("data");
      dataItem = readDataItem(iRank);
      dataItem.setNodeName(sNodeName);
      closeData();
      // Try to get a description for the technical data
      try {
        // Set to "data" as description attribute the "description" node
        // beside
        openData("description");
        dataItem.setDesc(readDataItem(iRank).getData());
        closeData();
      } catch (NexusException ne) {
        closeData();
      }
      dataItem.setPath(getCurrentPath().clone());

      return dataItem;
    } else {
      return null;
    }
  }
Exemple #7
0
  /**
   * readDataInfo Return the DataItem fitting the opened DataItem, without main data. The DataItem
   * is initialized with dimsize, type... but the DataItem isn't read.
   */
  public DataItem readDataInfo() throws NexusException {
    NexusNode nnNode = getCurrentPath().getCurrentNode();
    if (!nnNode.isGroup() && nnNode.getClassName().equals("NXtechnical_data")) {
      return getDataItem();
    }

    // Get infos on DataItem (data type, rank, dimsize)
    int[] iNodeSize = new int[RANK_MAX]; // whole DataItem dimension's sizes
    int[] iDimSize; // data dimension's sizes
    int[] iDataInf = new int[2]; // iDataInf[0] = DataItem rank ;
    // iDataInf[1]= data type

    openFile();
    getNexusFile().getinfo(iNodeSize, iDataInf);

    // Initialize dimension's sizes
    iDimSize = new int[iDataInf[0]];
    System.arraycopy(iNodeSize, 0, iDimSize, 0, iDataInf[0]);

    // Check if DataItem is linked to an external DataItem
    DataItem dsData = new DataItem();
    dsData.setType(iDataInf[1]);
    dsData.setSize(iDimSize);
    dsData.setSlabSize(iDimSize);
    dsData.setStart(new int[iDimSize.length]);
    dsData.setNodeName(getCurrentPath().getDataItemName());
    dsData.setPath(getCurrentPath().clone());
    dsData.isSingleRawArray(m_bResultAsSingleRaw);

    if (dsData.getType() == NexusFile.NX_CHAR) {
      dsData.setData(readNodeValue(iDataInf, dsData.getSize(), iDimSize.length));
    }
    closeFile();

    // Initialize DataItem's attributes
    getDataItemAttribute(dsData);
    return dsData;
  }
Exemple #8
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();
  }