📄 elementimpl.java
字号:
if (attr != null) { removeAttr( attr ); return attr; } else { return null; } } public synchronized final Node item( int index ) { AttrProxy attr; attr = _firstAttr; while (attr != null && index > 0) { // Note: getNextSibling() will return null. attr = (AttrProxy)attr.getNextSibling(); --index; } return attr; } public int getLength() { return _attrCount; } public synchronized boolean equals( Object other ) { ElementProxy otherX; AttrProxy attr; boolean equal; // If both objects are the same, return true. If one is null, or they // do not belong to the same class, return false. Equality is not // tested across different DOMs or different ClassLoaders. if (this == other) { return true; } if (other == null || !(other instanceof Element)) { return false; } if (!super.equals( other )) { return false; } synchronized (other) { otherX = (ElementProxy)other; equal = _attrCount == otherX.getLength(); if (equal) { // Test for attributes first, this is the faster test and // can tell elements apart quite easily. Since attributes might // be out of sequence, retrieve attributes by name not by sequence. // This test is recursive to some degree. attr = _firstAttr; while (equal && attr != null) { equal = otherX.getNamedAttr( attr.getNodeName() ) != null && otherX.getNamedAttr( attr.getNodeName() ).equals( attr ); // Note: getNextSibling() will return null. attr = (AttrProxy)attr.getNextSibling(); } } } return equal; } public final Object clone() { ElementProxy clone = null; try { clone = (ElementProxy)_ownerDocument.createElement( getNodeName() ); cloneInto( clone, true ); } catch (Exception except) { throw new DOMExceptionImpl( DOMExceptionImpl.PDOM_ERR, except.getMessage() ); } return clone; } public final Node cloneNode( boolean deep ) { ElementProxy clone = null; try { clone = (ElementProxy)_ownerDocument.createElement( getNodeName() ); cloneInto( clone, deep ); } catch (Exception except) { throw new DOMExceptionImpl( DOMExceptionImpl.PDOM_ERR, except.getMessage() ); } return clone; } public String toString() { String name; name = getTagName(); if (name.length() > 32) { name = name.substring( 0, 32 ) + ".."; } return "Element node: [" + name + "] (" + getChildCount() + " nodes)"; } public synchronized void cloneInto( NodeProxy into, boolean deep ) { AttrProxy attr; ElementProxy intoX; super.cloneInto( into, deep ); intoX = (ElementProxy)into; // Duplicate all attributes . Note that attributes are duplicated with deep // cloning, since an attribute might contain Text and EntityReference nodes. intoX.setFirstAttr( null ); intoX.setLastAttr( null ); intoX.setAttrCount( 0 ); attr = _firstAttr; while (attr != null) { intoX.appendAttr( (AttrProxy)attr.cloneNode( true ) ); // Note: getNextSibling() will return null. attr = (AttrProxy)attr.getNextSibling(); } } protected boolean supportsChildern() { return true; } /** * Returns the named attribute or null if attribute not found. * * @param name The name of the attribute to return * @return The named attribute or null */ public synchronized final Attr getNamedAttr( String name ) { AttrProxy attr; attr = _firstAttr; while (attr != null) { if (attr.getName().equals( name )) { return attr; } // Note: getNextSibling() will return null. attr = (AttrProxy)attr.getNextSibling(); } return null; } /** * Append <TT>newAttr</TT> as the last attribute of this element. * If <TT>newAttr</TT> is not an attribute of this DOM, or is already in use * by some element, an exception is thrown. * * @param newAttr The new attribute to add * @return The newly added attribute * @throws org.w3c.dom.DOMException <TT>NO_MODIFICATION_ALLOWED_ERR</TT> * Node is read-only and cannot be modified * @throws org.w3c.dom.DOMException <TT>WRONG_DOCUMENT_ERR</TT> * <TT>newAttr</TT> is not an attribute in this DOM * @throws org.w3c.dom.DOMException <TT>INUSE_ATTRIBUTE_ERR</TT> * <TT>newAttr</TT> is already in use by some other element */ public synchronized final AttrProxy appendAttr( AttrProxy newAttr ) { // Make sure the node is not read-only and the attribute can be added to it. if (isReadOnly()) { throw new DOMExceptionImpl( DOMException.NO_MODIFICATION_ALLOWED_ERR ); } if (newAttr == null) { throw new DOMExceptionImpl( DOMException.WRONG_DOCUMENT_ERR, "Attribute does not belong to same document as this element." ); } if (newAttr.getParentNode() == this) { return newAttr; } if (newAttr.getParentNode() != null) { throw new DOMExceptionImpl( DOMException.INUSE_ATTRIBUTE_ERR ); } // We're going to mess with this attribute, so make sure no other thread // is touching it synchronized (newAttr) { newAttr.setParentNode( this ); newAttr.setOwnerDocument( getOwnerDocument() ); // If the list has no end (it is empty) then newAttr is added as the // only attribute in it. if (_lastAttr == null) { _lastAttr = newAttr; _firstAttr = newAttr; newAttr.setPreviousSibling( null ); newAttr.setNextSibling( null ); } else { // newAttr becomes the new end of the list, adjusting the previous // last attribute. _lastAttr.setNextSibling( newAttr ); newAttr.setPreviousSibling( _lastAttr ); newAttr.setNextSibling( null ); _lastAttr = newAttr; } // Keep this count accurate at all times. ++_attrCount; } return newAttr; } /** * Remove <TT>oldAttr</TT> from this element. If <TT>oldAttr</TT> is not an * attribute of this element, an exception is thrown. * * @param oldAttr The attribute to remove * @return The removed attribute * @throws org.w3c.dom.DOMException <TT>NO_MODIFICATION_ALLOWED_ERR</TT> * Node is read-only and cannot be modified * @throws org.w3c.dom.DOMException <TT>NOT_FOUND_ERR</TT> * <TT>oldAttr</TT> is not an attribute of this element */ public synchronized final AttrProxy removeAttr( AttrProxy oldAttr ) throws DOMException { // Make sure the element is not read-only and the attribute belonds to it. if (isReadOnly()) { throw new DOMExceptionImpl( DOMException.NO_MODIFICATION_ALLOWED_ERR ); } // Note: getParentNode() will return null. if (oldAttr == null || ((NodeProxy)oldAttr).getParentNode() != this) { throw new DOMExceptionImpl( DOMException.NOT_FOUND_ERR, "Not an attribute of this element." ); } // We're going to mess with this attribute node, so make sure no other // thread is touching it synchronized (oldAttr) { // Attribute becomes orphan. It is no longer first or last attribute of // this element. Removed from linked list. ((NodeProxy)oldAttr).setParentNode( null ); if (_firstAttr == oldAttr) { _firstAttr = (AttrProxy)oldAttr.getNextSibling(); } if (_lastAttr == oldAttr) { _lastAttr = (AttrProxy)oldAttr.getPreviousSibling(); } if (oldAttr.getPreviousSibling() != null) { ((NodeProxy)oldAttr.getPreviousSibling()).setNextSibling( oldAttr.getNextSibling() ); } if (oldAttr.getNextSibling() != null) { ((NodeProxy)oldAttr.getNextSibling()).setPreviousSibling( oldAttr.getPreviousSibling() ); } ((NodeProxy)oldAttr).setPreviousSibling( null ); ((NodeProxy)oldAttr).setNextSibling( null ); // Keep this count accurate at all times. --_attrCount; } return oldAttr; } /** * Constructor requires only owner document and tag name of element. * Tag name is case sensitive for XML, but converted to upper case for * HTML documents. * * @param owner Owner document of this element * @param name The tag name of the element */ public ElementImpl( DocumentImpl owner, String name ) { super( owner, name, null, true ); // Make sure that all element tag names are converted to upper case // for some documents (HTML). } public ElementImpl() { super(); } public void init( NodeProxy owner, Dictionary dictionary ) { // System.out.println ("ElementImpl.init()"); } public void onDelete() throws Exception { // remove all Attributes of this Element-Node deleteAllChildern( _firstAttr ); } private void deleteAllChildern( Node node ) throws Exception { Node dummyNode; while (node != null) { if (node.hasChildNodes()) { deleteAllChildern( node.getFirstChild() ); } dummyNode = node.getNextSibling(); database().deleteObject( (OzoneRemote)node ); node = dummyNode; } } /** */ public void writeExternal( ObjectOutput out ) throws IOException { super.writeExternal( out ); out.writeByte( (byte)_attrCount ); if (_attrCount > 0) { out.writeObject( _firstAttr ); out.writeObject( _lastAttr ); } } /** */ public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { super.readExternal( in ); _attrCount = in.readByte(); if (_attrCount > 0) { _firstAttr = (AttrProxy)in.readObject(); _lastAttr = (AttrProxy)in.readObject(); } else { _firstAttr = null; _lastAttr = null; } } /** * The attributes of this element are arranged in a doubly linked lists. * This reference identifies the first attribute in the list. */ private AttrProxy _firstAttr; /** * The attributes of this element are arranged in a doubly linked lists. * This reference identifies the last attribute in the list. */ private AttrProxy _lastAttr; /** * Counts how many attributes belong to this element. */ private int _attrCount; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -