1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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.1 $, $Date: 2004/02/02 18:50:16 $, $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
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 }