01: // ========================================================================
02: // Copyright 2003-2005 Mort Bay Consulting Pty. Ltd.
03: // ------------------------------------------------------------------------
04: // Licensed under the Apache License, Version 2.0 (the "License");
05: // you may not use this file except in compliance with the License.
06: // You may obtain a copy of the License at
07: // http://www.apache.org/licenses/LICENSE-2.0
08: // Unless required by applicable law or agreed to in writing, software
09: // distributed under the License is distributed on an "AS IS" BASIS,
10: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11: // See the License for the specific language governing permissions and
12: // limitations under the License.
13: // ========================================================================
14: package org.mortbay.jetty.webapp;
15:
16: import org.mortbay.log.Log;
17: import org.mortbay.resource.Resource;
18:
19: /* ------------------------------------------------------------------------------- */
20: /**
21: * Configure class path from a WEB-INF directory found within a contexts resource base.
22: *
23: * @author gregw
24: */
25: public class WebInfConfiguration implements Configuration {
26: protected WebAppContext _context;
27:
28: public WebInfConfiguration() {
29: }
30:
31: /* ------------------------------------------------------------------------------- */
32: public void setWebAppContext(WebAppContext context) {
33: _context = context;
34: }
35:
36: /* ------------------------------------------------------------------------------- */
37: public WebAppContext getWebAppContext() {
38: return _context;
39: }
40:
41: /* ------------------------------------------------------------------------------- */
42: /** Configure ClassPath.
43: * This method is called before the context ClassLoader is created.
44: * Paths and libraries should be added to the context using the setClassPath,
45: * addClassPath and addClassPaths methods. The default implementation looks
46: * for WEB-INF/classes, WEB-INF/lib/*.zip and WEB-INF/lib/*.jar
47: * @throws Exception
48: */
49: public void configureClassLoader() throws Exception {
50: //cannot configure if the context is already started
51: if (_context.isStarted()) {
52: if (Log.isDebugEnabled()) {
53: Log
54: .debug("Cannot configure webapp after it is started");
55: }
56: return;
57: }
58:
59: Resource web_inf = _context.getWebInf();
60:
61: // Add WEB-INF classes and lib classpaths
62: if (web_inf != null
63: && web_inf.isDirectory()
64: && _context.getClassLoader() instanceof WebAppClassLoader) {
65: // Look for classes directory
66: Resource classes = web_inf.addPath("classes/");
67: if (classes.exists())
68: ((WebAppClassLoader) _context.getClassLoader())
69: .addClassPath(classes.toString());
70:
71: // Look for jars
72: Resource lib = web_inf.addPath("lib/");
73: if (lib.exists() || lib.isDirectory())
74: ((WebAppClassLoader) _context.getClassLoader())
75: .addJars(lib);
76: }
77:
78: }
79:
80: /* ------------------------------------------------------------------------------- */
81: public void configureDefaults() throws Exception {
82: }
83:
84: /* ------------------------------------------------------------------------------- */
85: public void configureWebApp() throws Exception {
86: }
87:
88: /* ------------------------------------------------------------------------------- */
89: public void deconfigureWebApp() throws Exception {
90: }
91:
92: }
|