001: /**
002: * org/ozone-db/xml/dom/EntityReferenceImpl.java
003: *
004: * The contents of this file are subject to the OpenXML Public
005: * License Version 1.0; you may not use this file except in compliance
006: * with the License. You may obtain a copy of the License at
007: * http://www.openxml.org/license.html
008: *
009: * THIS SOFTWARE IS DISTRIBUTED ON AN "AS IS" BASIS WITHOUT WARRANTY
010: * OF ANY KIND, EITHER EXPRESSED OR IMPLIED. THE INITIAL DEVELOPER
011: * AND ALL CONTRIBUTORS SHALL NOT BE LIABLE FOR ANY DAMAGES AS A
012: * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
013: * DERIVATIVES. SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING
014: * RIGHTS AND LIMITATIONS UNDER THE LICENSE.
015: *
016: * The Initial Developer of this code under the License is Assaf Arkin.
017: * Portions created by Assaf Arkin are Copyright (C) 1998, 1999.
018: * All Rights Reserved.
019: */
020:
021: /**
022: * Changes for Persistent DOM running with ozone are
023: * Copyright 1999 by SMB GmbH. All rights reserved.
024: */package org.ozoneDB.xml.dom;
025:
026: import org.w3c.dom.*;
027:
028: /**
029: * Implements an entity reference. Entity references are read-only when an XML
030: * document is parsed, but are modifiable when an XML document is created in
031: * memory.
032: * <P>
033: * Notes:
034: * <OL>
035: * <LI>Node type is {@link org.w3c.dom.Node#ENTITY_REFERENCE_NODE}
036: * <LI>Node supports childern
037: * <LI>Node does not have a value
038: * <LI>One of two nodes that may be added to an attribute or an element
039: * </OL>
040: *
041: *
042: * @version $Revision: 1.1 $ $Date: 2001/12/18 11:03:24 $
043: * @author <a href="mailto:arkin@trendline.co.il">Assaf Arkin</a>
044: * @see org.w3c.dom.EntityReference
045: * @see NodeImpl
046: */
047: public final class EntityReferenceImpl extends NodeImpl implements
048: EntityReferenceProxy {
049:
050: final static long serialVersionUID = 1;
051:
052: public short getNodeType() {
053: return this .ENTITY_REFERENCE_NODE;
054: }
055:
056: public final void setNodeValue(String value) {
057: throw new DOMExceptionImpl(DOMException.NO_DATA_ALLOWED_ERR,
058: "This node type does not support values.");
059: }
060:
061: public final Object clone() {
062: EntityReferenceProxy clone = null;
063: try {
064: clone = (EntityReferenceProxy) database().createObject(
065: EntityReferenceImpl.class.getName());
066: clone.init(_ownerDocument, getNodeName());
067: cloneInto((NodeProxy) clone, true);
068: } catch (Exception except) {
069: throw new DOMExceptionImpl(DOMExceptionImpl.PDOM_ERR,
070: except.getMessage());
071: }
072: return clone;
073: }
074:
075: public final Node cloneNode(boolean deep) {
076: EntityReferenceProxy clone = null;
077: try {
078: clone = (EntityReferenceProxy) database().createObject(
079: EntityReferenceImpl.class.getName());
080: clone.init(_ownerDocument, getNodeName());
081: cloneInto((NodeProxy) clone, deep);
082: } catch (Exception except) {
083: throw new DOMExceptionImpl(DOMExceptionImpl.PDOM_ERR,
084: except.getMessage());
085: }
086: return clone;
087: }
088:
089: public String toString() {
090: String name;
091:
092: name = getNodeName();
093: if (name.length() > 32) {
094: name = name.substring(0, 32) + "..";
095: }
096: return "Entity ref: [" + name + "]";
097: }
098:
099: protected final boolean supportsChildern() {
100: return true;
101: }
102:
103: /**
104: * Parses an entity reference based on the entities contained in the document.
105: * If an entity with a matching name is found, it is parsed and the textual
106: * value is returned. Otherwise, an empty string is returned.
107: *
108: * @return Parsed entity reference or empty string
109: */
110: /*
111: synchronized String parseEntity() {
112: NamedNodeMap entities;
113: Node node;
114: StringBuffer parsed;
115: DocumentType docType;
116:
117: parsed = new StringBuffer();
118: // This document supports attribute children as per the XML spec
119: docType = getDocument().getDoctype();
120: if ( docType != null ) {
121: entities = docType.getEntities();
122: node = entities.getNamedItem( getNodeName() );
123: if ( node != null )
124: synchronized ( node ) {
125: node = node.getFirstChild();
126: while ( node != null ) {
127: if ( node instanceof Text )
128: parsed.append( ( (Text) node ).getData() );
129: else
130: if ( node instanceof EntityReference )
131: parsed.append( ( (EntityReferenceImpl) node ).parseEntity() );
132: node = node.getNextSibling();
133: }
134: }
135: }
136: return parsed.toString();
137: }
138: */
139:
140: /**
141: * Constructor requires only owner document and entity name.
142: *
143: * @param owner The owner of this document
144: * @param name The entity name
145: */
146: EntityReferenceImpl(DocumentImpl owner, String name) {
147: super (owner, name, null, true);
148: }
149:
150: public EntityReferenceImpl() {
151: super ();
152: }
153:
154: public void init(DocumentProxy owner, String name) {
155: super .init(owner, name, null, true);
156: }
157: }
|