⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nodeimpl.java

📁 用Java写的面相对象的数据库管理系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     * copying. This method is called by {@link #cloneNode} and the default     * {@link java.lang.Object#clone} method.     * <P>     * Contents cloning duplicates the node's name and value, and its children.     * It does not duplicate it's context, that is, the node's parent or sibling.     * Initially a clone node has no parents or siblings. However, the node does     * belong to the same document, since all nodes must belong to some document.     * The cloned node is never read-only.     *     * @param into A node into which to duplicate this one     * @param deep True if deep cloning is required     */    public synchronized void cloneInto( NodeProxy into, boolean deep ) {        NodeProxy child;                // falko: this expression cannot be true in ozone so I commented this        // out        // Make sure no function messed up with the class types.//        if (this.getClass() != into.getClass()) {//            throw new IllegalArgumentException( "Argument 'into' not same type as this node." );//        }         // Duplicate node name and value.        into.setNodeName( _nodeName );        String nodeValue = getNodeValue();        if (nodeValue != null) {            into.setNodeValue( nodeValue );        }        into.setOwnerDocument( _ownerDocument );        if (deep) {            child = (NodeProxy)getFirstChild();            while (child != null) {                into.appendChild( (Node)child.cloneNode( true ) );                child = (NodeProxy)child.getNextSibling();            }         }     }             public synchronized void setOwnerDocument( Document owner ) {        Node node;                if (owner == null) {            _ownerDocument = null;        } else {            if (!(owner instanceof DocumentProxy)) {                throw new IllegalArgumentException( "Argument 'owner' not of compatible DOM class." );            }             _ownerDocument = (DocumentProxy)owner;        }         node = getFirstChild();        while (node != null) {            ((NodeProxy)node).setOwnerDocument( owner );            node = node.getNextSibling();        }     }             /**     * Renders this node read only, preventing it's contents from being modified.     * Attempts to modify the node's contents will throw an exception. The node's     * children are also made read-only.     */    public synchronized final void setReadOnly() {        NodeProxy child;                _readOnly = true;        // Make all children read-only as well: this allows us to lock a branch        // but, for example, move it to a different tree.        child = (NodeProxy)getFirstChild();        while (child != null) {            child.setReadOnly();            child = (NodeProxy)child.getNextSibling();        }     }             /**     * Returns true if node is read-only and cannot be modified, or if node     * belongs to a read-only document.     *     * @return True if node is read-only and cannot be modified     * @see #setReadOnly     */    public final boolean isReadOnly() {        return _readOnly;    }             /**     * Returns true if this node supports children. Other methods query this to     * determine whether to properly support childern, return null or throw an     * exception in response. The default method returns false.     *     * @return True if childern supported by this node type     */    boolean supportsChildern() {        return false;    }             /**     * Returns the <TT>index</TT>-th child of this node. This method is used     * exclusively by {@link NodeListImpl}.     *     * @param index Index of child to retrieve     * @return The child node or null     * @see NodeListImpl#item(int)     */    public synchronized final Node getChild( int index ) {        NodeProxy node;                if (index < 0 || index > _childsCount) {            return null;        }         node = (NodeProxy)getFirstChild();        while (node != null && index > 0) {            node = (NodeProxy)node.getNextSibling();            --index;        }         return node;    }             /**     * Returns the number of children in this node.  This method is used     * exclusively by {@link NodeListImpl}.     *     * @return Number of childern in this node     * @see NodeListImpl#getLength     */    public final int getChildCount() {        return _childsCount;    }             /**     * Hidden constructor creates a new node. Only one constructor is supported,     * although cloning is also supported. Owner document must be supplied except     * for {@link DocumentImpl} in which case the document itself becomes its     * owner. Name must be supplied, either dynamic or static (e.g. "#document#").     * <P>     * If <TT>checkName</TT> is true, the supplied named is assumed to be a valid     * XML name token, one that can contain any Unicode letter and digit, must     * start with a letter, and may also contain hyphen, underscore, digit or colon.     *     * @param owner Document owner of this node, or null     * @param name Name of node     * @param value Initial value of node or null     * @param checkName True if name is an XML name token     * @throws org.w3c.dom.DOMException <TT>INVALID_CHARACTER_ERR</TT>     *  Node name cannot contain whitespaces or non-printable characters     */    protected NodeImpl( DocumentImpl owner, String name, String value, boolean checkName ) throws DOMException{        init( owner, name, value, checkName );    }            protected NodeImpl() {    }            public final void init( DocumentProxy owner, String name, String value, boolean checkName ) throws DOMException {        char ch;        int i;                if (name == null) {            throw new NullPointerException( "Argument 'name' is null." );        }                 _nodeName = name;        _ownerDocument = owner;        // Check the node name one character at a time to assure that no        // illegal characters are used. Node name must conform to Name token        // as defined in XML spec, including use of all Unicode letters and        // digits.        if (checkName && name.length() > 0) {            ch = name.charAt( 0 );            if (!Character.isLetter( ch ) && ch != '_' && ch != ':') {                throw new DOMExceptionImpl( DOMException.INVALID_CHARACTER_ERR );            }             for (i = 1; i < name.length(); ++i) {                ch = name.charAt( 1 );                if (!Character.isLetterOrDigit( ch ) && ch != '_' && ch != ':' && ch != '-' && ch != '.') {                    throw new DOMExceptionImpl( DOMException.INVALID_CHARACTER_ERR );                }             }         }         if (value != null) {            setNodeValue( value );        }     }         /**     * Element declaration node. Not part of the DOM, identifies an element     * declaration node appearing in the DTD.     */    public final static short ELEMENT_DECL_NODE = 13;            /**     * Attributes list declaration node. Not part of the DOM, identifies an     * attributes list declaration node appearing in the DTD..     */    public final static short ATTLIST_DECL_NODE = 14;            /**     * Parameter entity declaration node. Not part of the DOM, identifies an     * internal or external parameter entity declaration node appearing in the     * DTD (see {@link org.openxml.dom.ParamEntity}).     */    public final static short PARAM_ENTITY_NODE = 15;            /**     * This node ia part of a double-linked list that belongs to its parent.     * This reference identifies the next child in the list. Class access     * required by derived classes.     */    NodeProxy _nextNode;        /**     * This node ia part of a double-linked list that belongs to its parent.     * This reference identifies the previous child in the list. Class access     * required by derived classes.     */    NodeProxy _prevNode;        /**     * The parent of this node or null if the node has no parent. Class access     * required by derived classes.     */    NodeProxy _parent;        /**     * The document owner of this node, or the document itself. If the node belongs     * to any document, this will point to that document. For a document this will     * point at the document itself ({@link #getOwnerDocument} will return null,     * though). Class access required by derived classes.     */    DocumentProxy _ownerDocument;        /**     * The name of this node. All nodes have names, some are dynamic (e.g. the     * tag name of an element), others are static (e.g. "#document").     */    private String _nodeName;        /**     * The value of this node. Not all nodes support values and this might be     * null for some nodes.     */    private String _nodeValue;        /**     * The children of this node are arranged in a doubly linked lists.     * This reference identifies the first child in the list.     */    private NodeProxy _firstChild;        /**     * The children of this node are arranged in a doubly linked lists.     * This reference identifies the last child in the list.     */    private NodeProxy _lastChild;        /**     * Counts how many children nodes belong to this parent. Used to speed up     * some checks.     */    private int _childsCount;        /**     * True if this node is read-only and its contents cannot be modified.     */    private boolean _readOnly;        /**     * Holdes a list of iterators that are observing this node of its     * childern.     */    private NodeIteratorListener[] _iterators;            /**     */    public void writeExternal( ObjectOutput out ) throws IOException {        out.writeObject( _nextNode );        out.writeObject( _prevNode );        out.writeObject( _parent );        out.writeObject( _ownerDocument );                //out.writeObject (_nodeName);        if (_nodeName != null) {            out.writeByte( 1 );            out.writeUTF( _nodeName );        } else {            out.writeByte( -1 );        }                 // out.writeObject (_nodeValue);        if (_nodeValue != null) {            out.writeByte( 1 );            out.writeUTF( _nodeValue );        } else {            out.writeByte( -1 );        }                 out.writeObject( _firstChild );        out.writeObject( _lastChild );        out.writeInt( _childsCount );        out.writeBoolean( _readOnly );                if (_iterators != null) {            int len = _iterators.length;            out.writeInt( len );            for (int i = 0; i < len; i++) {                out.writeObject( _iterators[i] );            }         } else {            out.writeInt( -1 );        }     }             /**     */    public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException {        _nextNode = (NodeProxy)in.readObject();        _prevNode = (NodeProxy)in.readObject();        _parent = (NodeProxy)in.readObject();        _ownerDocument = (DocumentProxy)in.readObject();                int n = in.readByte();        if (n > 0) {            _nodeName = in.readUTF();        } else {            _nodeName = null;        }                 //_nodeValue = (String)in.readObject();        n = in.readByte();        if (n > 0) {            _nodeValue = in.readUTF();        } else {            _nodeValue = null;        }                 _firstChild = (NodeProxy)in.readObject();        _lastChild = (NodeProxy)in.readObject();        _childsCount = in.readInt();        _readOnly = in.readBoolean();                int len = in.readInt();        if (len > -1) {            _iterators = new NodeIteratorListener[len];            for (int i = 0; i < len; i++) {                _iterators[i] = (NodeIteratorListener)in.readObject();            }         } else {            _iterators = null;        }     } }

⌨️ 快捷键说明

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