View Javadoc

1   /*
2    wsmo4j - a WSMO API and Reference Implementation
3    Copyright (c) 2004-2005, OntoText Lab. / SIRMA
4    University of Innsbruck, Austria
5    This library is free software; you can redistribute it and/or modify it under
6    the terms of the GNU Lesser General Public License as published by the Free
7    Software Foundation; either version 2.1 of the License, or (at your option)
8    any later version.
9    This library is distributed in the hope that it will be useful, but WITHOUT
10   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   details.
13   You should have received a copy of the GNU Lesser General Public License along
14   with this library; if not, write to the Free Software Foundation, Inc.,
15   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16   */
17  
18  /**
19   * <p>Title: WSMO4J</p>
20   * <p>Description: WSMO API and a Reference Implementation</p>
21   * <p>Copyright:  Copyright (c) 2004-2005</p>
22   * <p>Company: OntoText Lab. / SIRMA </p>
23   */
24  
25  package org.wsmo.wsml;
26  
27  
28  /**
29   * This is a <b>checked</b> exception thrown when the stream being parsed
30   * contains syntax errors or is invalid w.r.t. the predefined grammar
31   *
32   * @author not attributable
33   * @version $Revision: 1156 $ $Date: 2005-10-17 17:57:00 +0300 (Mon, 17 Oct 2005) $
34   */
35  public class ParserException
36          extends Exception {
37      
38      //remember to change when updating class!
39      private static final long serialVersionUID = 4051040887066865975L;
40      
41      public static final String NO_NAMESPACE = "Parsing sQName, but could not find namespace defintion. ";
42      public static final String NAMESPACE_PREFIX_NOT_FOUND = "Parsing sQName, but could not find namespace defintion for prefix. ";
43      public static final String NOT_VALID_PARSETREE = "Could not parse WSML: ";
44      public static final String ANONYMOUS_ID_AS_ATOM = "Anonymous Id not allowed as identifier for Atom. ";
45      public static final String NB_ANONYMOUS_ID_AS_ATOM = "Numbered Anonymous Id not allowed as identifier for Atom. ";
46      public static final String VALUE_AS_ATOM = "Value not allowed as identifier of an atom. ";
47      public static final String FUNCTION_SYMBOL_AS_ATOM = "Function Symbol not allowed as identifier of an atom. ";
48      public static final String VARIABLE_AS_ATOM = "Variable not allowed as identifier of an atom. ";
49      public static final String WRONG_ARG_SIMPLE_DT = "Argument of a simple data value must be singular and of type wsml#string. ";
50  
51      private int line = -1;
52      private int pos = -1;
53      private String expectedToken = null;
54      private String foundToken = null;
55  
56      /**
57       * Creates a Parser Exception indicating a problem found when 
58       * processing an InputStream. 
59       *  
60       * @param msg message indicating the error that occured. Note
61       * that this class appends some exta information (if given) like the
62       * line and position of the error when "getMessage()" is called.
63       * 
64       * @param cause the initial cause of the error. In case the 
65       * problem is caused by the underlying parser (e.g. sableCC it
66       * will contain this Exception
67       */
68      public ParserException(String msg, Throwable cause) {
69          super(msg, cause);
70      }
71  
72      /**
73       * Indicates the line where the parsing error occured.
74       *
75       * @return line with parsing error or -1 if not known.
76       */
77      public int getErrorLine() {
78          return line;
79      }
80  
81      /**
82       * Sets the line where the error occured.
83       * 
84       * @param line where the error occured.
85       */
86      public void setErrorLine(int line) {
87          this.line=line;
88      }
89  
90      /**
91       * inicates the position where the parsing error occured.
92       *
93       * @return position where parsing error occured or -1 if not known.
94       */
95      public int getErrorPos() {
96          return pos;
97      }
98      
99      /**
100      * sets the position (column) where the error occured.
101      * 
102      * @param pos of error.
103      */
104     public void setErrorPos(int pos) {
105         this.pos=pos;
106     }
107     
108     /**
109      * returns the token that was expected.
110      * 
111      * @return the token that was expected or null if not known.
112      */
113     public String getFoundToken(){
114         return this.foundToken;
115     }
116 
117     /**
118      * set the token that was found during parsing.
119      * 
120      * @param token the token that was found during parsing.
121      */
122     public void setFoundToken(String token){
123         this.foundToken=token;
124     }
125 
126     /**
127      * Indicates which token was expecting when parsing error occured
128      *
129      * @return list of token (comma sperated) that are expecting at the position
130      *         with parsing error, null if not known.
131      */
132     public String getExpectedToken() {
133         return expectedToken;
134     }
135 
136     /**
137      * sets the token that was expected when parsing error occured.
138      * 
139      * @param token the toke that was expected when parsing error occured.
140      */
141     public void setExpectedToken(String token){
142         this.expectedToken=token;
143     }
144     
145     /**
146      * Returns human readable description of error. 
147      * @return message indicating the error that occured. Note
148      * that this class appends some exta information (if given) like the
149      * line and position of the error when "getMessage()" is called.
150      * @see java.lang.Throwable#getMessage()
151      */
152     public String getMessage() {
153         String details ="";
154         if (line!=-1) details = "(Line: "+line+" Pos: "+pos;
155         if (expectedToken!=null) details += " Expected:"+expectedToken;
156         if (foundToken!=null) details += " Found:"+foundToken;
157         if (line!=-1) details += ")";
158         return super.getMessage()+details;
159     }
160 }
161 /*
162  * $Log$
163  * Revision 1.7  2005/10/17 14:57:00  ohamano
164  * new exception text for simple data values without singular argument of type wsml#string
165  *
166  * Revision 1.6  2005/09/21 08:15:39  holgerlausen
167  * fixing java doc, removing asString()
168  *
169  * Revision 1.5  2005/08/04 05:48:26  holgerlausen
170  * added found token
171  *
172  * Revision 1.4  2005/08/01 13:01:27  holgerlausen
173  * more fine grained Error Handling
174  *
175  * Revision 1.3  2005/07/04 11:44:40  marin_dimitrov
176  * formatting?
177  *
178  * Revision 1.2  2005/06/30 09:43:28  alex_simov
179  * refactoring: org.wsmo.parser -> org.wsmo.wsml.*
180  *
181  * Revision 1.2  2005/06/28 09:00:42  holgerlausen
182  * extended ParserException and added enhanced version to WSMLAnalyzer to get better parser error
183  *
184  * Revision 1.1  2005/06/27 08:51:50  alex_simov
185  * refactoring: *.io.locator -> *.locator
186  * refactoring: *.io.parser -> *.parser
187  * refactoring: *.io.datastore -> *.datastore
188  *
189  * Revision 1.4  2005/06/22 14:40:49  alex_simov
190  * Copyright header added/updated
191  *
192  * Revision 1.3  2005/06/01 10:56:44  marin_dimitrov
193  * v0.4.0
194  *
195  * Revision 1.2  2005/05/11 14:02:03  marin
196  * formatting
197  *
198  * Revision 1.1.1.1  2005/05/10 15:12:12  marin
199  * no message
200  *
201  * Revision 1.2  2004/12/11 11:15:43  marin_dimitrov
202  * formatting:
203  * 1. indent is 4 spaces
204  * 2. line break indent is 8 spaces
205  * 3. no tabs
206  *
207  * Revision 1.1  2004/11/30 13:21:22  marin_dimitrov
208  * parser stuff moved from org.wsmo.io --> org.wsmo.io.parser
209  *
210  * Revision 1.2  2004/11/29 16:19:34  damyan_rm
211  * non-default public constructor added
212  *
213  * Revision 1.1  2004/11/26 11:26:10  marin_dimitrov
214  * Parser::parse now throws ParserException and InvalidModelException
215  */