Source Code Cross Referenced for Tomcat41Bootstrap.java in  » J2EE » Sofia » com » salmonllc » ideTools » 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 » J2EE » Sofia » com.salmonllc.ideTools 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //** Copyright Statement ***************************************************
002:        //The Salmon Open Framework for Internet Applications (SOFIA)
003:        // Copyright (C) 1999 - 2002, Salmon LLC
004:        //
005:        // This program is free software; you can redistribute it and/or
006:        // modify it under the terms of the GNU General Public License version 2
007:        // as published by the Free Software Foundation;
008:        //
009:        // This program is distributed in the hope that it will be useful,
010:        // but WITHOUT ANY WARRANTY; without even the implied warranty of
011:        // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:        // GNU 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, USA.
017:        //
018:        // For more information please visit http://www.salmonllc.com
019:        //** End Copyright Statement ***************************************************
020:        // ====================================================================
021:        //
022:        // The Apache Software License, Version 1.1
023:        //
024:        // Copyright (c) 1999 The Apache Software Foundation.  All rights
025:        // reserved.
026:        //
027:        // Redistribution and use in source and binary forms, with or without
028:        // modification, are permitted provided that the following conditions
029:        // are met:
030:        //
031:        // 1. Redistributions of source code must retain the above copyright
032:        //    notice, this list of conditions and the following disclaimer.
033:        //
034:        // 2. Redistributions in binary form must reproduce the above copyright
035:        //    notice, this list of conditions and the following disclaimer in
036:        //    the documentation and/or other materials provided with the
037:        //    distribution.
038:        //
039:        // 3. The end-user documentation included with the redistribution, if
040:        //    any, must include the following acknowlegement:
041:        //       "This product includes software developed by the
042:        //        Apache Software Foundation (http://www.apache.org/)."
043:        //    Alternately, this acknowlegement may appear in the software itself,
044:        //    if and wherever such third-party acknowlegements normally appear.
045:        //
046:        // 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
047:        //    Foundation" must not be used to endorse or promote products derived
048:        //    from this software without prior written permission. For written
049:        //    permission, please contact apache@apache.org.
050:        //
051:        // 5. Products derived from this software may not be called "Apache"
052:        //    nor may "Apache" appear in their names without prior written
053:        //    permission of the Apache Group.
054:        //
055:        //  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
056:        //  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
057:        //  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
058:        //  DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
059:        //  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
060:        //  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
061:        //  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
062:        //  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
063:        //  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
064:        //  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
065:        //  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
066:        //  SUCH DAMAGE.
067:        //  ====================================================================
068:        //
069:        //  This software consists of voluntary contributions made by many
070:        //  individuals on behalf of the Apache Software Foundation.  For more
071:        //  information on the Apache Software Foundation, please see
072:        //  <http://www.apache.org/>.
073:
074:        package com.salmonllc.ideTools;
075:
076:        import org.apache.catalina.startup.ClassLoaderFactory;
077:
078:        import java.io.File; //import org.apache.catalina.startup.*;
079:        import java.lang.reflect.Method;
080:
081:        /**
082:         * Boostrap loader for Catalina.  This application constructs a class loader
083:         * for use in loading the Catalina internal classes (by accumulating all of the
084:         * JAR files found in the "server" directory under "catalina.home"), and
085:         * starts the regular execution of the container.  The purpose of this
086:         * roundabout approach is to keep the Catalina internal classes (and any
087:         * other classes they depend on, such as an XML parser) out of the system
088:         * class path and therefore not visible to application level classes.
089:         *
090:         * @author Craig R. McClanahan
091:         * @version $Revision: 2 $ $Date: 10/31/02 11:37a $
092:         */
093:
094:        public final class Tomcat41Bootstrap {
095:
096:            // ------------------------------------------------------- Static Variables
097:
098:            /**
099:             * Debugging detail level for processing the startup.
100:             */
101:            private static int debug = 0;
102:            private boolean _restart = false;
103:            private String _extraCom = null;
104:            private String _extraArgs = null;
105:
106:            public static int START = 1;
107:            public static int STOP = 2;
108:            public static int RESTART = 3;
109:
110:            // ----------------------------------------------------------- Main Program
111:
112:            /**
113:             * Create a new bootstrap object, extraCom and extraArgs are so the browser can start after the server starts
114:             */
115:            private Tomcat41Bootstrap(boolean restart, String extraCom,
116:                    String extraArgs) {
117:                _restart = restart;
118:                _extraCom = extraCom;
119:                _extraArgs = extraArgs;
120:            }
121:
122:            /**
123:             * Start, stop or restart the local tomcat server. Optionally launch the browser as well.
124:             * @param process constants START, STOP or RESTART
125:             * @param browserPath - The full path to the browser executable
126:             * @param webPage - The URL of the web page to run
127:             */
128:            public static void execute(int process, String browserPath,
129:                    String webPage) {
130:                Tomcat41Bootstrap tb = new Tomcat41Bootstrap(
131:                        process == RESTART, browserPath, webPage);
132:                if (process == START)
133:                    executeCommand("start", tb);
134:                else if (process == STOP || process == RESTART)
135:                    executeCommand("stop", tb);
136:
137:            }
138:
139:            /**
140:             * The main program for the bootstrap.
141:             *
142:             * @param args Command line arguments to be processed
143:             */
144:            public static void executeCommand(String args[],
145:                    Tomcat41Bootstrap tb) {
146:
147:                // Set the debug flag appropriately
148:                for (int i = 0; i < args.length; i++) {
149:                    if ("-debug".equals(args[i]))
150:                        debug = 1;
151:                }
152:
153:                // Configure catalina.base from catalina.home if not yet set
154:                if (System.getProperty("catalina.base") == null)
155:                    System.setProperty("catalina.base", getCatalinaHome());
156:
157:                // Construct the class loaders we will need
158:                ClassLoader commonLoader = null;
159:                ClassLoader catalinaLoader = null;
160:                ClassLoader sharedLoader = null;
161:                try {
162:
163:                    File unpacked[] = new File[1];
164:                    File packed[] = new File[1];
165:                    File packed2[] = new File[2];
166:                    ClassLoaderFactory.setDebug(debug);
167:
168:                    unpacked[0] = new File(getCatalinaHome(), "common"
169:                            + File.separator + "classes");
170:                    packed2[0] = new File(getCatalinaHome(), "common"
171:                            + File.separator + "endorsed");
172:                    packed2[1] = new File(getCatalinaHome(), "common"
173:                            + File.separator + "lib");
174:                    commonLoader = ClassLoaderFactory.createClassLoader(
175:                            unpacked, packed2, null);
176:
177:                    unpacked[0] = new File(getCatalinaHome(), "server"
178:                            + File.separator + "classes");
179:                    packed[0] = new File(getCatalinaHome(), "server"
180:                            + File.separator + "lib");
181:                    catalinaLoader = ClassLoaderFactory.createClassLoader(
182:                            unpacked, packed, commonLoader);
183:
184:                    unpacked[0] = new File(getCatalinaBase(), "shared"
185:                            + File.separator + "classes");
186:                    packed[0] = new File(getCatalinaBase(), "shared"
187:                            + File.separator + "lib");
188:                    sharedLoader = ClassLoaderFactory.createClassLoader(
189:                            unpacked, packed, commonLoader);
190:                } catch (Throwable t) {
191:
192:                    log("Class loader creation threw exception", t);
193:                    System.exit(1);
194:
195:                }
196:
197:                Thread.currentThread().setContextClassLoader(catalinaLoader);
198:
199:                // Load our startup class and call its process() method
200:                try {
201:
202:                    //SecurityClassLoad.securityClassLoad(catalinaLoader);
203:
204:                    // Instantiate a startup class instance
205:                    if (debug >= 1)
206:                        log("Loading startup class");
207:                    Class startupClass = catalinaLoader
208:                            .loadClass("com.salmonllc.ideTools.Tomcat41Engine");
209:                    Object startupInstance = startupClass.newInstance();
210:
211:                    // Set the shared extensions class loader
212:                    if (debug >= 1)
213:                        log("Setting startup class properties");
214:                    String methodName = "setParentClassLoader";
215:                    Class paramTypes[] = new Class[1];
216:                    paramTypes[0] = Class.forName("java.lang.ClassLoader");
217:                    Object paramValues[] = new Object[1];
218:                    paramValues[0] = sharedLoader;
219:                    Method method = startupInstance.getClass().getMethod(
220:                            methodName, paramTypes);
221:                    method.invoke(startupInstance, paramValues);
222:
223:                    // Call the process() method
224:                    if (debug >= 1)
225:                        log("Calling startup class process() method");
226:                    methodName = "process";
227:                    paramTypes = new Class[2];
228:                    paramTypes[0] = args.getClass();
229:                    paramTypes[1] = tb.getClass();
230:                    paramValues = new Object[2];
231:                    paramValues[0] = args;
232:                    paramValues[1] = tb;
233:                    method = startupInstance.getClass().getMethod(methodName,
234:                            paramTypes);
235:                    method.invoke(startupInstance, paramValues);
236:
237:                } catch (Exception e) {
238:                    System.out.println("Exception during startup processing");
239:                    e.printStackTrace(System.out);
240:                    System.exit(2);
241:                }
242:
243:            }
244:
245:            /**
246:             * Get the value of the catalina.home environment variable.
247:             */
248:            private static String getCatalinaHome() {
249:                return System.getProperty("catalina.home", System
250:                        .getProperty("user.dir"));
251:            }
252:
253:            /**
254:             * Get the value of the catalina.base environment variable.
255:             */
256:            private static String getCatalinaBase() {
257:                return System.getProperty("catalina.base", getCatalinaHome());
258:            }
259:
260:            /**
261:             * Log a debugging detail message.
262:             *
263:             * @param message The message to be logged
264:             */
265:            private static void log(String message) {
266:
267:                System.out.print("Bootstrap: ");
268:                System.out.println(message);
269:
270:            }
271:
272:            /**
273:             * Log a debugging detail message with an exception.
274:             *
275:             * @param message The message to be logged
276:             * @param exception The exception to be logged
277:             */
278:            private static void log(String message, Throwable exception) {
279:
280:                log(message);
281:                exception.printStackTrace(System.out);
282:
283:            }
284:
285:            private static void executeCommand(String args, Tomcat41Bootstrap tb) {
286:                String argsArr[] = new String[1];
287:                argsArr[0] = args;
288:                executeCommand(argsArr, tb);
289:            }
290:
291:            String getBrowserExe() {
292:                return _extraCom;
293:            }
294:
295:            String getBrowserURL() {
296:                return _extraArgs;
297:            }
298:
299:            /**
300:             * This method gets fired when a process is executed
301:             */
302:            void notifyComplete() {
303:                if (_restart) {
304:                    _restart = false;
305:                    executeCommand("start", this);
306:                }
307:            }
308:
309:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.