View Javadoc

    1   // ========================================================================
    2   // Copyright 2003-2005 Mort Bay Consulting Pty. Ltd.
    3   // ------------------------------------------------------------------------
    4   // Licensed under the Apache License, Version 2.0 (the "License");
    5   // you may not use this file except in compliance with the License.
    6   // You may obtain a copy of the License at
    7   // http://www.apache.org/licenses/LICENSE-2.0
    8   // Unless required by applicable law or agreed to in writing, software
    9   // 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   * Configure class path from a WEB-INF directory found within a contexts resource base.
    21   *
    22   * @author gregw
    23   */
    24  public class WebInfConfiguration implements Configuration
    25  {
    26      protected WebAppContext _context;
    27
    28      public WebInfConfiguration()
    29      {
    30      }
    31
    32      /* ------------------------------------------------------------------------------- */
    33      public void setWebAppContext (WebAppContext context)
    34      {
    35          _context = context;
    36      }
    37
    38      /* ------------------------------------------------------------------------------- */
    39      public WebAppContext getWebAppContext()
    40      {
    41          return _context;
    42      }
    43
    44      /* ------------------------------------------------------------------------------- */
    45      /** Configure ClassPath.
    46       * This method is called before the context ClassLoader is created.
    47       * Paths and libraries should be added to the context using the setClassPath,
    48       * addClassPath and addClassPaths methods.  The default implementation looks
    49       * for WEB-INF/classes, WEB-INF/lib/*.zip and WEB-INF/lib/*.jar
    50       * @throws Exception
    51       */
    52      public  void configureClassLoader()
    53      throws Exception
    54      {
    55          //cannot configure if the context is already started
    56          if (_context.isStarted())
    57          {
    58              if (Log.isDebugEnabled()){Log.debug("Cannot configure webapp after it is started");}
    59              return;
    60          }
    61
    62          Resource web_inf=_context.getWebInf();
    63
    64          // Add WEB-INF classes and lib classpaths
    65          if (web_inf != null && web_inf.isDirectory() && _context.getClassLoader() instanceof WebAppClassLoader)
    66          {
    67              // Look for classes directory
    68              Resource classes= web_inf.addPath("classes/");
    69              if (classes.exists())
    70                  ((WebAppClassLoader)_context.getClassLoader()).addClassPath(classes.toString());
    71
    72              // Look for jars
    73              Resource lib= web_inf.addPath("lib/");
    74              if (lib.exists() || lib.isDirectory())
    75                  ((WebAppClassLoader)_context.getClassLoader()).addJars(lib);
    76          }
    77
    78       }
    79
    80      /* ------------------------------------------------------------------------------- */
    81      public void configureDefaults() throws Exception
    82      {
    83      }
    84
    85      /* ------------------------------------------------------------------------------- */
    86      public void configureWebApp() throws Exception
    87      {
    88      }
    89
    90      /* ------------------------------------------------------------------------------- */
    91      public void deconfigureWebApp() throws Exception
    92      {
    93      }
    94
    95  }