📄 entityimpl.java
字号:
/** * org/ozone-db/xml/dom/EntityImpl.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.*;/** * Implements an entity. * <P> * Notes: * <OL> * <LI>Node type is {@link org.w3c.dom.Node#ENTITY_NODE} * <LI>Node supports childern * <LI>Node does not have a value * <LI>Node only accessible from {@link org.w3c.dom.DocumentType} * </OL> * * * @version $Revision: 1.12 $ $Date: 2000/10/28 16:55:23 $ * @author <a href="mailto:arkin@trendline.co.il">Assaf Arkin</a> * @see org.w3c.dom.Entity * @see NodeImpl */public class EntityImpl extends NodeImpl implements EntityProxy, Externalizable { final static long serialVersionUID = 1; public short getNodeType() { return ENTITY_NODE; } public final void setNodeValue( String value ) { throw new DOMExceptionImpl( DOMException.NO_DATA_ALLOWED_ERR, "This node type does not support values." ); } public String getPublicId() { return _publicId; } public void setPublicId( String publicId ) { _publicId = publicId; } public String getSystemId() { return _systemId; } public void setSystemId( String systemId ) { _systemId = systemId; } public String getNotationName() { return _notation; } public void setNotationName( String notation ) { _notation = notation; } public final String getInternal() { return _internalValue; } /** * Returns true if entity is an unparsed general entity. An unparsed entity * is one for which a notation has been specified. * * @return True if unparsed general entity */ public boolean isUnparsed() { return _notation != null; } /** * Returns true if entity is an internal general entity. An internal entity * is one for which a value has been defined. An external entity is one for * which an external entity has been assigned through either system or * public identifiers. * <P> * If true is returned, then {@link #getInternal} will return a string * (might be empty). * * @return True if internal general entity */ public boolean isInternal() { return _internalValue != null; } public void setInternal( String internalValue ) { _internalValue = internalValue; } /** * Returns the parsing state of this entity. * * @return State of entity */ public short getState() { return _state; } /** * Changes the parsing state of this entity. Note that only some changes * are allowed: from declared to parsing, parsed or not found; from parsing * to parsed or not found; from not found to declared. * * @param newState New state of entity */ public void setState( short newState ) { if (_state == STATE_DECLARED && newState == STATE_PARSING || _state == STATE_NOT_FOUND && newState == STATE_DECLARED) { _state = newState; } else if ((_state == STATE_DECLARED || _state == STATE_PARSING) && (newState == STATE_PARSED || newState == STATE_NOT_FOUND)) { _state = newState; } else { throw new IllegalStateException( "Cannot switch from state " + _state + " to state " + newState + "." ); } } public synchronized boolean equals( Object other ) { EntityProxy otherX; // Test for node equality (this covers entity name and all its children) // and then test for specific entity qualities. if (super.equals( other )) { otherX = (EntityProxy)other; // If this entity is internal, both entities must be internal and have // equal internal value. if (this.isInternal()) { return otherX.isInternal() && this.getInternal().equals( otherX.getInternal() ); } // External or unparsed: either public id are both null, or public id // equals in both (and same for system id and notation). return (this.getPublicId() == null && otherX.getPublicId() == null || this.getPublicId() != null && this.getPublicId().equals( otherX.getPublicId() )) && (this.getSystemId() == null && otherX.getSystemId() == null || this.getSystemId() != null && this.getSystemId().equals( otherX.getSystemId() )) && (this.getNotationName() == null && otherX.getNotationName() == null || this.getNotationName() != null && this.getNotationName().equals( otherX.getNotationName() )); } return false; } public final Object clone() { EntityProxy clone = null; try { clone = (EntityProxy)database().createObject( EntityImpl.class.getName() ); clone.init( _ownerDocument, getNodeName() ); cloneInto( clone, true ); } catch (Exception except) { throw new DOMExceptionImpl( DOMExceptionImpl.PDOM_ERR, except.getMessage() ); } return clone; } public final Node cloneNode( boolean deep ) { EntityProxy clone = null; try { clone = (EntityProxy)database().createObject( EntityImpl.class.getName() ); clone.init( _ownerDocument, getNodeName() ); cloneInto( clone, deep ); } catch (Exception except) { throw new DOMExceptionImpl( DOMExceptionImpl.PDOM_ERR, except.getMessage() ); } return clone; } public String toString() { String name; String value; name = getNodeName(); if (name.length() > 32) { name = name.substring( 0, 32 ) + ".."; } if (isInternal()) { value = getInternal(); if (value.length() > 64) { value = value.substring( 0, 64 ) + ".."; } name = name + "] [" + value; } else { if (getSystemId() != null) { name = name + "] SYSTEM [" + getSystemId(); } if (getPublicId() != null) { name = name + "] PUBLIC [" + getPublicId(); } if (getNotationName() != null) { name = name + "] NDECL [" + getNotationName(); } } return "Entity decl: [" + name + "]"; } protected final boolean supportsChildern() { return true; } public synchronized void cloneInto( NodeProxy into, boolean deep ) { super.cloneInto( into, deep ); ((EntityProxy)into).setSystemId( this._systemId ); ((EntityProxy)into).setPublicId( this._publicId ); ((EntityProxy)into).setNotationName( this._notation ); ((EntityProxy)into).setInternal( this._internalValue ); ((EntityProxy)into).setState( this._state ); } /** * Constructs an unparsed general entity. Entity system identifier and notation * name must be provided, public identifier is optional. * * @param owner The owner document * @param name The entity name * @param systemId The system identifier * @param publicId The public identifier, if specified * @param notation The notation, if specified */ public EntityImpl( DocumentImpl owner, String name, String systemId, String publicId, String notation ) { super( owner, name, null, true ); if (notation == null) { throw new NullPointerException( "Argument 'notation' cannot be null." ); } else { init( owner, name, systemId, publicId, notation ); } } /** * Constructs an external general entity. Entity system identifier must be * provided, public identifier is optional. * * @param owner The owner document * @param name The entity name * @param systemId The system identifier * @param publicId The public identifier, if specified */ public EntityImpl( DocumentImpl owner, String name, String systemId, String publicId ) { super( owner, name, null, true ); if (systemId == null) { throw new NullPointerException( "Argument 'systemId' cannot be null." ); } else { init( owner, name, systemId, publicId ); } } /** * Constructs an internal general entity. Entity value must be provided. * * @param owner The owner document * @param name The entity name * @param internalValue The unparsed entity value */ public EntityImpl( DocumentImpl owner, String name, String internalValue ) { super( owner, name, null, true ); if (internalValue == null) { throw new NullPointerException( "Argument 'internalValue' cannot be null." ); } else { init( owner, name, internalValue ); } } private EntityImpl( DocumentImpl owner, String name ) { super( owner, name, null, true ); } public EntityImpl() { super(); } public void init( DocumentProxy owner, String name ) { super.init( owner, name, null, true ); } public void init( DocumentProxy owner, String name, String value ) { _systemId = null; _publicId = null; _notation = null; _state = STATE_DECLARED; _internalValue = value; } public void init( DocumentProxy owner, String name, String systemId, String publicId ) { _systemId = systemId; _publicId = publicId; _notation = null; _state = STATE_DECLARED; } public void init( DocumentProxy owner, String name, String systemId, String publicId, String notation ) { _systemId = systemId; _publicId = publicId; } /** */ public void writeExternal( ObjectOutput out ) throws IOException { super.writeExternal( out ); out.writeObject( _notation ); out.writeObject( _systemId ); out.writeObject( _publicId ); out.writeShort( _state ); out.writeObject( _internalValue ); } /** */ public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { super.readExternal( in ); _notation = (String)in.readObject(); _systemId = (String)in.readObject(); _publicId = (String)in.readObject(); _state = in.readShort(); _internalValue = (String)in.readObject(); } /** * The notation of this entity, if specified. */ protected String _notation; /** * The system identifier of this entity, if specified. */ protected String _systemId; /** * The public identifier of this entity, if specified. */ protected String _publicId; /** * Identifies the state of this entity as yet to be parsed, being parsed, * has been parsed, or cannot be found. */ private short _state; /** * Holds the internal value of the entity. */ private String _internalValue; /** * Entity has been declared but not parsed. This is the initial state for * an entity after it has been declared in the DTD but before it is used * in the document contents. */ public final static short STATE_DECLARED = 0; /** * Entity is being parsed. This state designates that the entity is being * parsed right now. State is used to identify circular references. */ public final static short STATE_PARSING = 1; /** * Entity has been parsed. This state indicates that entity has been parsed * and it's parsed contents is contained in its child nodes. */ public final static short STATE_PARSED = 2; /** * Entity not found. The entity could not be parsed before. */ public final static short STATE_NOT_FOUND = 3; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -