/** * copyAttr Copy the named attribute of the current source node into the current node * * @param sAttrName name of the attribute to be copied * @param nfrSource handler on the opened source file */ protected void copyAttr(String sAttrName, NexusFileReader nfrSource) throws NexusException { PathNexus pnSrcPath = nfrSource.getCurrentRealPath().clone(); PathNexus pnTgtPath = getCurrentRealPath().clone(); writeAttr(sAttrName, nfrSource.readAttr(sAttrName, pnSrcPath), getCurrentRealPath()); openPath(pnTgtPath); nfrSource.openPath(pnSrcPath); }
/** * copyAllAttr Copy all attributes of the current node from the source file into into the current * node. * * @param nfrSource handler on the opened source file */ protected void copyAllAttr(NexusFileReader nfrSource) throws NexusException { String sAttrName; Hashtable<String, AttributeEntry> listAttr = nfrSource.listAttribute(); for (Iterator<String> iter = listAttr.keySet().iterator(); iter.hasNext(); ) { sAttrName = (String) iter.next(); copyAttr(sAttrName, nfrSource); } }
/** * 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()); }
/** * defineArrayObject Returns an array of the corresponding type and dimension sizes * * @param iType integer corresponding to a Nexus data type * @param iDimSize array of sizes for each dimension * @throws NexusException */ protected static Object defineArrayObject(int iType, int[] iDimSize) throws NexusException { Object oArray; Class<?> cObject = NexusFileReader.defineTypeFromNexus(iType); oArray = java.lang.reflect.Array.newInstance(cObject, iDimSize); return oArray; }