annotate NGSrich_0.5.5/src/org/jdom/Content.java @ 0:89ad0a9cca52 default tip

Uploaded
author pfrommolt
date Mon, 21 Nov 2011 08:12:19 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1 /*--
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
2
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
3 $Id: Content.java,v 1.6 2007/11/10 05:28:58 jhunter Exp $
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
4
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
5 Copyright (C) 2007 Jason Hunter & Brett McLaughlin.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
6 All rights reserved.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
7
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
8 Redistribution and use in source and binary forms, with or without
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
9 modification, are permitted provided that the following conditions
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
10 are met:
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
11
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
12 1. Redistributions of source code must retain the above copyright
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
13 notice, this list of conditions, and the following disclaimer.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
14
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
15 2. Redistributions in binary form must reproduce the above copyright
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
16 notice, this list of conditions, and the disclaimer that follows
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
17 these conditions in the documentation and/or other materials
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
18 provided with the distribution.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
19
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
20 3. The name "JDOM" must not be used to endorse or promote products
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
21 derived from this software without prior written permission. For
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
22 written permission, please contact <request_AT_jdom_DOT_org>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
23
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
24 4. Products derived from this software may not be called "JDOM", nor
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
25 may "JDOM" appear in their name, without prior written permission
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
26 from the JDOM Project Management <request_AT_jdom_DOT_org>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
27
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
28 In addition, we request (but do not require) that you include in the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
29 end-user documentation provided with the redistribution and/or in the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
30 software itself an acknowledgement equivalent to the following:
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
31 "This product includes software developed by the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
32 JDOM Project (http://www.jdom.org/)."
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
33 Alternatively, the acknowledgment may be graphical using the logos
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
34 available at http://www.jdom.org/images/logos.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
35
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
36 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
37 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
38 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
39 DISCLAIMED. IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
40 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
41 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
42 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
43 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
44 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
45 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
46 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
47 SUCH DAMAGE.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
48
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
49 This software consists of voluntary contributions made by many
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
50 individuals on behalf of the JDOM Project and was originally
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
51 created by Jason Hunter <jhunter_AT_jdom_DOT_org> and
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
52 Brett McLaughlin <brett_AT_jdom_DOT_org>. For more information
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
53 on the JDOM Project, please see <http://www.jdom.org/>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
54
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
55 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
56
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
57 package org.jdom;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
58
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
59 import java.io.*;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
60
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
61 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
62 * Superclass for JDOM objects which can be legal child content
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
63 * of {@link org.jdom.Parent} nodes.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
64 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
65 * @see org.jdom.Comment
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
66 * @see org.jdom.DocType
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
67 * @see org.jdom.Element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
68 * @see org.jdom.EntityRef
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
69 * @see org.jdom.Parent
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
70 * @see org.jdom.ProcessingInstruction
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
71 * @see org.jdom.Text
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
72 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
73 * @author Bradley S. Huffman
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
74 * @author Jason Hunter
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
75 * @version $Revision: 1.6 $, $Date: 2007/11/10 05:28:58 $
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
76 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
77 public abstract class Content implements Cloneable, Serializable {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
78
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
79 protected Parent parent = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
80
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
81 protected Content() {}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
82
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
83 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
84 * Detaches this child from its parent or does nothing if the child
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
85 * has no parent.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
86 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
87 * @return this child detached
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
88 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
89 public Content detach() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
90 if (parent != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
91 parent.removeContent(this);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
92 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
93 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
94 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
95
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
96 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
97 * Return this child's parent, or null if this child is currently
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
98 * not attached. The parent can be either an {@link Element}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
99 * or a {@link Document}.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
100 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
101 * @return this child's parent or null if none
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
102 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
103 public Parent getParent() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
104 return parent;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
105 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
106
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
107 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
108 * A convenience method that returns any parent element for this element,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
109 * or null if the element is unattached or is a root element. This was the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
110 * original behavior of getParent() in JDOM Beta 9 which began returning
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
111 * Parent in Beta 10. This method provides a convenient upgrade path for
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
112 * JDOM Beta 10 and 1.0 users.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
113 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
114 * @return the containing Element or null if unattached or a root element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
115 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
116 public Element getParentElement() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
117 Parent parent = getParent();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
118 return (Element) ((parent instanceof Element) ? parent : null);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
119 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
120
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
121 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
122 * Sets the parent of this Content. The caller is responsible for removing
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
123 * any pre-existing parentage.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
124 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
125 * @param parent new parent element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
126 * @return the target element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
127 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
128 protected Content setParent(Parent parent) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
129 this.parent = parent;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
130 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
131 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
132
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
133 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
134 * Return this child's owning document or null if the branch containing
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
135 * this child is currently not attached to a document.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
136 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
137 * @return this child's owning document or null if none
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
138 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
139 public Document getDocument() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
140 if (parent == null) return null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
141 return parent.getDocument();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
142 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
143
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
144
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
145 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
146 * Returns the XPath 1.0 string value of this child.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
147 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
148 * @return xpath string value of this child.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
149 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
150 public abstract String getValue();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
151
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
152 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
153 * Returns a deep, unattached copy of this child and its descendants
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
154 * detached from any parent or document.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
155 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
156 * @return a detached deep copy of this child and descendants
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
157 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
158 public Object clone() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
159 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
160 Content c = (Content)super.clone();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
161 c.parent = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
162 return c;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
163 } catch (CloneNotSupportedException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
164 //Can not happen ....
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
165 //e.printStackTrace();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
166 return null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
167 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
168 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
169
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
170 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
171 * This tests for equality of this Content object to the supplied object.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
172 * Content items are considered equal only if they are referentially equal
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
173 * (i&#46;e&#46; the same object). User code may choose to compare objects
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
174 * based on their properties instead.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
175 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
176 * @param ob <code>Object</code> to compare to.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
177 * @return <code>boolean</code> - whether the <code>Content</code> is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
178 * equal to the supplied <code>Object</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
179 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
180 public final boolean equals(Object ob) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
181 return (ob == this);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
182 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
183
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
184 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
185 * This returns the hash code for this <code>Content</code> item.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
186 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
187 * @return <code>int</code> - hash code.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
188 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
189 public final int hashCode() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
190 return super.hashCode();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
191 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
192 }