annotate NGSrich_0.5.5/src/org/jdom/Attribute.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: Attribute.java,v 1.56 2007/11/10 05:28:58 jhunter Exp $
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
4
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
5 Copyright (C) 2000-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 * An XML attribute. Methods allow the user to obtain the value of the attribute
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
63 * as well as namespace and type information.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
64 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
65 * @version $Revision: 1.56 $, $Date: 2007/11/10 05:28:58 $
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
66 * @author Brett McLaughlin
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
67 * @author Jason Hunter
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
68 * @author Elliotte Rusty Harold
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
69 * @author Wesley Biggs
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
70 * @author Victor Toni
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
71 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
72 public class Attribute implements Serializable, Cloneable {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
73
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
74 private static final String CVS_ID =
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
75 "@(#) $RCSfile: Attribute.java,v $ $Revision: 1.56 $ $Date: 2007/11/10 05:28:58 $ $Name: jdom_1_1_1 $";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
76
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
77 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
78 * Attribute type: the attribute has not been declared or type
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
79 * is unknown.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
80 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
81 * @see #getAttributeType
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
82 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
83 public final static int UNDECLARED_TYPE = 0;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
84
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
85 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
86 * Attribute type: the attribute value is a string.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
87 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
88 * @see #getAttributeType
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
89 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
90 public final static int CDATA_TYPE = 1;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
91
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
92 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
93 * Attribute type: the attribute value is a unique identifier.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
94 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
95 * @see #getAttributeType
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
96 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
97 public final static int ID_TYPE = 2;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
98
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
99 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
100 * Attribute type: the attribute value is a reference to a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
101 * unique identifier.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
102 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
103 * @see #getAttributeType
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
104 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
105 public final static int IDREF_TYPE = 3;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
106
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
107 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
108 * Attribute type: the attribute value is a list of references to
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
109 * unique identifiers.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
110 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
111 * @see #getAttributeType
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
112 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
113 public final static int IDREFS_TYPE = 4;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
114
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
115 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
116 * Attribute type: the attribute value is the name of an entity.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
117 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
118 * @see #getAttributeType
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
119 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
120 public final static int ENTITY_TYPE = 5;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
121
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
122 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
123 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
124 * Attribute type: the attribute value is a list of entity names.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
125 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
126 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
127 * @see #getAttributeType
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
128 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
129 public final static int ENTITIES_TYPE = 6;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
130
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
131 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
132 * Attribute type: the attribute value is a name token.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
133 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
134 * According to SAX 2.0 specification, attributes of enumerated
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
135 * types should be reported as "NMTOKEN" by SAX parsers. But the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
136 * major parsers (Xerces and Crimson) provide specific values
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
137 * that permit to recognize them as {@link #ENUMERATED_TYPE}.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
138 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
139 * @see #getAttributeType
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
140 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
141 public final static int NMTOKEN_TYPE = 7;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
142
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
143 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
144 * Attribute type: the attribute value is a list of name tokens.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
145 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
146 * @see #getAttributeType
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
147 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
148 public final static int NMTOKENS_TYPE = 8;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
149
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
150 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
151 * Attribute type: the attribute value is the name of a notation.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
152 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
153 * @see #getAttributeType
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
154 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
155 public final static int NOTATION_TYPE = 9;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
156
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
157 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
158 * Attribute type: the attribute value is a name token from an
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
159 * enumeration.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
160 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
161 * @see #getAttributeType
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
162 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
163 public final static int ENUMERATED_TYPE = 10;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
164
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
165 // Keep the old constant names for one beta cycle to help migration
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
166
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
167
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
168
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
169 /** The local name of the <code>Attribute</code> */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
170 protected String name;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
171
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
172 /** The <code>{@link Namespace}</code> of the <code>Attribute</code> */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
173 protected transient Namespace namespace;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
174
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
175 /** The value of the <code>Attribute</code> */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
176 protected String value;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
177
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
178 /** The type of the <code>Attribute</code> */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
179 protected int type = UNDECLARED_TYPE;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
180
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
181 /** Parent element, or null if none */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
182 protected Element parent;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
183
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
184 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
185 * Default, no-args constructor for implementations to use if needed.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
186 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
187 protected Attribute() {}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
188
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
189 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
190 * This will create a new <code>Attribute</code> with the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
191 * specified (local) name and value, and in the provided
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
192 * <code>{@link Namespace}</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
193 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
194 * @param name <code>String</code> name of <code>Attribute</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
195 * @param value <code>String</code> value for new attribute.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
196 * @param namespace <code>Namespace</code> namespace for new attribute.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
197 * @throws IllegalNameException if the given name is illegal as an
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
198 * attribute name or if if the new namespace is the default
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
199 * namespace. Attributes cannot be in a default namespace.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
200 * @throws IllegalDataException if the given attribute value is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
201 * illegal character data (as determined by
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
202 * {@link org.jdom.Verifier#checkCharacterData}).
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
203 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
204 public Attribute(final String name, final String value, final Namespace namespace) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
205 this(name, value, UNDECLARED_TYPE, namespace);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
206 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
207
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
208 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
209 * This will create a new <code>Attribute</code> with the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
210 * specified (local) name, value, and type, and in the provided
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
211 * <code>{@link Namespace}</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
212 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
213 * @param name <code>String</code> name of <code>Attribute</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
214 * @param value <code>String</code> value for new attribute.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
215 * @param type <code>int</code> type for new attribute.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
216 * @param namespace <code>Namespace</code> namespace for new attribute.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
217 * @throws IllegalNameException if the given name is illegal as an
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
218 * attribute name or if if the new namespace is the default
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
219 * namespace. Attributes cannot be in a default namespace.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
220 * @throws IllegalDataException if the given attribute value is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
221 * illegal character data (as determined by
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
222 * {@link org.jdom.Verifier#checkCharacterData}) or
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
223 * if the given attribute type is not one of the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
224 * supported types.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
225 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
226 public Attribute(final String name, final String value, final int type, final Namespace namespace) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
227 setName(name);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
228 setValue(value);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
229 setAttributeType(type);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
230 setNamespace(namespace);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
231 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
232
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
233 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
234 * This will create a new <code>Attribute</code> with the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
235 * specified (local) name and value, and does not place
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
236 * the attribute in a <code>{@link Namespace}</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
237 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
238 * <b>Note</b>: This actually explicitly puts the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
239 * <code>Attribute</code> in the "empty" <code>Namespace</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
240 * (<code>{@link Namespace#NO_NAMESPACE}</code>).
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
241 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
242 * @param name <code>String</code> name of <code>Attribute</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
243 * @param value <code>String</code> value for new attribute.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
244 * @throws IllegalNameException if the given name is illegal as an
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
245 * attribute name.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
246 * @throws IllegalDataException if the given attribute value is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
247 * illegal character data (as determined by
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
248 * {@link org.jdom.Verifier#checkCharacterData}).
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
249 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
250 public Attribute(final String name, final String value) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
251 this(name, value, UNDECLARED_TYPE, Namespace.NO_NAMESPACE);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
252 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
253
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
254 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
255 * This will create a new <code>Attribute</code> with the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
256 * specified (local) name, value and type, and does not place
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
257 * the attribute in a <code>{@link Namespace}</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
258 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
259 * <b>Note</b>: This actually explicitly puts the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
260 * <code>Attribute</code> in the "empty" <code>Namespace</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
261 * (<code>{@link Namespace#NO_NAMESPACE}</code>).
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
262 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
263 * @param name <code>String</code> name of <code>Attribute</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
264 * @param value <code>String</code> value for new attribute.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
265 * @param type <code>int</code> type for new attribute.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
266 * @throws IllegalNameException if the given name is illegal as an
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
267 * attribute name.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
268 * @throws IllegalDataException if the given attribute value is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
269 * illegal character data (as determined by
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
270 * {@link org.jdom.Verifier#checkCharacterData}) or
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
271 * if the given attribute type is not one of the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
272 * supported types.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
273 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
274 public Attribute(final String name, final String value, final int type) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
275 this(name, value, type, Namespace.NO_NAMESPACE);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
276 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
277
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
278 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
279 * This will return the parent of this <code>Attribute</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
280 * If there is no parent, then this returns <code>null</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
281 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
282 * @return parent of this <code>Attribute</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
283 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
284 public Element getParent() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
285 return parent;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
286 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
287
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
288 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
289 * This retrieves the owning <code>{@link Document}</code> for
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
290 * this Attribute, or null if not a currently a member of a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
291 * <code>{@link Document}</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
292 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
293 * @return <code>Document</code> owning this Attribute, or null.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
294 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
295 public Document getDocument() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
296 final Element parentElement = getParent();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
297 if (parentElement != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
298 return parentElement.getDocument();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
299 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
300
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
301 return null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
302 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
303
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
304 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
305 * This will set the parent of this <code>Attribute</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
306 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
307 * @param parent <code>Element</code> to be new parent.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
308 * @return this <code>Attribute</code> modified.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
309 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
310 protected Attribute setParent(final Element parent) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
311 this.parent = parent;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
312 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
313 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
314
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
315 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
316 * This detaches the <code>Attribute</code> from its parent, or does
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
317 * nothing if the <code>Attribute</code> has no parent.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
318 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
319 * @return <code>Attribute</code> - this <code>Attribute</code> modified.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
320 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
321 public Attribute detach() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
322 final Element parentElement = getParent();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
323 if (parentElement != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
324 parentElement.removeAttribute(getName(),getNamespace());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
325 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
326
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
327 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
328 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
329
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
330 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
331 * This will retrieve the local name of the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
332 * <code>Attribute</code>. For any XML attribute
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
333 * which appears as
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
334 * <code>[namespacePrefix]:[attributeName]</code>,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
335 * the local name of the attribute would be
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
336 * <code>[attributeName]</code>. When the attribute
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
337 * has no namespace, the local name is simply the attribute
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
338 * name.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
339 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
340 * To obtain the namespace prefix for this
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
341 * attribute, the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
342 * <code>{@link #getNamespacePrefix()}</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
343 * method should be used.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
344 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
345 * @return <code>String</code> - name of this attribute,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
346 * without any namespace prefix.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
347 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
348 public String getName() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
349 return name;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
350 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
351
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
352 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
353 * This sets the local name of the <code>Attribute</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
354 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
355 * @param name the new local name to set
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
356 * @return <code>Attribute</code> - the attribute modified.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
357 * @throws IllegalNameException if the given name is illegal as an
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
358 * attribute name.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
359 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
360 public Attribute setName(final String name) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
361 final String reason = Verifier.checkAttributeName(name);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
362 if (reason != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
363 throw new IllegalNameException(name, "attribute", reason);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
364 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
365 this.name = name;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
366 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
367 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
368
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
369 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
370 * This will retrieve the qualified name of the <code>Attribute</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
371 * For any XML attribute whose name is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
372 * <code>[namespacePrefix]:[elementName]</code>,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
373 * the qualified name of the attribute would be
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
374 * everything (both namespace prefix and
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
375 * element name). When the attribute has no
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
376 * namespace, the qualified name is simply the attribute's
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
377 * local name.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
378 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
379 * To obtain the local name of the attribute, the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
380 * <code>{@link #getName()}</code> method should be used.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
381 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
382 * To obtain the namespace prefix for this attribute,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
383 * the <code>{@link #getNamespacePrefix()}</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
384 * method should be used.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
385 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
386 * @return <code>String</code> - full name for this element.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
387 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
388 public String getQualifiedName() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
389 // Note: Any changes here should be reflected in
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
390 // XMLOutputter.printQualifiedName()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
391 final String prefix = namespace.getPrefix();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
392
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
393 // no prefix found
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
394 if ((prefix == null) || ("".equals(prefix))) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
395 return getName();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
396 } else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
397 return new StringBuffer(prefix)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
398 .append(':')
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
399 .append(getName())
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
400 .toString();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
401 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
402 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
403
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
404 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
405 * This will retrieve the namespace prefix of the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
406 * <code>Attribute</code>. For any XML attribute
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
407 * which appears as
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
408 * <code>[namespacePrefix]:[attributeName]</code>,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
409 * the namespace prefix of the attribute would be
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
410 * <code>[namespacePrefix]</code>. When the attribute
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
411 * has no namespace, an empty <code>String</code> is returned.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
412 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
413 * @return <code>String</code> - namespace prefix of this
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
414 * attribute.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
415 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
416 public String getNamespacePrefix() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
417 return namespace.getPrefix();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
418 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
419
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
420 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
421 * This returns the URI mapped to this <code>Attribute</code>'s
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
422 * prefix. If no mapping is found, an empty <code>String</code> is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
423 * returned.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
424 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
425 * @return <code>String</code> - namespace URI for this <code>Attribute</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
426 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
427 public String getNamespaceURI() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
428 return namespace.getURI();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
429 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
430
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
431 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
432 * This will return this <code>Attribute</code>'s
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
433 * <code>{@link Namespace}</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
434 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
435 * @return <code>Namespace</code> - Namespace object for this <code>Attribute</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
436 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
437 public Namespace getNamespace() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
438 return namespace;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
439 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
440
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
441 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
442 * This sets this <code>Attribute</code>'s <code>{@link Namespace}</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
443 * If the provided namespace is null, the attribute will have no namespace.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
444 * The namespace must have a prefix.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
445 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
446 * @param namespace the new namespace
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
447 * @return <code>Element</code> - the element modified.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
448 * @throws IllegalNameException if the new namespace is the default
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
449 * namespace. Attributes cannot be in a default namespace.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
450 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
451 public Attribute setNamespace(Namespace namespace) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
452 if (namespace == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
453 namespace = Namespace.NO_NAMESPACE;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
454 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
455
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
456 // Verify the attribute isn't trying to be in a default namespace
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
457 // Attributes can't be in a default namespace
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
458 if (namespace != Namespace.NO_NAMESPACE &&
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
459 "".equals(namespace.getPrefix())) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
460 throw new IllegalNameException("", "attribute namespace",
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
461 "An attribute namespace without a prefix can only be the " +
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
462 "NO_NAMESPACE namespace");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
463 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
464 this.namespace = namespace;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
465 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
466 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
467
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
468 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
469 * This will return the actual textual value of this
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
470 * <code>Attribute</code>. This will include all text
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
471 * within the quotation marks.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
472 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
473 * @return <code>String</code> - value for this attribute.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
474 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
475 public String getValue() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
476 return value;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
477 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
478
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
479 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
480 * This will set the value of the <code>Attribute</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
481 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
482 * @param value <code>String</code> value for the attribute.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
483 * @return <code>Attribute</code> - this Attribute modified.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
484 * @throws IllegalDataException if the given attribute value is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
485 * illegal character data (as determined by
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
486 * {@link org.jdom.Verifier#checkCharacterData}).
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
487 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
488 public Attribute setValue(final String value) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
489 final String reason = Verifier.checkCharacterData(value);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
490 if (reason != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
491 throw new IllegalDataException(value, "attribute", reason);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
492 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
493 this.value = value;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
494 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
495 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
496
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
497 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
498 * This will return the actual declared type of this
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
499 * <code>Attribute</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
500 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
501 * @return <code>int</code> - type for this attribute.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
502 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
503 public int getAttributeType() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
504 return type;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
505 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
506
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
507 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
508 * This will set the type of the <code>Attribute</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
509 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
510 * @param type <code>int</code> type for the attribute.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
511 * @return <code>Attribute</code> - this Attribute modified.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
512 * @throws IllegalDataException if the given attribute type is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
513 * not one of the supported types.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
514 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
515 public Attribute setAttributeType(final int type) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
516 if ((type < UNDECLARED_TYPE) || (type > ENUMERATED_TYPE)) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
517 throw new IllegalDataException(String.valueOf(type),
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
518 "attribute", "Illegal attribute type");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
519 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
520 this.type = type;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
521 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
522 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
523
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
524 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
525 * This returns a <code>String</code> representation of the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
526 * <code>Attribute</code>, suitable for debugging.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
527 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
528 * @return <code>String</code> - information about the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
529 * <code>Attribute</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
530 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
531 public String toString() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
532 return new StringBuffer()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
533 .append("[Attribute: ")
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
534 .append(getQualifiedName())
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
535 .append("=\"")
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
536 .append(value)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
537 .append("\"")
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
538 .append("]")
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
539 .toString();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
540 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
541
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
542 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
543 * This tests for equality of this <code>Attribute</code> to the supplied
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
544 * <code>Object</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
545 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
546 * @param ob <code>Object</code> to compare to.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
547 * @return <code>boolean</code> - whether the <code>Attribute</code> is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
548 * equal to the supplied <code>Object</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
549 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
550 public final boolean equals(final Object ob) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
551 return (ob == this);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
552 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
553
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
554 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
555 * This returns the hash code for this <code>Attribute</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
556 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
557 * @return <code>int</code> - hash code.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
558 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
559 public final int hashCode() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
560 return super.hashCode();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
561 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
562
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
563 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
564 * This will return a clone of this <code>Attribute</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
565 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
566 * @return <code>Object</code> - clone of this <code>Attribute</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
567 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
568 public Object clone() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
569 Attribute attribute = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
570 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
571 attribute = (Attribute) super.clone();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
572 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
573 catch (final CloneNotSupportedException ignore) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
574 // Won't happen
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
575 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
576
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
577 // Name, namespace, and value are references to imutable objects
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
578 // and are copied by super.clone() (aka Object.clone())
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
579
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
580 // super.clone() copies reference to set parent to null
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
581 attribute.parent = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
582 return attribute;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
583 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
584
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
585 /////////////////////////////////////////////////////////////////
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
586 // Convenience Methods below here
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
587 /////////////////////////////////////////////////////////////////
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
588
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
589 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
590 * This gets the value of the attribute, in
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
591 * <code>int</code> form, and if no conversion
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
592 * can occur, throws a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
593 * <code>{@link DataConversionException}</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
594 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
595 * @return <code>int</code> value of attribute.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
596 * @throws DataConversionException when conversion fails.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
597 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
598 public int getIntValue() throws DataConversionException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
599 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
600 return Integer.parseInt(value.trim());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
601 } catch (final NumberFormatException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
602 throw new DataConversionException(name, "int");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
603 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
604 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
605
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
606 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
607 * This gets the value of the attribute, in
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
608 * <code>long</code> form, and if no conversion
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
609 * can occur, throws a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
610 * <code>{@link DataConversionException}</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
611 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
612 * @return <code>long</code> value of attribute.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
613 * @throws DataConversionException when conversion fails.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
614 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
615 public long getLongValue() throws DataConversionException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
616 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
617 return Long.parseLong(value.trim());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
618 } catch (final NumberFormatException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
619 throw new DataConversionException(name, "long");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
620 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
621 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
622
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
623 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
624 * This gets the value of the attribute, in
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
625 * <code>float</code> form, and if no conversion
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
626 * can occur, throws a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
627 * <code>{@link DataConversionException}</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
628 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
629 * @return <code>float</code> value of attribute.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
630 * @throws DataConversionException when conversion fails.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
631 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
632 public float getFloatValue() throws DataConversionException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
633 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
634 // Avoid Float.parseFloat() to support JDK 1.1
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
635 return Float.valueOf(value.trim()).floatValue();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
636 } catch (final NumberFormatException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
637 throw new DataConversionException(name, "float");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
638 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
639 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
640
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
641 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
642 * This gets the value of the attribute, in
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
643 * <code>double</code> form, and if no conversion
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
644 * can occur, throws a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
645 * <code>{@link DataConversionException}</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
646 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
647 * @return <code>double</code> value of attribute.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
648 * @throws DataConversionException when conversion fails.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
649 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
650 public double getDoubleValue() throws DataConversionException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
651 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
652 // Avoid Double.parseDouble() to support JDK 1.1
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
653 return Double.valueOf(value.trim()).doubleValue();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
654 } catch (final NumberFormatException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
655 // Specially handle INF and -INF that Double.valueOf doesn't do
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
656 String v = value.trim();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
657 if ("INF".equals(v)) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
658 return Double.POSITIVE_INFINITY;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
659 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
660 if ("-INF".equals(v)) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
661 return Double.NEGATIVE_INFINITY;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
662 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
663 throw new DataConversionException(name, "double");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
664 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
665 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
666
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
667 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
668 * This gets the effective boolean value of the attribute, or throws a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
669 * <code>{@link DataConversionException}</code> if a conversion can't be
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
670 * performed. True values are: "true", "on", "1", and "yes". False
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
671 * values are: "false", "off", "0", and "no". Values are trimmed before
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
672 * comparison. Values other than those listed here throw the exception.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
673 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
674 * @return <code>boolean</code> value of attribute.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
675 * @throws DataConversionException when conversion fails.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
676 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
677 public boolean getBooleanValue() throws DataConversionException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
678 final String valueTrim = value.trim();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
679 if (
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
680 (valueTrim.equalsIgnoreCase("true")) ||
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
681 (valueTrim.equalsIgnoreCase("on")) ||
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
682 (valueTrim.equalsIgnoreCase("1")) ||
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
683 (valueTrim.equalsIgnoreCase("yes"))) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
684 return true;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
685 } else if (
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
686 (valueTrim.equalsIgnoreCase("false")) ||
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
687 (valueTrim.equalsIgnoreCase("off")) ||
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
688 (valueTrim.equalsIgnoreCase("0")) ||
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
689 (valueTrim.equalsIgnoreCase("no"))
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
690 ) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
691 return false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
692 } else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
693 throw new DataConversionException(name, "boolean");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
694 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
695 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
696
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
697 // Support a custom Namespace serialization so no two namespace
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
698 // object instances may exist for the same prefix/uri pair
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
699 private void writeObject(final ObjectOutputStream out) throws IOException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
700
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
701 out.defaultWriteObject();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
702
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
703 // We use writeObject() and not writeUTF() to minimize space
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
704 // This allows for writing pointers to already written strings
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
705 out.writeObject(namespace.getPrefix());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
706 out.writeObject(namespace.getURI());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
707 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
708
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
709 private void readObject(final ObjectInputStream in)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
710 throws IOException, ClassNotFoundException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
711
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
712 in.defaultReadObject();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
713
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
714 namespace = Namespace.getNamespace(
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
715 (String) in.readObject(), (String) in.readObject());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
716 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
717 }