KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mortbay > jetty > servlet > JettyWebConfiguration


1 //========================================================================
2
//$Id: JettyWebConfiguration.java,v 1.4 2005/11/18 17:54:05 gregwilkins Exp $
3
//Copyright 2000-2004 Mort Bay Consulting Pty. Ltd.
4
//------------------------------------------------------------------------
5
//Licensed under the Apache License, Version 2.0 (the "License");
6
//you may not use this file except in compliance with the License.
7
//You may obtain a copy of the License at
8
//http://www.apache.org/licenses/LICENSE-2.0
9
//Unless required by applicable law or agreed to in writing, software
10
//distributed under the License is distributed on an "AS IS" BASIS,
11
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//See the License for the specific language governing permissions and
13
//limitations under the License.
14
//========================================================================
15

16 package org.mortbay.jetty.servlet;
17
18 import org.apache.commons.logging.Log;
19 import org.mortbay.log.LogFactory;
20 import org.mortbay.http.ContextLoader;
21 import org.mortbay.jetty.servlet.WebApplicationContext.Configuration;
22 import org.mortbay.util.Resource;
23 import org.mortbay.xml.XmlConfiguration;
24
25
26 /**
27  *
28  * JettyWebConfiguration
29  *
30  * @author janb
31  * @version $Revision: 1.4 $ $Date: 2005/11/18 17:54:05 $
32  *
33  */

34 public class JettyWebConfiguration implements Configuration
35 {
36     private static Log log= LogFactory.getLog(JettyWebConfiguration.class);
37     private WebApplicationContext _context;
38
39     
40     /**
41      * @see org.mortbay.jetty.servlet.WebApplicationContext.Configuration#setWebApplicationContext(org.mortbay.jetty.servlet.WebApplicationContext)
42      */

43     public void setWebApplicationContext (WebApplicationContext context)
44     {
45        _context = context;
46     }
47
48     public WebApplicationContext getWebApplicationContext ()
49     {
50         return _context;
51     }
52     
53     /** configureClassPath
54      * Not used.
55      * @see org.mortbay.jetty.servlet.WebApplicationContext.Configuration#configureClassPath()
56      */

57     public void configureClassPath () throws Exception JavaDoc
58     {
59     }
60
61     /** configureDefaults
62      * Not used.
63      * @see org.mortbay.jetty.servlet.WebApplicationContext.Configuration#configureDefaults()
64      */

65     public void configureDefaults () throws Exception JavaDoc
66     {
67     }
68
69     /** configureWebApp
70      * Apply web-jetty.xml configuration
71      * @see org.mortbay.jetty.servlet.WebApplicationContext.Configuration#configureWebApp()
72      */

73     public void configureWebApp () throws Exception JavaDoc
74     {
75         //cannot configure if the _context is already started
76
if (_context.isStarted())
77         {
78             if (log.isDebugEnabled()){log.debug("Cannot configure webapp after it is started");};
79             return;
80         }
81         
82         if(log.isDebugEnabled())
83             log.debug("Configuring web-jetty.xml");
84         
85         Resource webInf=getWebApplicationContext().getWebInf();
86         // handle any WEB-INF descriptors
87
if(webInf!=null&&webInf.isDirectory())
88         {
89             // do jetty.xml file
90
Resource jetty=webInf.addPath("web-jetty.xml");
91             if(!jetty.exists())
92                 jetty=webInf.addPath("jetty-web.xml");
93             if(!getWebApplicationContext().isIgnoreWebJetty()&&jetty.exists())
94             {
95                 
96                 // Give permission to see Jetty classes
97
String JavaDoc[] old_server_classes = _context.getServerClasses();
98                 String JavaDoc[] server_classes = new String JavaDoc[1+(old_server_classes==null?0:old_server_classes.length)];
99                 server_classes[0]="-org.mortbay.";
100                 if (server_classes!=null)
101                     System.arraycopy(old_server_classes, 0, server_classes, 1, old_server_classes.length);
102                 
103                 try
104                 {
105                     _context.setServerClasses(server_classes);
106                     if(log.isDebugEnabled())
107                         log.debug("Configure: "+jetty);
108                     
109                     XmlConfiguration jetty_config=new XmlConfiguration(jetty.getURL());
110                     jetty_config.configure(getWebApplicationContext());
111                 }
112                 finally
113                 {
114                     if (_context.getServerClasses()==server_classes)
115                         _context.setServerClasses(old_server_classes);
116                 }
117             }
118         }
119         
120     }
121 }
122
Popular Tags