Source Code Cross Referenced for ParseException.java in  » Database-DBMS » db-derby-10.2 » org » apache » derby » impl » sql » compile » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » db derby 10.2 » org.apache.derby.impl.sql.compile 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:           Derby - Class org.apache.derby.impl.sql.compile.ParseException
004:
005:           Licensed to the Apache Software Foundation (ASF) under one or more
006:           contributor license agreements.  See the NOTICE file distributed with
007:           this work for additional information regarding copyright ownership.
008:           The ASF licenses this file to you under the Apache License, Version 2.0
009:           (the "License"); you may not use this file except in compliance with
010:           the License.  You may obtain a copy of the License at
011:
012:              http://www.apache.org/licenses/LICENSE-2.0
013:
014:           Unless required by applicable law or agreed to in writing, software
015:           distributed under the License is distributed on an "AS IS" BASIS,
016:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017:           See the License for the specific language governing permissions and
018:           limitations under the License.
019:
020:         */
021:
022:        package org.apache.derby.impl.sql.compile;
023:
024:        /**
025:         * This exception is thrown when parse errors are encountered.
026:         * You can explicitly create objects of this exception type by
027:         * calling the method generateParseException in the generated
028:         * parser.
029:         *
030:         * You can modify this class to customize your error reporting
031:         * mechanisms so long as you retain the public fields.
032:         */
033:        public class ParseException extends Exception {
034:
035:            /**
036:             * This constructor is used by the method "generateParseException"
037:             * in the generated parser.  Calling this constructor generates
038:             * a new object of this type with the fields "currentToken",
039:             * "expectedTokenSequences", and "tokenImage" set.  The boolean
040:             * flag "specialConstructor" is also set to true to indicate that
041:             * this constructor was used to create this object.
042:             * This constructor calls its super class with the empty string
043:             * to force the "toString" method of parent class "Throwable" to
044:             * print the error message in the form:
045:             *     ParseException: <result of getMessage>
046:             */
047:            public ParseException(Token currentTokenVal,
048:                    int[][] expectedTokenSequencesVal, String[] tokenImageVal) {
049:                super ("");
050:                specialConstructor = true;
051:                currentToken = currentTokenVal;
052:                expectedTokenSequences = expectedTokenSequencesVal;
053:                tokenImage = tokenImageVal;
054:            }
055:
056:            /**
057:             * The following constructors are for use by you for whatever
058:             * purpose you can think of.  Constructing the exception in this
059:             * manner makes the exception behave in the normal way - i.e., as
060:             * documented in the class "Throwable".  The fields "errorToken",
061:             * "expectedTokenSequences", and "tokenImage" do not contain
062:             * relevant information.  The JavaCC generated code does not use
063:             * these constructors.
064:             */
065:
066:            public ParseException() {
067:                super ();
068:                specialConstructor = false;
069:            }
070:
071:            public ParseException(String message) {
072:                super (message);
073:                specialConstructor = false;
074:            }
075:
076:            /**
077:             * This variable determines which constructor was used to create
078:             * this object and thereby affects the semantics of the
079:             * "getMessage" method (see below).
080:             */
081:            protected boolean specialConstructor;
082:
083:            /**
084:             * This is the last token that has been consumed successfully.  If
085:             * this object has been created due to a parse error, the token
086:             * followng this token will (therefore) be the first error token.
087:             */
088:            public Token currentToken;
089:
090:            /**
091:             * Each entry in this array is an array of integers.  Each array
092:             * of integers represents a sequence of tokens (by their ordinal
093:             * values) that is expected at this point of the parse.
094:             */
095:            public int[][] expectedTokenSequences;
096:
097:            /**
098:             * This is a reference to the "tokenImage" array of the generated
099:             * parser within which the parse error occurred.  This array is
100:             * defined in the generated ...Constants interface.
101:             */
102:            public String[] tokenImage;
103:
104:            /**
105:             * This method has the standard behavior when this object has been
106:             * created using the standard constructors.  Otherwise, it uses
107:             * "currentToken" and "expectedTokenSequences" to generate a parse
108:             * error message and returns it.  If this object has been created
109:             * due to a parse error, and you do not catch it (it gets thrown
110:             * from the parser), then this method is called during the printing
111:             * of the final stack trace, and hence the correct error message
112:             * gets displayed.
113:             */
114:            public String getMessage() {
115:                if (!specialConstructor) {
116:                    return super .getMessage();
117:                }
118:                String expected = "";
119:                int maxSize = 0;
120:                for (int i = 0; i < expectedTokenSequences.length; i++) {
121:                    if (maxSize < expectedTokenSequences[i].length) {
122:                        maxSize = expectedTokenSequences[i].length;
123:                    }
124:                    for (int j = 0; j < expectedTokenSequences[i].length; j++) {
125:                        expected += tokenImage[expectedTokenSequences[i][j]]
126:                                + " ";
127:                    }
128:                    if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
129:                        expected += "...";
130:                    }
131:                    expected += eol + "    ";
132:                }
133:                String retval = "Encountered \"";
134:                Token tok = currentToken.next;
135:                for (int i = 0; i < maxSize; i++) {
136:                    if (i != 0)
137:                        retval += " ";
138:                    if (tok.kind == 0) {
139:                        retval += tokenImage[0];
140:                        break;
141:                    }
142:                    retval += add_escapes(tok.image);
143:                    tok = tok.next;
144:                }
145:                retval += "\" at line " + currentToken.next.beginLine
146:                        + ", column " + currentToken.next.beginColumn;
147:                /*
148:                 * For output compatibility with previous releases, do not report expected tokens.
149:                 *
150:                   retval += "." + eol;
151:                   if (expectedTokenSequences.length == 1) {
152:                     retval += "Was expecting:" + eol + "    ";
153:                   } else {
154:                     retval += "Was expecting one of:" + eol + "    ";
155:                   }
156:                   retval += expected;
157:                 */
158:                return retval;
159:            }
160:
161:            /**
162:             * The end of line string for this machine.
163:             */
164:            protected String eol = System.getProperty("line.separator", "\n");
165:
166:            /**
167:             * Used to convert raw characters to their escaped version
168:             * when these raw version cannot be used as part of an ASCII
169:             * string literal.
170:             */
171:            protected String add_escapes(String str) {
172:                StringBuffer retval = new StringBuffer();
173:                char ch;
174:                for (int i = 0; i < str.length(); i++) {
175:                    switch (str.charAt(i)) {
176:                    case 0:
177:                        continue;
178:                    case '\b':
179:                        retval.append("\\b");
180:                        continue;
181:                    case '\t':
182:                        retval.append("\\t");
183:                        continue;
184:                    case '\n':
185:                        retval.append("\\n");
186:                        continue;
187:                    case '\f':
188:                        retval.append("\\f");
189:                        continue;
190:                    case '\r':
191:                        retval.append("\\r");
192:                        continue;
193:                    case '\"':
194:                        retval.append("\\\"");
195:                        continue;
196:                    case '\'':
197:                        retval.append("\\\'");
198:                        continue;
199:                    case '\\':
200:                        retval.append("\\\\");
201:                        continue;
202:                    default:
203:                        if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
204:                            String s = "0000" + Integer.toString(ch, 16);
205:                            retval.append("\\u"
206:                                    + s.substring(s.length() - 4, s.length()));
207:                        } else {
208:                            retval.append(ch);
209:                        }
210:                        continue;
211:                    }
212:                }
213:                return retval.toString();
214:            }
215:
216:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.