Source Code Cross Referenced for GrammaticaTask.java in  » Parser » grammatica » net » percederberg » grammatica » ant » 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 » Parser » grammatica » net.percederberg.grammatica.ant 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * GrammaticaTask.java
003:         *
004:         * This work is free software; you can redistribute it and/or modify
005:         * it under the terms of the GNU General Public License as published
006:         * by the Free Software Foundation; either version 2 of the License,
007:         * or (at your option) any later version.
008:         *
009:         * This work is distributed in the hope that it will be useful, but
010:         * WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012:         * General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU General Public License
015:         * along with this program; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
017:         * USA
018:         *
019:         * As a special exception, the copyright holders of this library give
020:         * you permission to link this library with independent modules to
021:         * produce an executable, regardless of the license terms of these
022:         * independent modules, and to copy and distribute the resulting
023:         * executable under terms of your choice, provided that you also meet,
024:         * for each linked independent module, the terms and conditions of the
025:         * license of that module. An independent module is a module which is
026:         * not derived from or based on this library. If you modify this
027:         * library, you may extend this exception to your version of the
028:         * library, but you are not obligated to do so. If you do not wish to
029:         * do so, delete this exception statement from your version.
030:         *
031:         * Copyright (c) 2003 Per Cederberg. All rights reserved.
032:         */
033:
034:        package net.percederberg.grammatica.ant;
035:
036:        import java.io.File;
037:        import java.io.FileNotFoundException;
038:        import java.util.Vector;
039:
040:        import org.apache.tools.ant.BuildException;
041:        import org.apache.tools.ant.Task;
042:
043:        import net.percederberg.grammatica.Grammar;
044:        import net.percederberg.grammatica.GrammarException;
045:        import net.percederberg.grammatica.parser.ParserLogException;
046:
047:        /**
048:         * A Grammatica Ant task.
049:         *
050:         * @author   Per Cederberg, <per at percederberg dot net>
051:         * @version  1.4
052:         * @since    1.4
053:         */
054:        public class GrammaticaTask extends Task {
055:
056:            /**
057:             * The grammar file to process.
058:             */
059:            private File file = null;
060:
061:            /**
062:             * The fail on error flag.
063:             */
064:            private boolean failOnError = true;
065:
066:            /**
067:             * The list of processing elements.
068:             */
069:            private Vector processors = new Vector();
070:
071:            /**
072:             * Creates a new Grammatica Ant task.
073:             */
074:            public GrammaticaTask() {
075:            }
076:
077:            /**
078:             * Sets the grammar file.
079:             * 
080:             * @param file           the new grammar file
081:             */
082:            public void setGrammar(File file) {
083:                this .file = file;
084:            }
085:
086:            /**
087:             * Sets the fail on error flag. This flag defaults to true.
088:             * 
089:             * @param failOnError    the new fail on error flag value
090:             */
091:            public void setFailonerror(boolean failOnError) {
092:                this .failOnError = failOnError;
093:            }
094:
095:            /**
096:             * Adds a new validation inner element.
097:             * 
098:             * @param elem           the validation element
099:             */
100:            public void addValidation(ValidationElement elem) {
101:                processors.add(elem);
102:            }
103:
104:            /**
105:             * Adds a new C# code generation inner element.
106:             * 
107:             * @param elem           the C# code generation element
108:             */
109:            public void addCSharp(CSharpElement elem) {
110:                processors.add(elem);
111:            }
112:
113:            /**
114:             * Adds a new Java code generation inner element.
115:             * 
116:             * @param elem           the Java code generation element
117:             */
118:            public void addJava(JavaElement elem) {
119:                processors.add(elem);
120:            }
121:
122:            /**
123:             * Executes the task.
124:             * 
125:             * @throws BuildException if the task execution failed
126:             */
127:            public void execute() throws BuildException {
128:                Grammar grammar;
129:                int i;
130:
131:                // Validate all elements
132:                if (file == null) {
133:                    throw new BuildException("missing 'grammar' attribute");
134:                }
135:                if (processors.size() <= 0) {
136:                    throw new BuildException(
137:                            "missing <validate>, <java>, or <csharp> inner element");
138:                }
139:                for (i = 0; i < processors.size(); i++) {
140:                    ((ProcessingElement) processors.get(i)).validate();
141:                }
142:
143:                // Read grammar file
144:                try {
145:                    grammar = new Grammar(file);
146:                } catch (FileNotFoundException e) {
147:                    throw new BuildException(e);
148:                } catch (ParserLogException e) {
149:                    handleError(e);
150:                    return;
151:                } catch (GrammarException e) {
152:                    handleError(e);
153:                    return;
154:                }
155:
156:                // Process grammar file
157:                for (i = 0; i < processors.size(); i++) {
158:                    try {
159:                        ((ProcessingElement) processors.get(i))
160:                                .process(grammar);
161:                    } catch (BuildException e) {
162:                        handleError(e);
163:                    }
164:                }
165:            }
166:
167:            /**
168:             * Handles an error. This will either print the error or throw
169:             * a build exception, depending of the failOnError flag.
170:             * 
171:             * @param e              the error exception 
172:             * 
173:             * @throws BuildException if the build should fail on errors
174:             */
175:            private void handleError(Exception e) throws BuildException {
176:                if (failOnError) {
177:                    if (e instanceof  BuildException) {
178:                        throw (BuildException) e;
179:                    } else {
180:                        throw new BuildException(e);
181:                    }
182:                }
183:                System.err.println("ERROR: " + e.getMessage());
184:            }
185:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.