View Javadoc

1   /*
2    * Copyright (C) 2003-2006 Christian Siefkes <christian@siefkes.net>.
3    * Development of this software is supported by the German Research Society,
4    * Berlin-Brandenburg Graduate School in Distributed Information Systems
5    * (DFG grant no. GRK 316).
6    *
7    * This program is free software; you can redistribute it and/or modify
8    * it under the terms of the GNU General Public License as published by
9    * the Free Software Foundation; either version 2 of the License, or
10   * (at your option) any later version.
11   *
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with this program; if not, visit
19   * http://www.gnu.org/licenses/gpl.html or write to the Free Software
20   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21   */
22  package de.fu_berlin.ties.xml;
23  
24  import org.apache.commons.lang.builder.ToStringBuilder;
25  
26  /***
27   * A constituent in an XML document that is not a tag. An instance of this class
28   * represents a document or markup declaration, XML prolog, processing
29   * instruction, comment, CDATA section, textual content or outer whitespace.
30   *
31   * @author Christian Siefkes
32   * @version $Revision: 1.4 $, $Date: 2006/10/21 16:04:29 $, $Author: siefkes $
33   */
34  public class OtherConstituent extends XMLConstituent {
35  
36      /***
37       * Type constant: a document type declaration.
38       */
39      public static final short DOCTYPE = 3;
40  
41      /***
42       * Type constant: the XML prolog.
43       */
44      public static final short XML_PROLOG = 4;
45  
46      /***
47       * Type constant: a processing instruction.
48       */
49      public static final short PI = 5;
50  
51      /***
52       * Type constant: a comment.
53       */
54      public static final short COMMENT = 6;
55  
56      /***
57       * Type constant: a CDATA section.
58       */
59      public static final short CDATA_SECTION = 7;
60  
61      /***
62       * Type constant: textual content. Textual content is trimmed, preceding
63       * and trailing whitespace are stored as {@link #OUTER_WHITESPACE}
64       * constituents.
65       */
66      public static final short TEXT = 8;
67  
68      /***
69       * Type constant: Whitespace between elements.
70       */
71      public static final short OUTER_WHITESPACE = 9;
72  
73      /***
74       * Creates a new instance, without setting a reference to a next
75       * constituent.
76       *
77       * @param constType the typ of this constituent (must be one of the static
78       * type constants defined in this class)
79       * @param rep the representation of this constituent within the XML
80       * document, i.e. the string fragment from the document representing this
81       * constituent
82       * @throws IllegalArgumentException if <code>constType</code> differs from
83       * the static type constants defined in this class
84       */
85      public OtherConstituent(final short constType, final String rep)
86              throws IllegalArgumentException {
87          this(constType, rep, null, null);
88      }
89  
90      /***
91       * Creates a new instance.
92       *
93       * @param constType the typ of this constituent (must be one of the static
94       * type constants defined in this class)
95       * @param rep the representation of this constituent within the XML
96       * document, i.e. the string fragment from the document representing this
97       * constituent
98       * @param prevEntry a reference to the next constituent
99       * @param nextEntry a reference to the next constituent
100      * @throws IllegalArgumentException if <code>constType</code> differs from
101      * the static type constants defined in this class
102      */
103     public OtherConstituent(final short constType, final String rep,
104             final XMLConstituent prevEntry,
105             final XMLConstituent nextEntry)
106             throws IllegalArgumentException {
107         super(constType, rep, prevEntry, nextEntry);
108 
109         // ensure range of type constant
110         if ((constType < DOCTYPE) || (constType > OUTER_WHITESPACE)) {
111             throw new IllegalArgumentException("Specified tag type must "
112                 + "be one of the static type constants defined in "
113                 + "TagConstituent, but it is " + constType);
114         }
115     }
116 
117     /***
118      * Returns a string representation of this object.
119      *
120      * @return a textual representation
121      */
122     public String toString() {
123         return new ToStringBuilder(this).
124             appendSuper(super.toString()).
125             toString();
126     }
127 
128 }