View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript-XML: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2005 Kevin Rogers
4   //
5   // This file is part of MillScript-XML.
6   //
7   // MillScript-XML is free software; you can redistribute it and/or modify it under
8   // the terms of the GNU General Public License as published by the Free
9   // Software Foundation; either version 2 of the License, or (at your option)
10  // any later version.
11  //
12  // MillScript-XML is distributed in the hope that it will be useful, but WITHOUT
13  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  // more details.
16  //
17  // You should have received a copy of the GNU General Public License along with
18  // MillScript-XML; if not, write to the Free Software Foundation, Inc., 59 Temple
19  // Place, Suite 330, Boston, MA  02111-1307  USA
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 }