Source Code Cross Referenced for Tool.java in  » Database-ORM » toplink » persistence » antlr » preprocessor » 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 ORM » toplink » persistence.antlr.preprocessor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package persistence.antlr.preprocessor;
002:
003:        /* ANTLR Translator Generator
004:         * Project led by Terence Parr at http://www.jGuru.com
005:         * Software rights: http://www.antlr.org/license.html
006:         *
007:         */
008:
009:        import java.io.*;
010:        import persistence.antlr.collections.impl.Vector;
011:        import java.util.Enumeration;
012:
013:        /** Tester for the preprocessor */
014:        public class Tool {
015:            protected Hierarchy theHierarchy;
016:            protected String grammarFileName;
017:            protected String[] args;
018:            protected int nargs; // how many args in new args list
019:            protected Vector grammars;
020:            protected persistence.antlr.Tool antlrTool;
021:
022:            public Tool(persistence.antlr.Tool t, String[] args) {
023:                antlrTool = t;
024:                processArguments(args);
025:            }
026:
027:            public static void main(String[] args) {
028:                persistence.antlr.Tool antlrTool = new persistence.antlr.Tool();
029:                Tool theTool = new Tool(antlrTool, args);
030:                theTool.preprocess();
031:                String[] a = theTool.preprocessedArgList();
032:                for (int i = 0; i < a.length; i++) {
033:                    System.out.print(" " + a[i]);
034:                }
035:                System.out.println();
036:            }
037:
038:            public boolean preprocess() {
039:                if (grammarFileName == null) {
040:                    antlrTool.toolError("no grammar file specified");
041:                    return false;
042:                }
043:                if (grammars != null) {
044:                    theHierarchy = new Hierarchy(antlrTool);
045:                    for (Enumeration e = grammars.elements(); e
046:                            .hasMoreElements();) {
047:                        String f = (String) e.nextElement();
048:                        try {
049:                            theHierarchy.readGrammarFile(f);
050:                        } catch (FileNotFoundException fe) {
051:                            antlrTool.toolError("file " + f + " not found");
052:                            return false;
053:                        }
054:                    }
055:                }
056:
057:                // do the actual inheritance stuff
058:                boolean complete = theHierarchy.verifyThatHierarchyIsComplete();
059:                if (!complete)
060:                    return false;
061:                theHierarchy.expandGrammarsInFile(grammarFileName);
062:                GrammarFile gf = theHierarchy.getFile(grammarFileName);
063:                String expandedFileName = gf
064:                        .nameForExpandedGrammarFile(grammarFileName);
065:
066:                // generate the output file if necessary
067:                if (expandedFileName.equals(grammarFileName)) {
068:                    args[nargs++] = grammarFileName; // add to argument list
069:                } else {
070:                    try {
071:                        gf.generateExpandedFile(); // generate file to feed ANTLR
072:                        args[nargs++] = antlrTool.getOutputDirectory()
073:                                + System.getProperty("file.separator")
074:                                + expandedFileName; // add to argument list
075:                    } catch (IOException io) {
076:                        antlrTool
077:                                .toolError("cannot write expanded grammar file "
078:                                        + expandedFileName);
079:                        return false;
080:                    }
081:                }
082:                return true;
083:            }
084:
085:            /** create new arg list with correct length to pass to ANTLR */
086:            public String[] preprocessedArgList() {
087:                String[] a = new String[nargs];
088:                System.arraycopy(args, 0, a, 0, nargs);
089:                args = a;
090:                return args;
091:            }
092:
093:            /** Process -glib options and grammar file.  Create a new args list
094:             *  that does not contain the -glib option.  The grammar file name
095:             *  might be modified and, hence, is not added yet to args list.
096:             */
097:            private void processArguments(String[] incomingArgs) {
098:                this .nargs = 0;
099:                this .args = new String[incomingArgs.length];
100:                for (int i = 0; i < incomingArgs.length; i++) {
101:                    if (incomingArgs[i].length() == 0) {
102:                        antlrTool.warning("Zero length argument ignoring...");
103:                        continue;
104:                    }
105:                    if (incomingArgs[i].equals("-glib")) {
106:                        // if on a pc and they use a '/', warn them
107:                        if (File.separator.equals("\\")
108:                                && incomingArgs[i].indexOf('/') != -1) {
109:                            antlrTool
110:                                    .warning("-glib cannot deal with '/' on a PC: use '\\'; ignoring...");
111:                        } else {
112:                            grammars = antlrTool.parseSeparatedList(
113:                                    incomingArgs[i + 1], ';');
114:                            i++;
115:                        }
116:                    } else if (incomingArgs[i].equals("-o")) {
117:                        args[this .nargs++] = incomingArgs[i];
118:                        if (i + 1 >= incomingArgs.length) {
119:                            antlrTool
120:                                    .error("missing output directory with -o option; ignoring");
121:                        } else {
122:                            i++;
123:                            args[this .nargs++] = incomingArgs[i];
124:                            antlrTool.setOutputDirectory(incomingArgs[i]);
125:                        }
126:                    } else if (incomingArgs[i].charAt(0) == '-') {
127:                        args[this .nargs++] = incomingArgs[i];
128:                    } else {
129:                        // Must be the grammar file
130:                        grammarFileName = incomingArgs[i];
131:                        if (grammars == null) {
132:                            grammars = new Vector(10);
133:                        }
134:                        grammars.appendElement(grammarFileName); // process it too
135:                        if ((i + 1) < incomingArgs.length) {
136:                            antlrTool
137:                                    .warning("grammar file must be last; ignoring other arguments...");
138:                            break;
139:                        }
140:                    }
141:                }
142:            }
143:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.