001:/*
002: * $RCSfile: VrmlTokenMgrError.java,v $
003: *
004: * @(#)VrmlTokenMgrError.java 1.4 98/11/05 20:35:33
005: *
006: * Copyright (c) 1996-1998 Sun Microsystems, Inc. All Rights Reserved.
007: *
008: * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
009: * modify and redistribute this software in source and binary code form,
010: * provided that i) this copyright notice and license appear on all copies of
011: * the software; and ii) Licensee does not utilize the software in a manner
012: * which is disparaging to Sun.
013: *
014: * This software is provided "AS IS," without a warranty of any kind. ALL
015: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
016: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
017: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
018: * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
019: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
020: * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
021: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
022: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
023: * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
024: * POSSIBILITY OF SUCH DAMAGES.
025: *
026: * This software is not designed or intended for use in on-line control of
027: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
028: * the design, construction, operation or maintenance of any nuclear
029: * facility. Licensee represents and warrants that it will not use or
030: * redistribute the Software for such purposes.
031: *
032: * $Revision: 1.2 $
033: * $Date: 2005/02/03 23:07:04 $
034: * $State: Exp $
035: */
036:// Search for _Node to see start of nodes
037:
038:package org.jdesktop.j3d.loaders.vrml97.impl;
039:
040:/**
041: * Generated by JavaCC, but renamed to VrmlTokenMgrError for use with
042: * VrmlTokenManager
043: */
044:public class VrmlTokenMgrError extends Error {
045: /*
046: * Ordinals for various reasons why an Error of this type can be thrown.
047: */
048: /** Lexical error occured. */
049: final static int LEXICAL_ERROR = 0;
050:
051: /**
052: * An attempt wass made to create a second instance of a static token manager.
053: */
054: final static int STATIC_LEXER_ERROR = 1;
055:
056: /** Tried to change to an invalid lexical state. */
057: final static int INVALID_LEXICAL_STATE = 2;
058:
059: /**
060: * Detected (and bailed out of) an infinite loop in the token manager.
061: */
062: final static int LOOP_DETECTED = 3;
063:
064: /**
065: * Indicates the reason why the exception is thrown. It will have
066: * one of the above 4 values.
067: */
068: int errorCode;
069:
070: /**
071: * Replaces unprintable characters by their espaced (or unicode escaped)
072: * equivalents in the given string
073: *
074: *@param str The feature to be added to the Escapes attribute
075: *@return Description of the Return Value
076: */
077: protected final static String addEscapes(String str) {
078: StringBuffer retval = new StringBuffer();
079: char ch;
080: for (int i = 0; i < str.length(); i++) {
081: switch (str.charAt(i)) {
082: case 0:
083: continue;
084: case '\b':
085: retval.append("\\b");
086: continue;
087: case '\t':
088: retval.append("\\t");
089: continue;
090: case '\n':
091: retval.append("\\n");
092: continue;
093: case '\f':
094: retval.append("\\f");
095: continue;
096: case '\r':
097: retval.append("\\r");
098: continue;
099: case '\"':
100: retval.append("\\\"");
101: continue;
102: case '\'':
103: retval.append("\\\'");
104: continue;
105: case '\\':
106: retval.append("\\\\");
107: continue;
108: default:
109: if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
110: String s = "0000" + Integer.toString(ch, 16);
111: retval.append("\\u" + s.substring(s.length() - 4, s.length()));
112: }
113: else {
114: retval.append(ch);
115: }
116: continue;
117: }
118: }
119: return retval.toString();
120: }
121:
122: /**
123: * Returns a detailed message for the Error when it is thrown by the
124: * token manager to indicate a lexical error.
125: * Parameters :
126: * EOFSeen : indicates if EOF caused the lexicl error
127: * curLexState : lexical state in which this error occured
128: * errorLine : line number when the error occured
129: * errorColumn : column number when the error occured
130: * errorAfter : prefix that was seen before this error occured
131: * curchar : the offending character
132: * Note: You can customize the lexical error message by modifying this method.
133: *
134: *@param EOFSeen Description of the Parameter
135: *@param lexState Description of the Parameter
136: *@param errorLine Description of the Parameter
137: *@param errorColumn Description of the Parameter
138: *@param errorAfter Description of the Parameter
139: *@param curChar Description of the Parameter
140: *@return Description of the Return Value
141: */
142: private final static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
143: return ("Lexical error at line " +
144: errorLine + ", column " +
145: errorColumn + ". Encountered: " +
146: (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + "), ") +
147: "after : \"" + addEscapes(errorAfter) + "\"");
148: }
149:
150: /**
151: * You can also modify the body of this method to customize your error messages.
152: * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
153: * of end-users concern, so you can return something like :
154: *
155: * "Internal Error : Please file a bug report .... "
156: *
157: * from this method for such cases in the release version of your parser.
158: *
159: *@return The message value
160: */
161: public String getMessage() {
162: return super .getMessage();
163: }
164:
165: /*
166: * Constructors of various flavors follow.
167: */
168: /**Constructor for the VrmlTokenMgrError object */
169: public VrmlTokenMgrError() { }
170:
171: /**
172: *Constructor for the VrmlTokenMgrError object
173: *
174: *@param message Description of the Parameter
175: *@param reason Description of the Parameter
176: */
177: public VrmlTokenMgrError(String message, int reason) {
178: super (message);
179: errorCode = reason;
180: }
181:
182: /**
183: *Constructor for the VrmlTokenMgrError object
184: *
185: *@param EOFSeen Description of the Parameter
186: *@param lexState Description of the Parameter
187: *@param errorLine Description of the Parameter
188: *@param errorColumn Description of the Parameter
189: *@param errorAfter Description of the Parameter
190: *@param curChar Description of the Parameter
191: *@param reason Description of the Parameter
192: */
193: public VrmlTokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
194: this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
195: }
196:}
|