KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > dom > AbstractEntityReference


1 /*
2
3    Copyright 2000-2002 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.dom;
19
20 import org.apache.batik.dom.util.DOMUtilities;
21 import org.w3c.dom.DOMException JavaDoc;
22 import org.w3c.dom.EntityReference JavaDoc;
23 import org.w3c.dom.Node JavaDoc;
24
25 /**
26  * This class implements the {@link org.w3c.dom.EntityReference} interface.
27  *
28  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
29  * @version $Id: AbstractEntityReference.java,v 1.7 2005/02/22 09:12:58 cam Exp $
30  */

31 public abstract class AbstractEntityReference
32     extends AbstractParentChildNode
33     implements EntityReference JavaDoc {
34     /**
35      * The node name.
36      */

37     protected String JavaDoc nodeName;
38
39     /**
40      * Creates a new EntityReference object.
41      */

42     protected AbstractEntityReference() {
43     }
44
45     /**
46      * Creates a new EntityReference object.
47      * @param name The entity name.
48      * @param owner The owner document.
49      * @exception DOMException
50      * INVALID_CHARACTER_ERR: Raised if the specified name contains an
51      * illegal character.
52      */

53     protected AbstractEntityReference(String JavaDoc name, AbstractDocument owner)
54     throws DOMException JavaDoc {
55     ownerDocument = owner;
56
57     if (!DOMUtilities.isValidName(name)) {
58         throw createDOMException(DOMException.INVALID_CHARACTER_ERR,
59                      "xml.name",
60                      new Object JavaDoc[] { name });
61     }
62     nodeName = name;
63     }
64
65     /**
66      * <b>DOM</b>: Implements {@link org.w3c.dom.Node#getNodeType()}.
67      * @return {@link org.w3c.dom.Node#ENTITY_REFERENCE_NODE}
68      */

69     public short getNodeType() {
70     return ENTITY_REFERENCE_NODE;
71     }
72
73     /**
74      * Sets the name of this node.
75      */

76     public void setNodeName(String JavaDoc v) {
77     nodeName = v;
78     }
79
80     /**
81      * <b>DOM</b>: Implements {@link org.w3c.dom.Node#getNodeName()}.
82      * @return {@link #nodeName}.
83      */

84     public String JavaDoc getNodeName() {
85     return nodeName;
86     }
87
88     /**
89      * Exports this node to the given document.
90      */

91     protected Node JavaDoc export(Node JavaDoc n, AbstractDocument d) {
92     super.export(n, d);
93     AbstractEntityReference ae = (AbstractEntityReference)n;
94     ae.nodeName = nodeName;
95     return n;
96     }
97
98     /**
99      * Deeply exports this node to the given document.
100      */

101     protected Node JavaDoc deepExport(Node JavaDoc n, AbstractDocument d) {
102     super.deepExport(n, d);
103     AbstractEntityReference ae = (AbstractEntityReference)n;
104     ae.nodeName = nodeName;
105     return n;
106     }
107
108     /**
109      * Copy the fields of the current node into the given node.
110      * @param n a node of the type of this.
111      */

112     protected Node JavaDoc copyInto(Node JavaDoc n) {
113     super.copyInto(n);
114     AbstractEntityReference ae = (AbstractEntityReference)n;
115     ae.nodeName = nodeName;
116     return n;
117     }
118
119     /**
120      * Deeply copy the fields of the current node into the given node.
121      * @param n a node of the type of this.
122      */

123     protected Node JavaDoc deepCopyInto(Node JavaDoc n) {
124     super.deepCopyInto(n);
125     AbstractEntityReference ae = (AbstractEntityReference)n;
126     ae.nodeName = nodeName;
127     return n;
128     }
129
130     /**
131      * Checks the validity of a node to be inserted.
132      */

133     protected void checkChildType(Node JavaDoc n, boolean replace) {
134     switch (n.getNodeType()) {
135     case ELEMENT_NODE:
136     case PROCESSING_INSTRUCTION_NODE:
137     case COMMENT_NODE:
138     case TEXT_NODE:
139     case CDATA_SECTION_NODE:
140     case ENTITY_REFERENCE_NODE:
141     case DOCUMENT_FRAGMENT_NODE:
142         break;
143     default:
144         throw createDOMException
145                 (DOMException.HIERARCHY_REQUEST_ERR,
146                  "child.type",
147                  new Object JavaDoc[] { new Integer JavaDoc(getNodeType()),
148                                 getNodeName(),
149                                 new Integer JavaDoc(n.getNodeType()),
150                                 n.getNodeName() });
151     }
152     }
153 }
154
Popular Tags