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


001:        /*
002:         * Copyright 2002-2004 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 com.sun.tools.javah;
027:
028:        import java.io.File;
029:        import java.io.FileInputStream;
030:        import java.io.IOException;
031:        import java.util.ResourceBundle;
032:        import java.text.MessageFormat;
033:        import java.util.MissingResourceException;
034:
035:        /**
036:         * Messages, verbose and error handling support.
037:         *
038:         * For errors, the failure modes are:
039:         *      error -- User did something wrong
040:         *      bug   -- Bug has occurred in javah
041:         *      fatal -- We can't even find resources, so bail fast, don't localize
042:         *
043:         */
044:        public class Util {
045:
046:            /*
047:             * Help for verbosity.
048:             */
049:            public static boolean verbose = false;
050:
051:            public static void log(String s) {
052:                System.out.println(s);
053:            }
054:
055:            /* 
056:             * Help for loading localized messages.
057:             */
058:            private static ResourceBundle m;
059:
060:            private static void initMessages() {
061:                try {
062:                    m = ResourceBundle
063:                            .getBundle("com.sun.tools.javah.resources.l10n");
064:                } catch (MissingResourceException mre) {
065:                    fatal(
066:                            "Error loading resources.  Please file a bug report.",
067:                            mre);
068:                }
069:            }
070:
071:            public static String getText(String key) {
072:                return getText(key, null, null);
073:            }
074:
075:            private static String getText(String key, String a1, String a2) {
076:                if (m == null)
077:                    initMessages();
078:                try {
079:                    return MessageFormat.format(m.getString(key), new Object[] {
080:                            a1, a2 });
081:                } catch (MissingResourceException e) {
082:                    fatal("Key " + key + " not found in resources.", e);
083:                }
084:                return null; /* dead code */
085:            }
086:
087:            /*
088:             * Usage message.
089:             */
090:            public static void usage(int exitValue) {
091:                if (exitValue == 0) {
092:                    System.out.println(getText("usage"));
093:                } else {
094:                    System.err.println(getText("usage"));
095:                }
096:                System.exit(exitValue);
097:            }
098:
099:            public static void version() {
100:                System.out.println(getText("javah.version", System
101:                        .getProperty("java.version"), null));
102:                System.exit(0);
103:            }
104:
105:            /*
106:             * Failure modes.
107:             */
108:            public static void bug(String key) {
109:                bug(key, null);
110:            }
111:
112:            public static void bug(String key, Exception e) {
113:                if (e != null)
114:                    e.printStackTrace();
115:                System.err.println(getText(key));
116:                System.err.println(getText("bug.report"));
117:                System.exit(11);
118:            }
119:
120:            public static void error(String key) {
121:                error(key, null);
122:            }
123:
124:            public static void error(String key, String a1) {
125:                error(key, a1, null);
126:            }
127:
128:            public static void error(String key, String a1, String a2) {
129:                error(key, a1, a2, false);
130:            }
131:
132:            public static void error(String key, String a1, String a2,
133:                    boolean showUsage) {
134:                System.err.println("Error: " + getText(key, a1, a2));
135:                if (showUsage)
136:                    usage(15);
137:                System.exit(15);
138:            }
139:
140:            private static void fatal(String msg) {
141:                fatal(msg, null);
142:            }
143:
144:            private static void fatal(String msg, Exception e) {
145:                if (e != null) {
146:                    e.printStackTrace();
147:                }
148:                System.err.println(msg);
149:                System.exit(10);
150:            }
151:
152:            /*
153:             * Support for platform specific things in javah, such as pragma
154:             * directives, exported symbols etc.
155:             */
156:            static private ResourceBundle platform = null;
157:
158:            /*
159:             * Set when platform has been initialized.
160:             */
161:            static private boolean platformInit = false;
162:
163:            static String getPlatformString(String key) {
164:                if (!platformInit) {
165:                    initPlatform();
166:                    platformInit = true;
167:                }
168:                if (platform == null)
169:                    return null;
170:                try {
171:                    return platform.getString(key);
172:                } catch (MissingResourceException mre) {
173:                    return null;
174:                }
175:            }
176:
177:            private static void initPlatform() {
178:                String os = System.getProperty("os.name");
179:                if (os.startsWith("Windows")) {
180:                    os = "win32";
181:                } else if (os.indexOf("Linux") >= 0) {
182:                    os = "Linux";
183:                }
184:                String arch = System.getProperty("os.arch");
185:                String resname = "com.sun.tools.javah.resources." + os + "_"
186:                        + arch;
187:                try {
188:                    platform = ResourceBundle.getBundle(resname);
189:                } catch (MissingResourceException mre) {
190:                    // fatal("Error loading resources.  Please file a bug report.", mre);
191:                }
192:            }
193:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.