Source Code Cross Referenced for CommandLineArguments.java in  » Web-Services » xins » org » xins » common » servlet » container » 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 » Web Services » xins » org.xins.common.servlet.container 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: CommandLineArguments.java,v 1.4 2007/09/18 08:45:08 agoubard Exp $
003:         *
004:         * Copyright 2003-2007 Orange Nederland Breedband B.V.
005:         * See the COPYRIGHT file for redistribution and use restrictions.
006:         */
007:        package org.xins.common.servlet.container;
008:
009:        import java.io.File;
010:        import java.net.URI;
011:        import java.net.URISyntaxException;
012:        import java.net.URL;
013:
014:        /**
015:         * Class used to parse and get the command line arguments when the internal
016:         * Servlet container is started.
017:         *
018:         * @version $Revision: 1.4 $ $Date: 2007/09/18 08:45:08 $
019:         * @author <a href="mailto:anthony.goubard@japplis.com">Anthony Goubard</a>
020:         */
021:        class CommandLineArguments {
022:
023:            /**
024:             * The port number to use for the Servlet container or -1 if the Servlet
025:             * container should not be started.
026:             */
027:            private int port;
028:
029:            /**
030:             * The WAR file to execute.
031:             */
032:            private File warFile;
033:
034:            /**
035:             * The ClassLoader mode with which the Servlet should be loaded.
036:             */
037:            private int loaderMode = -1;
038:
039:            /**
040:             * <code>true</code> if the graphical user interface should be started,
041:             * <code>false</code> to run the Servlet in the console.
042:             */
043:            private boolean showGUI;
044:
045:            /**
046:             * Parses the command line arguments.
047:             *
048:             * @param args
049:             *    the command line arguments as passed to the <code>main()</code> method.
050:             */
051:            CommandLineArguments(String[] args) {
052:                port = HTTPServletStarter.DEFAULT_PORT_NUMBER;
053:                showGUI = false;
054:                if (args.length == 1 && args[0].equals("-help")) {
055:                    System.out
056:                            .println("Usage: java [-Dorg.xins.server.config=<xins properties>] -jar <api name>.war [-port:<port number>] [-gui] [-war:<war file>] [-loader:<classloader mode>]");
057:                    System.out
058:                            .println("  if port number = -1, the Servlet is not started.");
059:                    System.exit(0);
060:                }
061:                for (int i = 0; i < args.length; i++) {
062:                    String arg = args[i];
063:                    if (arg.startsWith("-port:") || arg.startsWith("-port=")) {
064:                        try {
065:                            port = Integer.parseInt(arg.substring(6));
066:                        } catch (NumberFormatException nfe) {
067:                            System.err
068:                                    .println("Warning: Incorrect port number \""
069:                                            + args[1]
070:                                            + "\", using "
071:                                            + HTTPServletStarter.DEFAULT_PORT_NUMBER
072:                                            + " as port number.");
073:                        }
074:                    } else if (arg.startsWith("-war:")
075:                            || arg.startsWith("-war=")) {
076:                        warFile = new File(arg.substring(5));
077:                    } else if (arg.startsWith("-loader:")
078:                            || arg.startsWith("-loader=")) {
079:                        try {
080:                            loaderMode = Integer.parseInt(args[2]);
081:                        } catch (NumberFormatException nfe) {
082:                            System.err
083:                                    .println("Warning: Incorrect ClassLoader \""
084:                                            + args[2]
085:                                            + "\", using "
086:                                            + ServletClassLoader.USE_WAR_LIB
087:                                            + " as default.");
088:                        }
089:                    } else if (arg.equalsIgnoreCase("-gui")) {
090:                        showGUI = true;
091:
092:                        // for backward compatibility
093:                    } else if (arg.endsWith(".war") && warFile == null) {
094:                        warFile = new File(arg);
095:                    } else if (port == HTTPServletStarter.DEFAULT_PORT_NUMBER) {
096:                        try {
097:                            port = Integer.parseInt(arg);
098:                        } catch (NumberFormatException nfe) {
099:                        }
100:                    }
101:                }
102:
103:                // Detect the location of the WAR file if needed.
104:                if (warFile == null) {
105:                    URL codeLocation = HTTPServletStarter.class
106:                            .getProtectionDomain().getCodeSource()
107:                            .getLocation();
108:                    System.out
109:                            .println("No WAR file passed as argument, using: "
110:                                    + codeLocation);
111:                    try {
112:                        warFile = new File(new URI(codeLocation.toString()));
113:                    } catch (URISyntaxException murlex) {
114:                        murlex.printStackTrace();
115:                    }
116:                }
117:
118:                if (warFile == null || !warFile.exists()) {
119:                    System.err.println("WAR file \"" + warFile
120:                            + "\" not found.");
121:                    System.exit(-1);
122:                }
123:
124:                // Detect the ClassLoader mode
125:                if (loaderMode == -1) {
126:                    String classPath = System.getProperty("java.class.path");
127:                    if (classPath.indexOf("xins-common.jar") != -1
128:                            && classPath.indexOf("servlet.jar") != -1
129:                            && classPath.indexOf("xins-server.jar") != -1
130:                            && classPath.indexOf("xmlenc.jar") != -1) {
131:                        loaderMode = ServletClassLoader.USE_WAR_EXTERNAL_LIB;
132:                    } else {
133:                        loaderMode = ServletClassLoader.USE_WAR_LIB;
134:                    }
135:                }
136:            }
137:
138:            /**
139:             * Gets the port number specified. If no default port number is specified
140:             * return the default port number.
141:             *
142:             * @return
143:             *    the port number.
144:             */
145:            int getPort() {
146:                return port;
147:            }
148:
149:            /**
150:             * Gets the location of the WAR file to execute.
151:             *
152:             * @return
153:             *    the WAR file or <code>null</code> if not found.
154:             */
155:            File getWarFile() {
156:                return warFile;
157:            }
158:
159:            /**
160:             * Gets the class loader mode.
161:             *
162:             * @return
163:             *    the class loader mode to use to load the WAR classes.
164:             */
165:            int getLoaderMode() {
166:                return loaderMode;
167:            }
168:
169:            /**
170:             * Indicates whether to run it in console mode or with the Swing user interface.
171:             *
172:             * @return
173:             *    <code>true</code> for the graphical user interface mode,
174:             *    <code>false</code> for the console mode.
175:             */
176:            boolean showGUI() {
177:                return showGUI;
178:            }
179:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.