dtmdocumentimpl.java

来自「Mobile 应用程序使用 Java Micro Edition (Java M」· Java 代码 · 共 1,662 行 · 第 1/5 页

JAVA
1,662
字号
                        // purpose of the while loop -- does this                        // logic make any sense?                        return (m_docHandle | nodes.specialFind(axisContextHandle, nodeHandle));                }                return NULL;        }        /**         * Given a node handle, find its parent node.         *         * @param nodeHandle the id of the node.         * @return int Node-number of parent,         * or DTM.NULL to indicate none exists.         */        public int getParent(int nodeHandle) {                // Should check to see within range?                // Document Root should not have to be handled differently                return (m_docHandle | nodes.readEntry(nodeHandle, 1));        }        /**         * Returns the root element of the document.         * @return nodeHandle to the Document Root.         */        public int getDocumentRoot() {                return (m_docHandle | m_docElement);        }        /**         * Given a node handle, find the owning document node.         *         * @return int Node handle of document, which should always be valid.         */        public int getDocument() {                return m_docHandle;        }        /**         * Given a node handle, find the owning document node.  This has the exact         * same semantics as the DOM Document method of the same name, in that if         * the nodeHandle is a document node, it will return NULL.         *         * <p>%REVIEW% Since this is DOM-specific, it may belong at the DOM         * binding layer. Included here as a convenience function and to         * aid porting of DOM code to DTM.</p>         *         * @param nodeHandle the id of the node.         * @return int Node handle of owning document, or NULL if the nodeHandle is         *             a document.         */        public int getOwnerDocument(int nodeHandle) {                // Assumption that Document Node is always in 0 slot                if ((nodeHandle & NODEHANDLE_MASK) == 0)                        return NULL;                return (nodeHandle & DOCHANDLE_MASK);        }        /**         * Given a node handle, find the owning document node.  This has the DTM         * semantics; a Document node is its own owner.         *         * <p>%REVIEW% Since this is DOM-specific, it may belong at the DOM         * binding layer. Included here as a convenience function and to         * aid porting of DOM code to DTM.</p>         *         * @param nodeHandle the id of the node.         * @return int Node handle of owning document, or NULL if the nodeHandle is         *             a document.         */        public int getDocumentRoot(int nodeHandle) {                // Assumption that Document Node is always in 0 slot                if ((nodeHandle & NODEHANDLE_MASK) == 0)                        return NULL;                return (nodeHandle & DOCHANDLE_MASK);        }        /**         * Get the string-value of a node as a String object         * (see http://www.w3.org/TR/xpath#data-model         * for the definition of a node's string-value).         *         * @param nodeHandle The node ID.         *         * @return A string object that represents the string-value of the given node.         */        public XMLString getStringValue(int nodeHandle) {        // ###zaj - researching        nodes.readSlot(nodeHandle, gotslot);        int nodetype=gotslot[0] & 0xFF;        String value=null;        switch (nodetype) {        case TEXT_NODE:        case COMMENT_NODE:        case CDATA_SECTION_NODE:                value= m_char.getString(gotslot[2], gotslot[3]);                break;        case PROCESSING_INSTRUCTION_NODE:        case ATTRIBUTE_NODE:        case ELEMENT_NODE:        case ENTITY_REFERENCE_NODE:        default:                break;        }        return m_xsf.newstr( value );        }        /**         * Get number of character array chunks in         * the string-value of a node.         * (see http://www.w3.org/TR/xpath#data-model         * for the definition of a node's string-value).         * Note that a single text node may have multiple text chunks.         *         * EXPLANATION: This method is an artifact of the fact that the         * underlying m_chars object may not store characters in a         * single contiguous array -- for example,the current         * FastStringBuffer may split a single node's text across         * multiple allocation units.  This call tells us how many         * separate accesses will be required to retrieve the entire         * content. PLEASE NOTE that this may not be the same as the         * number of SAX characters() events that caused the text node         * to be built in the first place, since m_chars buffering may         * be on different boundaries than the parser's buffers.         *         * @param nodeHandle The node ID.         *         * @return number of character array chunks in         *         the string-value of a node.         * */        //###zaj - tbd        public int getStringValueChunkCount(int nodeHandle)        {                //###zaj    return value                return 0;        }        /**         * Get a character array chunk in the string-value of a node.         * (see http://www.w3.org/TR/xpath#data-model         * for the definition of a node's string-value).         * Note that a single text node may have multiple text chunks.         *         * EXPLANATION: This method is an artifact of the fact that         * the underlying m_chars object may not store characters in a         * single contiguous array -- for example,the current         * FastStringBuffer may split a single node's text across         * multiple allocation units.  This call retrieves a single         * contiguous portion of the text -- as much as m-chars was         * able to store in a single allocation unit.  PLEASE NOTE         * that this may not be the same granularityas the SAX         * characters() events that caused the text node to be built         * in the first place, since m_chars buffering may be on         * different boundaries than the parser's buffers.         *         * @param nodeHandle The node ID.         * @param chunkIndex Which chunk to get.         * @param startAndLen An array of 2 where the start position and length of         *                    the chunk will be returned.         *         * @return The character array reference where the chunk occurs.  */        //###zaj - tbd        public char[] getStringValueChunk(int nodeHandle, int chunkIndex,                                                                                                                                                int[] startAndLen) {return new char[0];}        /**         * Given a node handle, return an ID that represents the node's expanded name.         *         * @param nodeHandle The handle to the node in question.         *         * @return the expanded-name id of the node.         */        public int getExpandedTypeID(int nodeHandle) {           nodes.readSlot(nodeHandle, gotslot);           String qName = m_localNames.indexToString(gotslot[3]);           // Remove prefix from qName           // %TBD% jjk This is assuming the elementName is the qName.           int colonpos = qName.indexOf(":");           String localName = qName.substring(colonpos+1);           // Get NS           String namespace = m_nsNames.indexToString(gotslot[0] << 16);           // Create expanded name           String expandedName = namespace + ":" + localName;           int expandedNameID = m_nsNames.stringToIndex(expandedName);        return expandedNameID;        }        /**         * Given an expanded name, return an ID.  If the expanded-name does not         * exist in the internal tables, the entry will be created, and the ID will         * be returned.  Any additional nodes that are created that have this         * expanded name will use this ID.         *         * @return the expanded-name id of the node.         */        public int getExpandedTypeID(String namespace, String localName, int type) {           // Create expanded name          // %TBD% jjk Expanded name is bitfield-encoded as          // typeID[6]nsuriID[10]localID[16]. Switch to that form, and to          // accessing the ns/local via their tables rather than confusing          // nsnames and expandednames.           String expandedName = namespace + ":" + localName;           int expandedNameID = m_nsNames.stringToIndex(expandedName);           return expandedNameID;        }        /**         * Given an expanded-name ID, return the local name part.         *         * @param ExpandedNameID an ID that represents an expanded-name.         * @return String Local name of this node.         */        public String getLocalNameFromExpandedNameID(int ExpandedNameID) {           // Get expanded name           String expandedName = m_localNames.indexToString(ExpandedNameID);           // Remove prefix from expanded name           int colonpos = expandedName.indexOf(":");           String localName = expandedName.substring(colonpos+1);           return localName;        }        /**         * Given an expanded-name ID, return the namespace URI part.         *         * @param ExpandedNameID an ID that represents an expanded-name.         * @return String URI value of this node's namespace, or null if no         * namespace was resolved.        */        public String getNamespaceFromExpandedNameID(int ExpandedNameID) {           String expandedName = m_localNames.indexToString(ExpandedNameID);           // Remove local name from expanded name           int colonpos = expandedName.indexOf(":");           String nsName = expandedName.substring(0, colonpos);        return nsName;        }        /**         * fixednames        */        private static final String[] fixednames=        {                null,null,							// nothing, Element                null,"#text",						// Attr, Text                "#cdata_section",null,	// CDATA, EntityReference                null,null,							// Entity, PI                "#comment","#document",	// Comment, Document                null,"#document-fragment", // Doctype, DocumentFragment                null};									// Notation        /**         * Given a node handle, return its DOM-style node name. This will         * include names such as #text or #document.         *         * @param nodeHandle the id of the node.         * @return String Name of this node, which may be an empty string.         * %REVIEW% Document when empty string is possible...         */        public String getNodeName(int nodeHandle) {                nodes.readSlot(nodeHandle, gotslot);                short type = (short) (gotslot[0] & 0xFFFF);                String name = fixednames[type];                if (null == name) {                  int i=gotslot[3];                  /**/System.out.println("got i="+i+" "+(i>>16)+"/"+(i&0xffff));                  name=m_localNames.indexToString(i & 0xFFFF);                  String prefix=m_prefixNames.indexToString(i >>16);                  if(prefix!=null && prefix.length()>0)                    name=prefix+":"+name;                }                return name;        }        /**         * Given a node handle, return the XPath node name.  This should be         * the name as described by the XPath data model, NOT the DOM-style         * name.         *         * @param nodeHandle the id of the node.         * @return String Name of this node.         */        public String getNodeNameX(int nodeHandle) {return null;}        /**         * Given a node handle, return its DOM-style localname.         * (As defined in Namespaces, this is the portion of the name after any         * colon character)         *         * %REVIEW% What's the local name of something other than Element/Attr?         * Should this be DOM-style (undefined unless namespaced), or other?         *         * @param nodeHandle the id of the node.         * @return String Local name of this node.         */        public String getLocalName(int nodeHandle) {                nodes.readSlot(nodeHandle, gotslot);                short type = (short) (gotslot[0] & 0xFFFF);                String name = "";                if ((type==ELEMENT_NODE) || (type==ATTRIBUTE_NODE)) {                  int i=gotslot[3];                  name=m_localNames.indexToString(i & 0xFFFF);                  if(name==null) name="";                }                return name;        }        /**         * Given a namespace handle, return the prefix that the namespace decl is         * mapping.         * Given a node handle, return the prefix used to map to the namespace.         *         * <p> %REVIEW% Are you sure you want "" for no prefix?  </p>         *         * %REVIEW%  Should this be DOM-style (undefined unless namespaced),         * or other?         *         * @param nodeHandle the id of the node.         * @return String prefix of this node's name, or "" if no

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?