Source Code Cross Referenced for Main.java in  » 6.0-JDK-Modules-sun » tools » sun » tools » javap » 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 » 6.0 JDK Modules sun » tools » sun.tools.javap 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2003 Sun Microsystems, Inc.  All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004:         *
005:         * This code is free software; you can redistribute it and/or modify it
006:         * under the terms of the GNU General Public License version 2 only, as
007:         * published by the Free Software Foundation.  Sun designates this
008:         * particular file as subject to the "Classpath" exception as provided
009:         * by Sun in the LICENSE file that accompanied this code.
010:         *
011:         * This code is distributed in the hope that it will be useful, but WITHOUT
012:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014:         * version 2 for more details (a copy is included in the LICENSE file that
015:         * accompanied this code).
016:         *
017:         * You should have received a copy of the GNU General Public License version
018:         * 2 along with this work; if not, write to the Free Software Foundation,
019:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020:         *
021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022:         * CA 95054 USA or visit www.sun.com if you need additional information or
023:         * have any questions.
024:         */
025:
026:        package sun.tools.javap;
027:
028:        import java.util.*;
029:        import java.io.*;
030:
031:        /**
032:         * Entry point for javap, class file disassembler.
033:         *
034:         * @author  Sucheta Dambalkar (Adopted code from old javap)
035:         */
036:        public class Main {
037:
038:            private Vector classList = new Vector();
039:            private PrintWriter out;
040:            JavapEnvironment env = new JavapEnvironment();
041:            private static boolean errorOccurred = false;
042:            private static final String progname = "javap";
043:
044:            public Main(PrintWriter out) {
045:                this .out = out;
046:            }
047:
048:            public static void main(String argv[]) {
049:                entry(argv);
050:                if (errorOccurred) {
051:                    System.exit(1);
052:                }
053:            }
054:
055:            /**
056:             * Entry point for tool if you don't want System.exit() called.
057:             */
058:            public static void entry(String argv[]) {
059:                PrintWriter out = new PrintWriter(new OutputStreamWriter(
060:                        System.out));
061:                try {
062:
063:                    Main jpmain = new Main(out);
064:                    jpmain.perform(argv);
065:
066:                } finally {
067:                    out.close();
068:                }
069:            }
070:
071:            /**
072:             * Process the arguments and perform the desired action
073:             */
074:            private void perform(String argv[]) {
075:                if (parseArguments(argv)) {
076:                    displayResults();
077:
078:                }
079:            }
080:
081:            private void error(String msg) {
082:                errorOccurred = true;
083:                System.err.println(msg);
084:                System.err.flush();
085:            }
086:
087:            /**
088:             * Print usage information
089:             */
090:            private void usage() {
091:                java.io.PrintStream out = System.out;
092:                out.println("Usage: " + progname + " <options> <classes>...");
093:                out.println();
094:                out.println("where options include:");
095:                out
096:                        .println("   -c                        Disassemble the code");
097:                out
098:                        .println("   -classpath <pathlist>     Specify where to find user class files");
099:                out
100:                        .println("   -extdirs <dirs>           Override location of installed extensions");
101:                out
102:                        .println("   -help                     Print this usage message");
103:                out
104:                        .println("   -J<flag>                  Pass <flag> directly to the runtime system");
105:                out
106:                        .println("   -l                        Print line number and local variable tables");
107:                out
108:                        .println("   -public                   Show only public classes and members");
109:                out
110:                        .println("   -protected                Show protected/public classes and members");
111:                out
112:                        .println("   -package                  Show package/protected/public classes");
113:                out
114:                        .println("                             and members (default)");
115:                out
116:                        .println("   -private                  Show all classes and members");
117:                out
118:                        .println("   -s                        Print internal type signatures");
119:                out
120:                        .println("   -bootclasspath <pathlist> Override location of class files loaded");
121:                out
122:                        .println("                             by the bootstrap class loader");
123:                out
124:                        .println("   -verbose                  Print stack size, number of locals and args for methods");
125:                out
126:                        .println("                             If verifying, print reasons for failure");
127:                out.println();
128:            }
129:
130:            /**
131:             * Parse the command line arguments. 
132:             * Set flags, construct the class list and create environment.
133:             */
134:            private boolean parseArguments(String argv[]) {
135:                for (int i = 0; i < argv.length; i++) {
136:                    String arg = argv[i];
137:                    if (arg.startsWith("-")) {
138:                        if (arg.equals("-l")) {
139:                            env.showLineAndLocal = true;
140:                        } else if (arg.equals("-private") || arg.equals("-p")) {
141:                            env.showAccess = env.PRIVATE;
142:                        } else if (arg.equals("-package")) {
143:                            env.showAccess = env.PACKAGE;
144:                        } else if (arg.equals("-protected")) {
145:                            env.showAccess = env.PROTECTED;
146:                        } else if (arg.equals("-public")) {
147:                            env.showAccess = env.PUBLIC;
148:                        } else if (arg.equals("-c")) {
149:                            env.showDisassembled = true;
150:                        } else if (arg.equals("-s")) {
151:                            env.showInternalSigs = true;
152:                        } else if (arg.equals("-verbose")) {
153:                            env.showVerbose = true;
154:                        } else if (arg.equals("-v")) {
155:                            env.showVerbose = true;
156:                        } else if (arg.equals("-h")) {
157:                            error("-h is no longer available - use the 'javah' program");
158:                            return false;
159:                        } else if (arg.equals("-verify")) {
160:                            error("-verify is no longer available - use 'java -verify'");
161:                            return false;
162:                        } else if (arg.equals("-verify-verbose")) {
163:                            error("-verify is no longer available - use 'java -verify'");
164:                            return false;
165:                        } else if (arg.equals("-help")) {
166:                            usage();
167:                            return false;
168:                        } else if (arg.equals("-classpath")) {
169:                            if ((i + 1) < argv.length) {
170:                                env.classPathString = argv[++i];
171:                            } else {
172:                                error("-classpath requires argument");
173:                                usage();
174:                                return false;
175:                            }
176:                        } else if (arg.equals("-bootclasspath")) {
177:                            if ((i + 1) < argv.length) {
178:                                env.bootClassPathString = argv[++i];
179:                            } else {
180:                                error("-bootclasspath requires argument");
181:                                usage();
182:                                return false;
183:                            }
184:                        } else if (arg.equals("-extdirs")) {
185:                            if ((i + 1) < argv.length) {
186:                                env.extDirsString = argv[++i];
187:                            } else {
188:                                error("-extdirs requires argument");
189:                                usage();
190:                                return false;
191:                            }
192:                        } else if (arg.equals("-all")) {
193:                            env.showallAttr = true;
194:                        } else {
195:                            error("invalid flag: " + arg);
196:                            usage();
197:                            return false;
198:                        }
199:                    } else {
200:                        classList.addElement(arg);
201:                        env.nothingToDo = false;
202:                    }
203:                }
204:                if (env.nothingToDo) {
205:                    System.out
206:                            .println("No classes were specified on the command line.  Try -help.");
207:                    errorOccurred = true;
208:                    return false;
209:                }
210:                return true;
211:            }
212:
213:            /**
214:             * Display results
215:             */
216:            private void displayResults() {
217:                for (int i = 0; i < classList.size(); i++) {
218:                    String Name = (String) classList.elementAt(i);
219:                    InputStream classin = env.getFileInputStream(Name);
220:
221:                    try {
222:                        JavapPrinter printer = new JavapPrinter(classin, out,
223:                                env);
224:                        printer.print(); // actual do display
225:
226:                    } catch (IllegalArgumentException exc) {
227:                        error(exc.getMessage());
228:                    }
229:                }
230:            }
231:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.