KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > xml > dom > EntityReferenceImpl


1 /**
2  * org/ozone-db/xml/dom/EntityReferenceImpl.java
3  *
4  * The contents of this file are subject to the OpenXML Public
5  * License Version 1.0; you may not use this file except in compliance
6  * with the License. You may obtain a copy of the License at
7  * http://www.openxml.org/license.html
8  *
9  * THIS SOFTWARE IS DISTRIBUTED ON AN "AS IS" BASIS WITHOUT WARRANTY
10  * OF ANY KIND, EITHER EXPRESSED OR IMPLIED. THE INITIAL DEVELOPER
11  * AND ALL CONTRIBUTORS SHALL NOT BE LIABLE FOR ANY DAMAGES AS A
12  * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
13  * DERIVATIVES. SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING
14  * RIGHTS AND LIMITATIONS UNDER THE LICENSE.
15  *
16  * The Initial Developer of this code under the License is Assaf Arkin.
17  * Portions created by Assaf Arkin are Copyright (C) 1998, 1999.
18  * All Rights Reserved.
19  */

20
21 /**
22  * Changes for Persistent DOM running with ozone are
23  * Copyright 1999 by SMB GmbH. All rights reserved.
24  */

25
26 package org.ozoneDB.xml.dom;
27
28 import org.w3c.dom.*;
29
30
31 /**
32  * Implements an entity reference. Entity references are read-only when an XML
33  * document is parsed, but are modifiable when an XML document is created in
34  * memory.
35  * <P>
36  * Notes:
37  * <OL>
38  * <LI>Node type is {@link org.w3c.dom.Node#ENTITY_REFERENCE_NODE}
39  * <LI>Node supports childern
40  * <LI>Node does not have a value
41  * <LI>One of two nodes that may be added to an attribute or an element
42  * </OL>
43  *
44  *
45  * @version $Revision: 1.2 $ $Date: 2003/11/20 23:18:42 $
46  * @author <a HREF="mailto:arkin@trendline.co.il">Assaf Arkin</a>
47  * @see org.w3c.dom.EntityReference
48  * @see NodeImpl
49  */

50 public final class EntityReferenceImpl extends NodeImpl implements EntityReferenceProxy {
51
52     final static long serialVersionUID = 1;
53
54
55     public short getNodeType() {
56         return this.ENTITY_REFERENCE_NODE;
57     }
58
59
60     public final void setNodeValue( String JavaDoc value ) {
61         throw new DOMExceptionImpl( DOMException.NO_DATA_ALLOWED_ERR, "This node type does not support values." );
62     }
63
64
65     public final Object JavaDoc clone() {
66         EntityReferenceProxy clone = null;
67         try {
68             clone = (EntityReferenceProxy)database().createObject( EntityReferenceImpl.class.getName() );
69             clone.init( _ownerDocument, getNodeName() );
70             cloneInto( clone, true );
71         } catch (Exception JavaDoc except) {
72             throw new DOMExceptionImpl( DOMExceptionImpl.PDOM_ERR, except.getMessage() );
73         }
74         return clone;
75     }
76
77
78     public final Node cloneNode( boolean deep ) {
79         EntityReferenceProxy clone = null;
80         try {
81             clone = (EntityReferenceProxy)database().createObject( EntityReferenceImpl.class.getName() );
82             clone.init( _ownerDocument, getNodeName() );
83             cloneInto( clone, deep );
84         } catch (Exception JavaDoc except) {
85             throw new DOMExceptionImpl( DOMExceptionImpl.PDOM_ERR, except.getMessage() );
86         }
87         return clone;
88     }
89
90
91     public String JavaDoc toString() {
92         String JavaDoc name;
93
94         name = getNodeName();
95         if (name.length() > 32) {
96             name = name.substring( 0, 32 ) + "..";
97         }
98         return "Entity ref: [" + name + "]";
99     }
100
101
102     protected final boolean supportsChildern() {
103         return true;
104     }
105
106     /**
107      * Parses an entity reference based on the entities contained in the document.
108      * If an entity with a matching name is found, it is parsed and the textual
109      * value is returned. Otherwise, an empty string is returned.
110      *
111      * @return Parsed entity reference or empty string
112      */

113     /*
114     synchronized String parseEntity() {
115         NamedNodeMap entities;
116         Node node;
117         StringBuffer parsed;
118         DocumentType docType;
119
120         parsed = new StringBuffer();
121         // This document supports attribute children as per the XML spec
122         docType = getDocument().getDoctype();
123         if ( docType != null ) {
124             entities = docType.getEntities();
125             node = entities.getNamedItem( getNodeName() );
126             if ( node != null )
127                 synchronized ( node ) {
128                     node = node.getFirstChild();
129                     while ( node != null ) {
130                         if ( node instanceof Text )
131                             parsed.append( ( (Text) node ).getData() );
132                         else
133                         if ( node instanceof EntityReference )
134                             parsed.append( ( (EntityReferenceImpl) node ).parseEntity() );
135                         node = node.getNextSibling();
136                         }
137                     }
138             }
139         return parsed.toString();
140         }
141      */

142
143
144     /**
145      * Constructor requires only owner document and entity name.
146      *
147      * @param owner The owner of this document
148      * @param name The entity name
149      */

150     EntityReferenceImpl( DocumentImpl owner, String JavaDoc name ) {
151         super( owner, name, null, true );
152     }
153
154
155     public EntityReferenceImpl() {
156         super();
157     }
158
159
160     public void init( DocumentProxy owner, String JavaDoc name ) {
161         super.init( owner, name, null, true );
162     }
163 }
164
Popular Tags