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.

Content.java 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*--
  2. $Id: Content.java,v 1.6 2007/11/10 05:28:58 jhunter Exp $
  3. Copyright (C) 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. * Superclass for JDOM objects which can be legal child content
  49. * of {@link org.jdom.Parent} nodes.
  50. *
  51. * @see org.jdom.Comment
  52. * @see org.jdom.DocType
  53. * @see org.jdom.Element
  54. * @see org.jdom.EntityRef
  55. * @see org.jdom.Parent
  56. * @see org.jdom.ProcessingInstruction
  57. * @see org.jdom.Text
  58. *
  59. * @author Bradley S. Huffman
  60. * @author Jason Hunter
  61. * @version $Revision: 1.6 $, $Date: 2007/11/10 05:28:58 $
  62. */
  63. public abstract class Content implements Cloneable, Serializable {
  64. protected Parent parent = null;
  65. protected Content() {}
  66. /**
  67. * Detaches this child from its parent or does nothing if the child
  68. * has no parent.
  69. *
  70. * @return this child detached
  71. */
  72. public Content detach() {
  73. if (parent != null) {
  74. parent.removeContent(this);
  75. }
  76. return this;
  77. }
  78. /**
  79. * Return this child's parent, or null if this child is currently
  80. * not attached. The parent can be either an {@link Element}
  81. * or a {@link Document}.
  82. *
  83. * @return this child's parent or null if none
  84. */
  85. public Parent getParent() {
  86. return parent;
  87. }
  88. /**
  89. * A convenience method that returns any parent element for this element,
  90. * or null if the element is unattached or is a root element. This was the
  91. * original behavior of getParent() in JDOM Beta 9 which began returning
  92. * Parent in Beta 10. This method provides a convenient upgrade path for
  93. * JDOM Beta 10 and 1.0 users.
  94. *
  95. * @return the containing Element or null if unattached or a root element
  96. */
  97. public Element getParentElement() {
  98. Parent parent = getParent();
  99. return (Element) ((parent instanceof Element) ? parent : null);
  100. }
  101. /**
  102. * Sets the parent of this Content. The caller is responsible for removing
  103. * any pre-existing parentage.
  104. *
  105. * @param parent new parent element
  106. * @return the target element
  107. */
  108. protected Content setParent(Parent parent) {
  109. this.parent = parent;
  110. return this;
  111. }
  112. /**
  113. * Return this child's owning document or null if the branch containing
  114. * this child is currently not attached to a document.
  115. *
  116. * @return this child's owning document or null if none
  117. */
  118. public Document getDocument() {
  119. if (parent == null) return null;
  120. return parent.getDocument();
  121. }
  122. /**
  123. * Returns the XPath 1.0 string value of this child.
  124. *
  125. * @return xpath string value of this child.
  126. */
  127. public abstract String getValue();
  128. /**
  129. * Returns a deep, unattached copy of this child and its descendants
  130. * detached from any parent or document.
  131. *
  132. * @return a detached deep copy of this child and descendants
  133. */
  134. public Object clone() {
  135. try {
  136. Content c = (Content)super.clone();
  137. c.parent = null;
  138. return c;
  139. } catch (CloneNotSupportedException e) {
  140. //Can not happen ....
  141. //e.printStackTrace();
  142. return null;
  143. }
  144. }
  145. /**
  146. * This tests for equality of this Content object to the supplied object.
  147. * Content items are considered equal only if they are referentially equal
  148. * (i&#46;e&#46; the same object). User code may choose to compare objects
  149. * based on their properties instead.
  150. *
  151. * @param ob <code>Object</code> to compare to.
  152. * @return <code>boolean</code> - whether the <code>Content</code> is
  153. * equal to the supplied <code>Object</code>.
  154. */
  155. public final boolean equals(Object ob) {
  156. return (ob == this);
  157. }
  158. /**
  159. * This returns the hash code for this <code>Content</code> item.
  160. *
  161. * @return <code>int</code> - hash code.
  162. */
  163. public final int hashCode() {
  164. return super.hashCode();
  165. }
  166. }