Source Code Cross Referenced for WebAppDeployer.java in  » Sevlet-Container » jetty-modules » org » mortbay » jetty » deployer » 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 » Sevlet Container » jetty modules » org.mortbay.jetty.deployer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //========================================================================
002:        //$Id: WebAppDeployer.java 1237 2006-11-17 09:32:17Z gregw $
003:        //Copyright 2006 Mort Bay Consulting Pty. Ltd.
004:        //------------------------------------------------------------------------
005:        //Licensed under the Apache License, Version 2.0 (the "License");
006:        //you may not use this file except in compliance with the License.
007:        //You may obtain a copy of the License at 
008:        //http://www.apache.org/licenses/LICENSE-2.0
009:        //Unless required by applicable law or agreed to in writing, software
010:        //distributed under the License is distributed on an "AS IS" BASIS,
011:        //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012:        //See the License for the specific language governing permissions and
013:        //limitations under the License.
014:        //========================================================================
015:
016:        package org.mortbay.jetty.deployer;
017:
018:        import java.util.ArrayList;
019:
020:        import org.mortbay.component.AbstractLifeCycle;
021:        import org.mortbay.jetty.Handler;
022:        import org.mortbay.jetty.HandlerContainer;
023:        import org.mortbay.jetty.handler.ContextHandler;
024:        import org.mortbay.jetty.handler.ContextHandlerCollection;
025:        import org.mortbay.jetty.webapp.WebAppContext;
026:        import org.mortbay.resource.Resource;
027:
028:        /**
029:         * Web Application Deployer.
030:         * 
031:         * The class searches a directory for and deploys standard web application.
032:         * At startup, the directory specified by {@link #setWebAppDir(String)} is searched 
033:         * for subdirectories (excluding hidden and CVS) or files ending with ".zip"
034:         * or "*.war".  For each webapp discovered is passed to a new instance
035:         * of {@link WebAppContext} (or a subclass specified by {@link #getContexts()}.
036:         * {@link ContextHandlerCollection#getContextClass()}
037:         * 
038:         * This deployer does not do hot deployment or undeployment. Nor does
039:         * it support per webapplication configuration. For these features 
040:         * see {@link ContextDeployer}.
041:         * 
042:         * @see {@link ContextDeployer}
043:         */
044:        public class WebAppDeployer extends AbstractLifeCycle {
045:            private HandlerContainer _contexts;
046:            private String _webAppDir;
047:            private String _defaultsDescriptor;
048:            private String[] _configurationClasses;
049:            private boolean _extract;
050:            private boolean _parentLoaderPriority;
051:            private boolean _allowDuplicates;
052:            private ArrayList _deployed;
053:
054:            public String[] getConfigurationClasses() {
055:                return _configurationClasses;
056:            }
057:
058:            public void setConfigurationClasses(String[] configurationClasses) {
059:                _configurationClasses = configurationClasses;
060:            }
061:
062:            public HandlerContainer getContexts() {
063:                return _contexts;
064:            }
065:
066:            public void setContexts(HandlerContainer contexts) {
067:                _contexts = contexts;
068:            }
069:
070:            public String getDefaultsDescriptor() {
071:                return _defaultsDescriptor;
072:            }
073:
074:            public void setDefaultsDescriptor(String defaultsDescriptor) {
075:                _defaultsDescriptor = defaultsDescriptor;
076:            }
077:
078:            public boolean isExtract() {
079:                return _extract;
080:            }
081:
082:            public void setExtract(boolean extract) {
083:                _extract = extract;
084:            }
085:
086:            public boolean isParentLoaderPriority() {
087:                return _parentLoaderPriority;
088:            }
089:
090:            public void setParentLoaderPriority(
091:                    boolean parentPriorityClassLoading) {
092:                _parentLoaderPriority = parentPriorityClassLoading;
093:            }
094:
095:            public String getWebAppDir() {
096:                return _webAppDir;
097:            }
098:
099:            public void setWebAppDir(String dir) {
100:                _webAppDir = dir;
101:            }
102:
103:            public boolean getAllowDuplicates() {
104:                return _allowDuplicates;
105:            }
106:
107:            /* ------------------------------------------------------------ */
108:            /**
109:             * @param allowDuplicates If false, do not deploy webapps that have already been deployed or duplicate context path
110:             */
111:            public void setAllowDuplicates(boolean allowDuplicates) {
112:                _allowDuplicates = allowDuplicates;
113:            }
114:
115:            /* ------------------------------------------------------------ */
116:            /**
117:             * @throws Exception 
118:             */
119:            public void doStart() throws Exception {
120:                _deployed = new ArrayList();
121:
122:                scan();
123:
124:            }
125:
126:            /* ------------------------------------------------------------ */
127:            /** Scan for webapplications.
128:             * 
129:             * @throws Exception
130:             */
131:            public void scan() throws Exception {
132:                if (_contexts == null)
133:                    throw new IllegalArgumentException("No HandlerContainer");
134:
135:                Resource r = Resource.newResource(_webAppDir);
136:                if (!r.exists())
137:                    throw new IllegalArgumentException(
138:                            "No such webapps resource " + r);
139:
140:                if (!r.isDirectory())
141:                    throw new IllegalArgumentException(
142:                            "Not directory webapps resource " + r);
143:
144:                String[] files = r.list();
145:
146:                files: for (int f = 0; files != null && f < files.length; f++) {
147:                    String context = files[f];
148:
149:                    if (context.equalsIgnoreCase("CVS/")
150:                            || context.equalsIgnoreCase("CVS")
151:                            || context.startsWith("."))
152:                        continue;
153:
154:                    Resource app = r.addPath(r.encode(context));
155:
156:                    if (context.toLowerCase().endsWith(".war")
157:                            || context.toLowerCase().endsWith(".jar")) {
158:                        context = context.substring(0, context.length() - 4);
159:                        Resource unpacked = r.addPath(context);
160:                        if (unpacked != null && unpacked.exists()
161:                                && unpacked.isDirectory())
162:                            continue;
163:                    } else if (!app.isDirectory())
164:                        continue;
165:
166:                    if (context.equalsIgnoreCase("root")
167:                            || context.equalsIgnoreCase("root/"))
168:                        context = "/";
169:                    else
170:                        context = "/" + context;
171:                    if (context.endsWith("/") && context.length() > 0)
172:                        context = context.substring(0, context.length() - 1);
173:
174:                    // Check the context path has not already been added or the webapp itself is not already deployed
175:                    if (!_allowDuplicates) {
176:                        Handler[] installed = _contexts
177:                                .getChildHandlersByClass(ContextHandler.class);
178:                        for (int i = 0; i < installed.length; i++) {
179:                            ContextHandler c = (ContextHandler) installed[i];
180:
181:                            if (context.equals(c.getContextPath()))
182:                                continue files;
183:
184:                            if (c.getBaseResource() != null
185:                                    && c.getBaseResource().getFile()
186:                                            .getAbsolutePath().equals(
187:                                                    app.getFile()
188:                                                            .getAbsolutePath()))
189:                                continue files;
190:
191:                        }
192:                    }
193:
194:                    // create a webapp
195:                    WebAppContext wah = null;
196:                    if (_contexts instanceof  ContextHandlerCollection
197:                            && WebAppContext.class
198:                                    .isAssignableFrom(((ContextHandlerCollection) _contexts)
199:                                            .getContextClass())) {
200:                        try {
201:                            wah = (WebAppContext) ((ContextHandlerCollection) _contexts)
202:                                    .getContextClass().newInstance();
203:                        } catch (Exception e) {
204:                            throw new Error(e);
205:                        }
206:                    } else {
207:                        wah = new WebAppContext();
208:                    }
209:
210:                    // configure it
211:                    wah.setContextPath(context);
212:                    if (_configurationClasses != null)
213:                        wah.setConfigurationClasses(_configurationClasses);
214:                    if (_defaultsDescriptor != null)
215:                        wah.setDefaultsDescriptor(_defaultsDescriptor);
216:                    wah.setExtractWAR(_extract);
217:                    wah.setWar(app.toString());
218:                    wah.setParentLoaderPriority(_parentLoaderPriority);
219:
220:                    // add it
221:                    _contexts.addHandler(wah);
222:                    _deployed.add(wah);
223:
224:                    if (_contexts.isStarted())
225:                        _contexts.start(); // TODO Multi exception
226:                }
227:            }
228:
229:            public void doStop() throws Exception {
230:                for (int i = _deployed.size(); i-- > 0;) {
231:                    WebAppContext wac = (WebAppContext) _deployed.get(i);
232:                    wac.stop();// TODO Multi exception
233:                }
234:            }
235:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.