1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.millscript.commons.xml.tokenizer.wellformed;
22
23 import org.millscript.commons.xml.alerts.XmlWellFormednessAlert;
24 import org.millscript.commons.xml.api.token.AttListDeclToken;
25 import org.millscript.commons.xml.api.token.ElementDeclToken;
26 import org.millscript.commons.xml.api.token.EntityDeclToken;
27 import org.millscript.commons.xml.api.token.NotationDeclToken;
28 import org.millscript.commons.xml.api.token.TokenVisitor;
29 import org.millscript.commons.xml.api.token.XmlDeclToken;
30
31 /**
32 * The abstract <code>TokenVisitor</code> implementation that forms a common
33 * parent for all our other well-formedness token visitor implementations,
34 * providing some default error messages and required common variables.
35 */
36 public abstract class AbsTokenVisitor implements TokenVisitor {
37
38 /**
39 * The next token visitor in our well-formedness chain.
40 */
41 final TokenVisitor nextTokenVisitor;
42
43 /**
44 * The well-formedness XML tokenizer our tokens come from.
45 */
46 final WellFormedXmlTokenizer wellFormed;
47
48 /**
49 * Constructs a new token visitor, with the specified tokenizer and
50 * next-in-the-chain token visitor.
51 *
52 * @param xt the well-formed XML tokenizer our tokens come from
53 * @param ntv the next token visitor in the well-formedness chain
54 */
55 AbsTokenVisitor( final WellFormedXmlTokenizer xt, final TokenVisitor ntv ) {
56 this.nextTokenVisitor = ntv;
57 this.wellFormed = xt;
58 }
59
60 /**
61 * @see org.millscript.commons.xml.api.token.TokenVisitor#visit(org.millscript.commons.xml.api.token.AttListDeclToken)
62 */
63 public void visit( final AttListDeclToken token ) {
64 throw new XmlWellFormednessAlert(
65 "Attribte list declaration is not valid outside a document type declaration"
66 ).decorate( token ).mishap();
67 }
68
69 /**
70 * @see org.millscript.commons.xml.api.token.TokenVisitor#visit(org.millscript.commons.xml.api.token.ElementDeclToken)
71 */
72 public void visit( final ElementDeclToken token ) {
73 throw new XmlWellFormednessAlert(
74 "Element declaration is not valid outside a document type declaration"
75 ).decorate( token ).mishap();
76 }
77
78 /**
79 * @see org.millscript.commons.xml.api.token.TokenVisitor#visit(org.millscript.commons.xml.api.token.EntityDeclToken)
80 */
81 public void visit( final EntityDeclToken token ) {
82 throw new XmlWellFormednessAlert(
83 "Entity declaration is not valid outside a document type declaration"
84 ).decorate( token ).mishap();
85 }
86
87 /**
88 * @see org.millscript.commons.xml.api.token.TokenVisitor#visit(org.millscript.commons.xml.api.token.NotationDeclToken)
89 */
90 public void visit( final NotationDeclToken token ) {
91 throw new XmlWellFormednessAlert(
92 "Notation declaration is not valid outside a document type declaration"
93 ).decorate( token ).mishap();
94 }
95
96 /**
97 * @see org.millscript.commons.xml.api.token.TokenVisitor#visit(org.millscript.commons.xml.api.token.XmlDeclToken)
98 */
99 public void visit( final XmlDeclToken token ) {
100 throw new XmlWellFormednessAlert(
101 "XML declaration must appear as the first entity in a document"
102 ).decorate( token ).mishap();
103 }
104
105 }