Desktop tool for browsing account info from EVE-Online
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Attribute.java 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. /*--
  2. $Id: Attribute.java,v 1.56 2007/11/10 05:28:58 jhunter Exp $
  3. Copyright (C) 2000-2007 Jason Hunter & Brett McLaughlin.
  4. All rights reserved.
  5. Redistribution and use in source and binary forms, with or without
  6. modification, are permitted provided that the following conditions
  7. are met:
  8. 1. Redistributions of source code must retain the above copyright
  9. notice, this list of conditions, and the following disclaimer.
  10. 2. Redistributions in binary form must reproduce the above copyright
  11. notice, this list of conditions, and the disclaimer that follows
  12. these conditions in the documentation and/or other materials
  13. provided with the distribution.
  14. 3. The name "JDOM" must not be used to endorse or promote products
  15. derived from this software without prior written permission. For
  16. written permission, please contact <request_AT_jdom_DOT_org>.
  17. 4. Products derived from this software may not be called "JDOM", nor
  18. may "JDOM" appear in their name, without prior written permission
  19. from the JDOM Project Management <request_AT_jdom_DOT_org>.
  20. In addition, we request (but do not require) that you include in the
  21. end-user documentation provided with the redistribution and/or in the
  22. software itself an acknowledgement equivalent to the following:
  23. "This product includes software developed by the
  24. JDOM Project (http://www.jdom.org/)."
  25. Alternatively, the acknowledgment may be graphical using the logos
  26. available at http://www.jdom.org/images/logos.
  27. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  28. WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  29. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  30. DISCLAIMED. IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
  31. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  32. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  33. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  34. USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  35. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  36. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  38. SUCH DAMAGE.
  39. This software consists of voluntary contributions made by many
  40. individuals on behalf of the JDOM Project and was originally
  41. created by Jason Hunter <jhunter_AT_jdom_DOT_org> and
  42. Brett McLaughlin <brett_AT_jdom_DOT_org>. For more information
  43. on the JDOM Project, please see <http://www.jdom.org/>.
  44. */
  45. package org.jdom;
  46. import java.io.*;
  47. /**
  48. * An XML attribute. Methods allow the user to obtain the value of the attribute
  49. * as well as namespace and type information.
  50. *
  51. * @version $Revision: 1.56 $, $Date: 2007/11/10 05:28:58 $
  52. * @author Brett McLaughlin
  53. * @author Jason Hunter
  54. * @author Elliotte Rusty Harold
  55. * @author Wesley Biggs
  56. * @author Victor Toni
  57. */
  58. public class Attribute implements Serializable, Cloneable {
  59. private static final String CVS_ID =
  60. "@(#) $RCSfile: Attribute.java,v $ $Revision: 1.56 $ $Date: 2007/11/10 05:28:58 $ $Name: jdom_1_1 $";
  61. /**
  62. * Attribute type: the attribute has not been declared or type
  63. * is unknown.
  64. *
  65. * @see #getAttributeType
  66. */
  67. public final static int UNDECLARED_TYPE = 0;
  68. /**
  69. * Attribute type: the attribute value is a string.
  70. *
  71. * @see #getAttributeType
  72. */
  73. public final static int CDATA_TYPE = 1;
  74. /**
  75. * Attribute type: the attribute value is a unique identifier.
  76. *
  77. * @see #getAttributeType
  78. */
  79. public final static int ID_TYPE = 2;
  80. /**
  81. * Attribute type: the attribute value is a reference to a
  82. * unique identifier.
  83. *
  84. * @see #getAttributeType
  85. */
  86. public final static int IDREF_TYPE = 3;
  87. /**
  88. * Attribute type: the attribute value is a list of references to
  89. * unique identifiers.
  90. *
  91. * @see #getAttributeType
  92. */
  93. public final static int IDREFS_TYPE = 4;
  94. /**
  95. * Attribute type: the attribute value is the name of an entity.
  96. *
  97. * @see #getAttributeType
  98. */
  99. public final static int ENTITY_TYPE = 5;
  100. /**
  101. * <p>
  102. * Attribute type: the attribute value is a list of entity names.
  103. * </p>
  104. *
  105. * @see #getAttributeType
  106. */
  107. public final static int ENTITIES_TYPE = 6;
  108. /**
  109. * Attribute type: the attribute value is a name token.
  110. * <p>
  111. * According to SAX 2.0 specification, attributes of enumerated
  112. * types should be reported as "NMTOKEN" by SAX parsers. But the
  113. * major parsers (Xerces and Crimson) provide specific values
  114. * that permit to recognize them as {@link #ENUMERATED_TYPE}.
  115. *
  116. * @see #getAttributeType
  117. */
  118. public final static int NMTOKEN_TYPE = 7;
  119. /**
  120. * Attribute type: the attribute value is a list of name tokens.
  121. *
  122. * @see #getAttributeType
  123. */
  124. public final static int NMTOKENS_TYPE = 8;
  125. /**
  126. * Attribute type: the attribute value is the name of a notation.
  127. *
  128. * @see #getAttributeType
  129. */
  130. public final static int NOTATION_TYPE = 9;
  131. /**
  132. * Attribute type: the attribute value is a name token from an
  133. * enumeration.
  134. *
  135. * @see #getAttributeType
  136. */
  137. public final static int ENUMERATED_TYPE = 10;
  138. // Keep the old constant names for one beta cycle to help migration
  139. /** The local name of the <code>Attribute</code> */
  140. protected String name;
  141. /** The <code>{@link Namespace}</code> of the <code>Attribute</code> */
  142. protected transient Namespace namespace;
  143. /** The value of the <code>Attribute</code> */
  144. protected String value;
  145. /** The type of the <code>Attribute</code> */
  146. protected int type = UNDECLARED_TYPE;
  147. /** Parent element, or null if none */
  148. protected Element parent;
  149. /**
  150. * Default, no-args constructor for implementations to use if needed.
  151. */
  152. protected Attribute() {}
  153. /**
  154. * This will create a new <code>Attribute</code> with the
  155. * specified (local) name and value, and in the provided
  156. * <code>{@link Namespace}</code>.
  157. *
  158. * @param name <code>String</code> name of <code>Attribute</code>.
  159. * @param value <code>String</code> value for new attribute.
  160. * @param namespace <code>Namespace</code> namespace for new attribute.
  161. * @throws IllegalNameException if the given name is illegal as an
  162. * attribute name or if if the new namespace is the default
  163. * namespace. Attributes cannot be in a default namespace.
  164. * @throws IllegalDataException if the given attribute value is
  165. * illegal character data (as determined by
  166. * {@link org.jdom.Verifier#checkCharacterData}).
  167. */
  168. public Attribute(final String name, final String value, final Namespace namespace) {
  169. this(name, value, UNDECLARED_TYPE, namespace);
  170. }
  171. /**
  172. * This will create a new <code>Attribute</code> with the
  173. * specified (local) name, value, and type, and in the provided
  174. * <code>{@link Namespace}</code>.
  175. *
  176. * @param name <code>String</code> name of <code>Attribute</code>.
  177. * @param value <code>String</code> value for new attribute.
  178. * @param type <code>int</code> type for new attribute.
  179. * @param namespace <code>Namespace</code> namespace for new attribute.
  180. * @throws IllegalNameException if the given name is illegal as an
  181. * attribute name or if if the new namespace is the default
  182. * namespace. Attributes cannot be in a default namespace.
  183. * @throws IllegalDataException if the given attribute value is
  184. * illegal character data (as determined by
  185. * {@link org.jdom.Verifier#checkCharacterData}) or
  186. * if the given attribute type is not one of the
  187. * supported types.
  188. */
  189. public Attribute(final String name, final String value, final int type, final Namespace namespace) {
  190. setName(name);
  191. setValue(value);
  192. setAttributeType(type);
  193. setNamespace(namespace);
  194. }
  195. /**
  196. * This will create a new <code>Attribute</code> with the
  197. * specified (local) name and value, and does not place
  198. * the attribute in a <code>{@link Namespace}</code>.
  199. * <p>
  200. * <b>Note</b>: This actually explicitly puts the
  201. * <code>Attribute</code> in the "empty" <code>Namespace</code>
  202. * (<code>{@link Namespace#NO_NAMESPACE}</code>).
  203. *
  204. * @param name <code>String</code> name of <code>Attribute</code>.
  205. * @param value <code>String</code> value for new attribute.
  206. * @throws IllegalNameException if the given name is illegal as an
  207. * attribute name.
  208. * @throws IllegalDataException if the given attribute value is
  209. * illegal character data (as determined by
  210. * {@link org.jdom.Verifier#checkCharacterData}).
  211. */
  212. public Attribute(final String name, final String value) {
  213. this(name, value, UNDECLARED_TYPE, Namespace.NO_NAMESPACE);
  214. }
  215. /**
  216. * This will create a new <code>Attribute</code> with the
  217. * specified (local) name, value and type, and does not place
  218. * the attribute in a <code>{@link Namespace}</code>.
  219. * <p>
  220. * <b>Note</b>: This actually explicitly puts the
  221. * <code>Attribute</code> in the "empty" <code>Namespace</code>
  222. * (<code>{@link Namespace#NO_NAMESPACE}</code>).
  223. *
  224. * @param name <code>String</code> name of <code>Attribute</code>.
  225. * @param value <code>String</code> value for new attribute.
  226. * @param type <code>int</code> type for new attribute.
  227. * @throws IllegalNameException if the given name is illegal as an
  228. * attribute name.
  229. * @throws IllegalDataException if the given attribute value is
  230. * illegal character data (as determined by
  231. * {@link org.jdom.Verifier#checkCharacterData}) or
  232. * if the given attribute type is not one of the
  233. * supported types.
  234. */
  235. public Attribute(final String name, final String value, final int type) {
  236. this(name, value, type, Namespace.NO_NAMESPACE);
  237. }
  238. /**
  239. * This will return the parent of this <code>Attribute</code>.
  240. * If there is no parent, then this returns <code>null</code>.
  241. *
  242. * @return parent of this <code>Attribute</code>
  243. */
  244. public Element getParent() {
  245. return parent;
  246. }
  247. /**
  248. * This retrieves the owning <code>{@link Document}</code> for
  249. * this Attribute, or null if not a currently a member of a
  250. * <code>{@link Document}</code>.
  251. *
  252. * @return <code>Document</code> owning this Attribute, or null.
  253. */
  254. public Document getDocument() {
  255. final Element parentElement = getParent();
  256. if (parentElement != null) {
  257. return parentElement.getDocument();
  258. }
  259. return null;
  260. }
  261. /**
  262. * This will set the parent of this <code>Attribute</code>.
  263. *
  264. * @param parent <code>Element</code> to be new parent.
  265. * @return this <code>Attribute</code> modified.
  266. */
  267. protected Attribute setParent(final Element parent) {
  268. this.parent = parent;
  269. return this;
  270. }
  271. /**
  272. * This detaches the <code>Attribute</code> from its parent, or does
  273. * nothing if the <code>Attribute</code> has no parent.
  274. *
  275. * @return <code>Attribute</code> - this <code>Attribute</code> modified.
  276. */
  277. public Attribute detach() {
  278. final Element parentElement = getParent();
  279. if (parentElement != null) {
  280. parentElement.removeAttribute(getName(),getNamespace());
  281. }
  282. return this;
  283. }
  284. /**
  285. * This will retrieve the local name of the
  286. * <code>Attribute</code>. For any XML attribute
  287. * which appears as
  288. * <code>[namespacePrefix]:[attributeName]</code>,
  289. * the local name of the attribute would be
  290. * <code>[attributeName]</code>. When the attribute
  291. * has no namespace, the local name is simply the attribute
  292. * name.
  293. * <p>
  294. * To obtain the namespace prefix for this
  295. * attribute, the
  296. * <code>{@link #getNamespacePrefix()}</code>
  297. * method should be used.
  298. *
  299. * @return <code>String</code> - name of this attribute,
  300. * without any namespace prefix.
  301. */
  302. public String getName() {
  303. return name;
  304. }
  305. /**
  306. * This sets the local name of the <code>Attribute</code>.
  307. *
  308. * @param name the new local name to set
  309. * @return <code>Attribute</code> - the attribute modified.
  310. * @throws IllegalNameException if the given name is illegal as an
  311. * attribute name.
  312. */
  313. public Attribute setName(final String name) {
  314. final String reason = Verifier.checkAttributeName(name);
  315. if (reason != null) {
  316. throw new IllegalNameException(name, "attribute", reason);
  317. }
  318. this.name = name;
  319. return this;
  320. }
  321. /**
  322. * This will retrieve the qualified name of the <code>Attribute</code>.
  323. * For any XML attribute whose name is
  324. * <code>[namespacePrefix]:[elementName]</code>,
  325. * the qualified name of the attribute would be
  326. * everything (both namespace prefix and
  327. * element name). When the attribute has no
  328. * namespace, the qualified name is simply the attribute's
  329. * local name.
  330. * <p>
  331. * To obtain the local name of the attribute, the
  332. * <code>{@link #getName()}</code> method should be used.
  333. * <p>
  334. * To obtain the namespace prefix for this attribute,
  335. * the <code>{@link #getNamespacePrefix()}</code>
  336. * method should be used.
  337. *
  338. * @return <code>String</code> - full name for this element.
  339. */
  340. public String getQualifiedName() {
  341. // Note: Any changes here should be reflected in
  342. // XMLOutputter.printQualifiedName()
  343. final String prefix = namespace.getPrefix();
  344. // no prefix found
  345. if ((prefix == null) || ("".equals(prefix))) {
  346. return getName();
  347. } else {
  348. return new StringBuffer(prefix)
  349. .append(':')
  350. .append(getName())
  351. .toString();
  352. }
  353. }
  354. /**
  355. * This will retrieve the namespace prefix of the
  356. * <code>Attribute</code>. For any XML attribute
  357. * which appears as
  358. * <code>[namespacePrefix]:[attributeName]</code>,
  359. * the namespace prefix of the attribute would be
  360. * <code>[namespacePrefix]</code>. When the attribute
  361. * has no namespace, an empty <code>String</code> is returned.
  362. *
  363. * @return <code>String</code> - namespace prefix of this
  364. * attribute.
  365. */
  366. public String getNamespacePrefix() {
  367. return namespace.getPrefix();
  368. }
  369. /**
  370. * This returns the URI mapped to this <code>Attribute</code>'s
  371. * prefix. If no mapping is found, an empty <code>String</code> is
  372. * returned.
  373. *
  374. * @return <code>String</code> - namespace URI for this <code>Attribute</code>.
  375. */
  376. public String getNamespaceURI() {
  377. return namespace.getURI();
  378. }
  379. /**
  380. * This will return this <code>Attribute</code>'s
  381. * <code>{@link Namespace}</code>.
  382. *
  383. * @return <code>Namespace</code> - Namespace object for this <code>Attribute</code>
  384. */
  385. public Namespace getNamespace() {
  386. return namespace;
  387. }
  388. /**
  389. * This sets this <code>Attribute</code>'s <code>{@link Namespace}</code>.
  390. * If the provided namespace is null, the attribute will have no namespace.
  391. * The namespace must have a prefix.
  392. *
  393. * @param namespace the new namespace
  394. * @return <code>Element</code> - the element modified.
  395. * @throws IllegalNameException if the new namespace is the default
  396. * namespace. Attributes cannot be in a default namespace.
  397. */
  398. public Attribute setNamespace(Namespace namespace) {
  399. if (namespace == null) {
  400. namespace = Namespace.NO_NAMESPACE;
  401. }
  402. // Verify the attribute isn't trying to be in a default namespace
  403. // Attributes can't be in a default namespace
  404. if (namespace != Namespace.NO_NAMESPACE &&
  405. "".equals(namespace.getPrefix())) {
  406. throw new IllegalNameException("", "attribute namespace",
  407. "An attribute namespace without a prefix can only be the " +
  408. "NO_NAMESPACE namespace");
  409. }
  410. this.namespace = namespace;
  411. return this;
  412. }
  413. /**
  414. * This will return the actual textual value of this
  415. * <code>Attribute</code>. This will include all text
  416. * within the quotation marks.
  417. *
  418. * @return <code>String</code> - value for this attribute.
  419. */
  420. public String getValue() {
  421. return value;
  422. }
  423. /**
  424. * This will set the value of the <code>Attribute</code>.
  425. *
  426. * @param value <code>String</code> value for the attribute.
  427. * @return <code>Attribute</code> - this Attribute modified.
  428. * @throws IllegalDataException if the given attribute value is
  429. * illegal character data (as determined by
  430. * {@link org.jdom.Verifier#checkCharacterData}).
  431. */
  432. public Attribute setValue(final String value) {
  433. final String reason = Verifier.checkCharacterData(value);
  434. if (reason != null) {
  435. throw new IllegalDataException(value, "attribute", reason);
  436. }
  437. this.value = value;
  438. return this;
  439. }
  440. /**
  441. * This will return the actual declared type of this
  442. * <code>Attribute</code>.
  443. *
  444. * @return <code>int</code> - type for this attribute.
  445. */
  446. public int getAttributeType() {
  447. return type;
  448. }
  449. /**
  450. * This will set the type of the <code>Attribute</code>.
  451. *
  452. * @param type <code>int</code> type for the attribute.
  453. * @return <code>Attribute</code> - this Attribute modified.
  454. * @throws IllegalDataException if the given attribute type is
  455. * not one of the supported types.
  456. */
  457. public Attribute setAttributeType(final int type) {
  458. if ((type < UNDECLARED_TYPE) || (type > ENUMERATED_TYPE)) {
  459. throw new IllegalDataException(String.valueOf(type),
  460. "attribute", "Illegal attribute type");
  461. }
  462. this.type = type;
  463. return this;
  464. }
  465. /**
  466. * This returns a <code>String</code> representation of the
  467. * <code>Attribute</code>, suitable for debugging.
  468. *
  469. * @return <code>String</code> - information about the
  470. * <code>Attribute</code>
  471. */
  472. public String toString() {
  473. return new StringBuffer()
  474. .append("[Attribute: ")
  475. .append(getQualifiedName())
  476. .append("=\"")
  477. .append(value)
  478. .append("\"")
  479. .append("]")
  480. .toString();
  481. }
  482. /**
  483. * This tests for equality of this <code>Attribute</code> to the supplied
  484. * <code>Object</code>.
  485. *
  486. * @param ob <code>Object</code> to compare to.
  487. * @return <code>boolean</code> - whether the <code>Attribute</code> is
  488. * equal to the supplied <code>Object</code>.
  489. */
  490. public final boolean equals(final Object ob) {
  491. return (ob == this);
  492. }
  493. /**
  494. * This returns the hash code for this <code>Attribute</code>.
  495. *
  496. * @return <code>int</code> - hash code.
  497. */
  498. public final int hashCode() {
  499. return super.hashCode();
  500. }
  501. /**
  502. * This will return a clone of this <code>Attribute</code>.
  503. *
  504. * @return <code>Object</code> - clone of this <code>Attribute</code>.
  505. */
  506. public Object clone() {
  507. Attribute attribute = null;
  508. try {
  509. attribute = (Attribute) super.clone();
  510. }
  511. catch (final CloneNotSupportedException ignore) {
  512. // Won't happen
  513. }
  514. // Name, namespace, and value are references to imutable objects
  515. // and are copied by super.clone() (aka Object.clone())
  516. // super.clone() copies reference to set parent to null
  517. attribute.parent = null;
  518. return attribute;
  519. }
  520. /////////////////////////////////////////////////////////////////
  521. // Convenience Methods below here
  522. /////////////////////////////////////////////////////////////////
  523. /**
  524. * This gets the value of the attribute, in
  525. * <code>int</code> form, and if no conversion
  526. * can occur, throws a
  527. * <code>{@link DataConversionException}</code>
  528. *
  529. * @return <code>int</code> value of attribute.
  530. * @throws DataConversionException when conversion fails.
  531. */
  532. public int getIntValue() throws DataConversionException {
  533. try {
  534. return Integer.parseInt(value.trim());
  535. } catch (final NumberFormatException e) {
  536. throw new DataConversionException(name, "int");
  537. }
  538. }
  539. /**
  540. * This gets the value of the attribute, in
  541. * <code>long</code> form, and if no conversion
  542. * can occur, throws a
  543. * <code>{@link DataConversionException}</code>
  544. *
  545. * @return <code>long</code> value of attribute.
  546. * @throws DataConversionException when conversion fails.
  547. */
  548. public long getLongValue() throws DataConversionException {
  549. try {
  550. return Long.parseLong(value.trim());
  551. } catch (final NumberFormatException e) {
  552. throw new DataConversionException(name, "long");
  553. }
  554. }
  555. /**
  556. * This gets the value of the attribute, in
  557. * <code>float</code> form, and if no conversion
  558. * can occur, throws a
  559. * <code>{@link DataConversionException}</code>
  560. *
  561. * @return <code>float</code> value of attribute.
  562. * @throws DataConversionException when conversion fails.
  563. */
  564. public float getFloatValue() throws DataConversionException {
  565. try {
  566. // Avoid Float.parseFloat() to support JDK 1.1
  567. return Float.valueOf(value.trim()).floatValue();
  568. } catch (final NumberFormatException e) {
  569. throw new DataConversionException(name, "float");
  570. }
  571. }
  572. /**
  573. * This gets the value of the attribute, in
  574. * <code>double</code> form, and if no conversion
  575. * can occur, throws a
  576. * <code>{@link DataConversionException}</code>
  577. *
  578. * @return <code>double</code> value of attribute.
  579. * @throws DataConversionException when conversion fails.
  580. */
  581. public double getDoubleValue() throws DataConversionException {
  582. try {
  583. // Avoid Double.parseDouble() to support JDK 1.1
  584. return Double.valueOf(value.trim()).doubleValue();
  585. } catch (final NumberFormatException e) {
  586. // Specially handle INF and -INF that Double.valueOf doesn't do
  587. String v = value.trim();
  588. if ("INF".equals(v)) {
  589. return Double.POSITIVE_INFINITY;
  590. }
  591. if ("-INF".equals(v)) {
  592. return Double.NEGATIVE_INFINITY;
  593. }
  594. throw new DataConversionException(name, "double");
  595. }
  596. }
  597. /**
  598. * This gets the effective boolean value of the attribute, or throws a
  599. * <code>{@link DataConversionException}</code> if a conversion can't be
  600. * performed. True values are: "true", "on", "1", and "yes". False
  601. * values are: "false", "off", "0", and "no". Values are trimmed before
  602. * comparison. Values other than those listed here throw the exception.
  603. *
  604. * @return <code>boolean</code> value of attribute.
  605. * @throws DataConversionException when conversion fails.
  606. */
  607. public boolean getBooleanValue() throws DataConversionException {
  608. final String valueTrim = value.trim();
  609. if (
  610. (valueTrim.equalsIgnoreCase("true")) ||
  611. (valueTrim.equalsIgnoreCase("on")) ||
  612. (valueTrim.equalsIgnoreCase("1")) ||
  613. (valueTrim.equalsIgnoreCase("yes"))) {
  614. return true;
  615. } else if (
  616. (valueTrim.equalsIgnoreCase("false")) ||
  617. (valueTrim.equalsIgnoreCase("off")) ||
  618. (valueTrim.equalsIgnoreCase("0")) ||
  619. (valueTrim.equalsIgnoreCase("no"))
  620. ) {
  621. return false;
  622. } else {
  623. throw new DataConversionException(name, "boolean");
  624. }
  625. }
  626. // Support a custom Namespace serialization so no two namespace
  627. // object instances may exist for the same prefix/uri pair
  628. private void writeObject(final ObjectOutputStream out) throws IOException {
  629. out.defaultWriteObject();
  630. // We use writeObject() and not writeUTF() to minimize space
  631. // This allows for writing pointers to already written strings
  632. out.writeObject(namespace.getPrefix());
  633. out.writeObject(namespace.getURI());
  634. }
  635. private void readObject(final ObjectInputStream in)
  636. throws IOException, ClassNotFoundException {
  637. in.defaultReadObject();
  638. namespace = Namespace.getNamespace(
  639. (String) in.readObject(), (String) in.readObject());
  640. }
  641. }