You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by mp...@apache.org on 2002/02/08 16:06:45 UTC

cvs commit: jakarta-turbine-2/src/java/org/apache/turbine Turbine.java

mpoeschl    02/02/08 07:06:45

  Modified:    src/java/org/apache/turbine Turbine.java
  Log:
  add loadSubsystems()
  it works with torque :-)
  fulcrum is next ...
  
  Revision  Changes    Path
  1.9       +87 -33    jakarta-turbine-2/src/java/org/apache/turbine/Turbine.java
  
  Index: Turbine.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/Turbine.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Turbine.java	15 Nov 2001 23:09:36 -0000	1.8
  +++ Turbine.java	8 Feb 2002 15:06:45 -0000	1.9
  @@ -3,7 +3,7 @@
   /* ====================================================================
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -25,13 +25,13 @@
    *    Alternately, this acknowledgment may appear in the software itself,
    *    if and wherever such third-party acknowledgments normally appear.
    *
  - * 4. The names "Apache" and "Apache Software Foundation" and 
  - *    "Apache Turbine" must not be used to endorse or promote products 
  - *    derived from this software without prior written permission. For 
  + * 4. The names "Apache" and "Apache Software Foundation" and
  + *    "Apache Turbine" must not be used to endorse or promote products
  + *    derived from this software without prior written permission. For
    *    written permission, please contact apache@apache.org.
    *
    * 5. Products derived from this software may not be called "Apache",
  - *    "Apache Turbine", nor may "Apache" appear in their name, without 
  + *    "Apache Turbine", nor may "Apache" appear in their name, without
    *    prior written permission of the Apache Software Foundation.
    *
    * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  @@ -58,11 +58,16 @@
   import java.io.PrintWriter;
   import java.io.File;
   import java.util.Enumeration;
  +import java.util.Vector;
   import javax.servlet.ServletConfig;
   import javax.servlet.ServletException;
   import javax.servlet.http.HttpServlet;
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
  +import org.apache.stratum.configuration.Configuration;
  +import org.apache.stratum.configuration.PropertiesConfiguration;
  +import org.apache.stratum.lifecycle.Configurable;
  +import org.apache.stratum.lifecycle.Initializable;
   import org.apache.turbine.modules.ActionLoader;
   import org.apache.turbine.modules.PageLoader;
   import org.apache.turbine.modules.actions.sessionvalidator.SessionValidator;
  @@ -75,6 +80,7 @@
   import org.apache.turbine.services.TurbineServices;
   import org.apache.turbine.services.resources.TurbineResources;
   import org.apache.turbine.services.logging.LoggingService;
  +import org.apache.turbine.services.servlet.TurbineServlet;
   import org.apache.turbine.services.template.TurbineTemplate;
   
   /**
  @@ -109,9 +115,10 @@
    * @author <a href="mailto:krzewski@e-point.pl">Rafal Krzewski</a>
    * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
    * @author <a href="mailto:sean@informage.net">Sean Legassick</a>
  - * @version $Id: Turbine.java,v 1.8 2001/11/15 23:09:36 jvanzyl Exp $
  + * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
  + * @version $Id: Turbine.java,v 1.9 2002/02/08 15:06:45 mpoeschl Exp $
    */
  -public class Turbine 
  +public class Turbine
       extends HttpServlet
       implements TurbineConstants
   {
  @@ -172,7 +179,7 @@
       private static String serverScheme;
       private static String serverPort;
       private static String contextPath;
  -    
  +
       /**
        * This init method will load the default resources from a
        * properties file.
  @@ -203,35 +210,38 @@
                   // to be developed from CVS. This feature will carry over
                   // into 3.0.
                   applicationRoot = config.getInitParameter(APPLICATION_ROOT);
  -                
  +
                   if (applicationRoot == null || applicationRoot.equals("webContext"))
                   {
                       applicationRoot = config.getServletContext().getRealPath("");
  -                }                    
  -                
  +                }
  +
                   // Set the webapp root. The applicationRoot and the
                   // webappRoot will be the same when the application is
                   // deployed, but during development they may have
                   // different values.
                   webappRoot = config.getServletContext().getRealPath("");
  -                
  +
                   // Create any directories that need to be setup for
                   // a running Turbine application.
                   createRuntimeDirectories();
  -                
  +
                   // Initialize essential services (Resources & Logging)
                   services.initPrimaryServices(config);
  -                
  +
                   // Now that TurbineResources is setup, we want to insert
                   // the applicationRoot and webappRoot into the resources
                   // so that ${applicationRoot} and ${webappRoot} can be
                   // use in the TRP.
                   TurbineResources.setProperty(APPLICATION_ROOT, applicationRoot);
                   TurbineResources.setProperty(WEBAPP_ROOT, webappRoot);
  -                
  +
                   // Initialize other services that require early init
                   services.initServices(config, false);
   
  +                // Initialize subsystems like torque and fulcrum
  +                loadSubsystems();
  +
                   log ("Turbine: init() Ready to Rumble!");
               }
               catch ( Exception e )
  @@ -248,13 +258,12 @@
        * runtime. Right now this includes:
        *
        * i) directories for logging
  -     *
        */
       private static void createRuntimeDirectories()
       {
           // Create the logging directory
           File logDir = new File(webappRoot + "/logs");
  -        
  +
           if (logDir.exists() == false)
           {
               if(logDir.mkdirs() == false)
  @@ -281,12 +290,12 @@
                       serverName = data.getRequest().getServerName();
                       serverPort = Integer.toString(data.getRequest().getServerPort());
                       serverScheme = data.getRequest().getScheme();
  -                    
  +
                       // Store the context path for tools like ContentURI and
                       // the UIManager that use webapp context path information
                       // for constructing URLs.
                       contextPath = data.getRequest().getContextPath();
  -                    
  +
                       log("Turbine: Starting HTTP initialization of services");
                       TurbineServices.getInstance().initServices(data);
                       log("Turbine: Completed HTTP initialization of services");
  @@ -389,8 +398,8 @@
                   .getInstance().getInstance(TurbineResources.getString(
                       "action.sessionvalidator"));
   
  -            // if this is the redirected stage of the initial request, 
  -            // check that the session is now not new. 
  +            // if this is the redirected stage of the initial request,
  +            // check that the session is now not new.
               // If it is not, then redirect back to the
               // original URL (i.e. remove the "redirected" pathinfo)
               if (data.getParameters()
  @@ -447,7 +456,7 @@
                           duri.addPathInfo((String)key, (String)value );
                       }
   
  -                    // add a dummy bit of path info to fool browser into 
  +                    // add a dummy bit of path info to fool browser into
                       // thinking this is a new URL
                       if (!data.getParameters()
                           .containsKey(REDIRECTED_PATHINFO_NAME))
  @@ -455,15 +464,15 @@
                           duri.addPathInfo(REDIRECTED_PATHINFO_NAME, "true");
                       }
   
  -                    // as the session is new take this opportunity to 
  +                    // as the session is new take this opportunity to
                       // set the session timeout if specified in TR.properties
  -                    int timeout = 
  +                    int timeout =
                           TurbineResources.getInt("session.timeout", -1);
  -                    
  +
                       if (timeout != -1)
                       {
                           data.getSession().setMaxInactiveInterval(timeout);
  -                    }                        
  +                    }
   
                       data.getResponse().sendRedirect( duri.toString() );
                       return;
  @@ -542,9 +551,9 @@
               // security purposes.  You should really never need more
               // than just the default page.  If you do, add logic to
               // DefaultPage to do what you want.
  -            
  +
               String defaultPage = TurbineTemplate.getDefaultPageName(data);
  -            
  +
               if (defaultPage == null)
               {
                   /*
  @@ -561,7 +570,7 @@
                   defaultPage = TurbineResources.getString(
                       "page.default", "DefaultPage");
               }
  -            
  +
               PageLoader.getInstance().exec(data, defaultPage);
   
               // If a module has set data.acl = null, remove acl from
  @@ -708,7 +717,7 @@
   
               PageLoader.getInstance()
                   .exec(data,
  -                      TurbineResources.getString("page.default", 
  +                      TurbineResources.getString("page.default",
                         "DefaultPage"));
   
               data.getResponse().setContentType( data.getContentType() );
  @@ -775,8 +784,8 @@
       public static String getApplicationRoot()
       {
           return applicationRoot;
  -    }        
  -    
  +    }
  +
       /**
        * Used to get the real path of configuration and resource
        * information. This can be used by an app being
  @@ -791,7 +800,7 @@
           {
               path = path.substring(1);
           }
  -        
  +
           return applicationRoot + "/" + path;
       }
   
  @@ -815,5 +824,50 @@
       {
           services.notice(message);
           services.error(t);
  +    }
  +
  +    /**
  +     * load subsystems like torque and fulcrum.
  +     */
  +    private void loadSubsystems()
  +    {
  +        // name of the subsystem
  +        String sysName;
  +        // name of the class to load
  +        String sysClassName;
  +        // name of the config file used to configure the subsystem
  +        String sysConfig;
  +
  +        // get name of all subsystems to be loaded
  +        Vector systems = TurbineResources.getVector("subsystem.name");
  +
  +        for (int i = 0; i < systems.size(); i++)
  +        {
  +            try
  +            {
  +                sysName = (String) systems.get(i);
  +                sysClassName = TurbineResources.getString("subsystem."
  +                        + sysName + ".classname");
  +                sysConfig = TurbineServlet.getRealPath(
  +                        TurbineResources.getString("subsystem."+ sysName
  +                        + ".config"));
  +
  +                Log.notice("loading subsystem " + sysName + " - class: "
  +                        + sysClassName + " with config: " + sysConfig);
  +
  +                Object sys = Class.forName(sysClassName).newInstance();
  +
  +                // configure subsystem using the defined config file
  +                ((Configurable) sys).configure( (Configuration)
  +                        new PropertiesConfiguration(sysConfig));
  +
  +                // initialize subsystem
  +                ((Initializable) sys).initialize();
  +            }
  +            catch (Exception ex)
  +            {
  +                Log.error(sysName + " could not be initialized!", ex);
  +            }
  +        }
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>