📄 attrimpl.java
字号:
/**
* org/ozone-db/xml/dom/AttrImpl.java
*
* The contents of this file are subject to the OpenXML Public
* License Version 1.0; you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://www.openxml.org/license.html
*
* THIS SOFTWARE IS DISTRIBUTED ON AN "AS IS" BASIS WITHOUT WARRANTY
* OF ANY KIND, EITHER EXPRESSED OR IMPLIED. THE INITIAL DEVELOPER
* AND ALL CONTRIBUTORS SHALL NOT BE LIABLE FOR ANY DAMAGES AS A
* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING
* RIGHTS AND LIMITATIONS UNDER THE LICENSE.
*
* The Initial Developer of this code under the License is Assaf Arkin.
* Portions created by Assaf Arkin are Copyright (C) 1998, 1999.
* All Rights Reserved.
*/
/**
* Changes for Persistent DOM running with ozone are
* Copyright 1999 by SMB GmbH. All rights reserved.
*/
package org.ozoneDB.xml.dom;
import java.io.*;
import org.w3c.dom.*;
import org.w3c.dom.html.HTMLDocument;
/**
* Represents an attribute in an {@link org.w3c.dom.Element} node.
* <P>
* Attributes are not real nodes, they are not children in their parent element
* and the methods {@link AttrImpl#getParentNode}, {@link AttrImpl#getNextSibling}
* and {@link #getPreviousSibling} always return null.
* <P>
* Attributes in XML documents support children, but only of the type {@link
* org.w3c.dom.Text} and {@link org.w3c.dom.EntityReference}.
* <P>
* The specified value of an attribute indicates whether it's value has been
* changed since it was constructed with the default value. The specified value
* is not used when cloning an attribute or testing for equality.
* <P>
* To speed up implementation, all attributes are implemented as double-linked
* list using {@link NodeImpl#_parent}, {@link NodeImpl#_nextNode} and
* {@link NodeImpl#_prevNode}.
*
*
* @version $Revision: 1.2 $ $Date: 2003/11/20 23:18:42 $
* @author <a href="mailto:arkin@trendline.co.il">Assaf Arkin</a>
* @see org.w3c.dom.Attr
* @see NodeImpl
* @see ElementImpl
*/
public final class AttrImpl extends NodeImpl implements AttrProxy, Externalizable {
final static long serialVersionUID = 1;
public Element getOwnerElement() {
return (Element)getParentNode();
}
public final short getNodeType() {
return ATTRIBUTE_NODE;
}
public final String getName() {
return getNodeName();
}
public final boolean getSpecified() {
return _specified;
}
public void setSpecified( boolean value ) {
_specified = value;
}
public String getValue() {
return getNodeValue();
}
public void setNodeValue( String value ) {
super.setNodeValue( value );
_specified = true;
}
public void setValue( String value ) {
super.setNodeValue( value );
_specified = true;
}
// public Node getParentNode() {
// // Must return null per DOM spec.
// return null;
// }
//
// public Node getPreviousSibling() {
// // Must return null per DOM spec.
// return null;
// }
//
// public Node getNextSibling() {
// // Must return null per DOM spec.
// return null;
// }
public String toString() {
String value;
value = getValue();
if (value.length() > 32) {
value = value.substring( 0, 32 ) + "..";
}
return "Attribute node: [" + getName() + "] [" + value + (_specified ? "] SPECIFIED" : "]");
}
protected boolean supportsChildern() {
return true;
}
public final Object clone() {
AttrProxy clone = null;
try {
clone = (AttrProxy)database().createObject( AttrImpl.class.getName() );
clone.init( _ownerDocument, getNodeName(), getNodeValue() );
cloneInto( clone, true );
} catch (Exception except) {
throw new DOMExceptionImpl( DOMExceptionImpl.PDOM_ERR, except.getMessage() );
}
return clone;
}
public final Node cloneNode( boolean deep ) {
AttrProxy clone = null;
try {
clone = (AttrProxy)database().createObject( AttrImpl.class.getName() );
clone.init( _ownerDocument, getNodeName(), getNodeValue() );
cloneInto( clone, deep );
} catch (Exception except) {
throw new DOMExceptionImpl( DOMExceptionImpl.PDOM_ERR, except.getMessage() );
}
return clone;
}
public synchronized void cloneInto( NodeProxy into, boolean deep ) {
super.cloneInto( into, deep );
((AttrProxy)into).setSpecified( getSpecified() );
}
/**
* Assures that the children of an attribute are either {@link
* org.w3c.dom.Text} or {@link org.w3c.dom.EntityReference}.
*
* @see NodeImpl#castNewChild
*/
protected Node castNewChild( Node newChild ) throws DOMException {
if (newChild == null) {
throw new DOMExceptionImpl( DOMException.HIERARCHY_REQUEST_ERR, "Child reference is null." );
}
if (!(newChild instanceof Text || newChild instanceof EntityReference)) {
throw new DOMExceptionImpl( DOMException.HIERARCHY_REQUEST_ERR,
"Child is not a compatible type for this node." );
}
return newChild;
}
/** */
public void writeExternal( ObjectOutput out ) throws IOException {
super.writeExternal( out );
out.writeBoolean( _specified );
}
/** */
public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException {
super.readExternal( in );
_specified = in.readBoolean();
}
/**
* Hidden constructor for attribute. Note that <TT>value</TT> is the DTD's
* default value for this attribute, it is not the value specified in the XML
* document. The value specified in the XML document should be passed by
* calling {@link #setValue} explicitly.
* <P>
* The attribute name is case sensitive for XML, but is case insensitive and
* all lower case for HTML documents. <TT>owner</TT> must point to a valid
* document object.
*
* @param owner The owner document
* @param name The attribute's name
* @param defValue The attribute's value as specified in the DTD or null
*/
AttrImpl( DocumentImpl owner, String name, String defValue ) {
super( owner, owner instanceof HTMLDocument ? name.toLowerCase() : name, defValue, true );
// Make sure that all attribute names are converted to lower case
// for HTML documents.
// Specified is always false. If a value was specified, it was the
// default.
_specified = false;
}
public AttrImpl() {
super();
_specified = false;
}
public final void init( DocumentProxy owner, String name, String value ) {
super.init( owner, owner instanceof HTMLDocument ? name.toLowerCase() : name, value, true );
}
/**
* True if a value has been specified for this node in the document.
* This value is not used when cloning or testing for equality.
*/
private boolean _specified;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -