henning     2003/02/27 06:53:47

  Modified:    src/java/org/apache/turbine Turbine.java
  Log:
  Remove all the various webserver information member variables and
  replace them with a slick ServerData structure.
  
  Revision  Changes    Path
  1.26      +42 -24    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.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- Turbine.java      9 Feb 2003 22:39:40 -0000       1.25
  +++ Turbine.java      27 Feb 2003 14:53:47 -0000      1.26
  @@ -94,10 +94,13 @@
   
   import org.apache.turbine.util.RunData;
   import org.apache.turbine.util.RunDataFactory;
  +import org.apache.turbine.util.ServerData;
   import org.apache.turbine.util.TurbineConfig;
   
   import org.apache.turbine.util.security.AccessControlList;
   
  +import org.apache.turbine.util.uri.URIConstants;
  +
   /**
    * Turbine is the main servlet for the entire system. It is <code>final</code>
    * because you should <i>not</i> ever need to subclass this servlet.  If you
  @@ -167,6 +170,9 @@
        */
       private static boolean firstDoGet = true;
   
  +    /** Keep all the properties of the web server in a convenient data structure */
  +    private static ServerData serverData = null;
  +
       /**
        * The base from which the Turbine application
        * will operate.
  @@ -200,18 +206,6 @@
       private static Log log = LogFactory.getLog(Turbine.class);
   
       /**
  -     * Server information. This information needs to
  -     * be made available to processes that do not have
  -     * access to RunData and the ServletService doesn't
  -     * seem to be working in all cases.
  -     */
  -    private static String serverName;
  -    private static String serverScheme;
  -    private static String serverPort;
  -    private static String scriptName;
  -    private static String contextPath;
  -
  -    /**
        * This init method will load the default resources from a
        * properties file.
        *
  @@ -502,7 +496,7 @@
        */
       public static String getServerName()
       {
  -        return serverName;
  +        return getDefaultServerData().getServerName();
       }
   
       /**
  @@ -512,7 +506,7 @@
        */
       public static String getServerScheme()
       {
  -        return serverScheme;
  +        return getDefaultServerData().getServerScheme();
       }
   
       /**
  @@ -522,7 +516,7 @@
        */
       public static String getServerPort()
       {
  -        return serverPort;
  +        return Integer.toString(getDefaultServerData().getServerPort());
       }
   
       /**
  @@ -534,7 +528,7 @@
        */
       public static String getScriptName()
       {
  -        return scriptName;
  +        return getDefaultServerData().getScriptName();
       }
   
       /**
  @@ -544,7 +538,32 @@
        */
       public static String getContextPath()
       {
  -        return contextPath;
  +        return getDefaultServerData().getContextPath();
  +    }
  +
  +    /**
  +     * Return all the Turbine Servlet information (Server Name, Port,
  +     * Scheme in a ServerData structure. This is generated from the
  +     * values set when initializing the Turbine and may not be correct
  +     * if you're running in a clustered structure. This might be used
  +     * if you need a DataURI and have no RunData object handy-
  +     *
  +     * @return An initialized ServerData object
  +     *
  +     */
  +    public static ServerData getDefaultServerData()
  +    {
  +        if(serverData == null)
  +        {
  +            log.error("ServerData Information requested from Turbine before first 
request!");
  +            // Will be overwritten once the first request is run;
  +            serverData = new ServerData(null,
  +                                        URIConstants.HTTP_PORT,
  +                                        URIConstants.HTTP,
  +                                        null,
  +                                        null);
  +        }
  +        return serverData;
       }
   
       /**
  @@ -958,15 +977,14 @@
        */
       public static synchronized void saveServletInfo(RunData data)
       {
  -        serverName = data.getRequest().getServerName();
  -        serverPort = new Integer(data.getRequest().getServerPort()).toString();
  -        serverScheme = data.getRequest().getScheme();
  -        scriptName = applicationRoot + data.getRequest().getServletPath();
  -
           // Store the context path for tools like ContentURI and
           // the UIManager that use webapp context path information
           // for constructing URLs.
  -        contextPath = data.getRequest().getContextPath();
  +
  +        //
  +        // Bundle all the information above up into a convenient structure
  +        //
  +        serverData = (ServerData) data.getServerData().clone();
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to