Save This Page
Home » openejb-3.1.2-src » org.apache.openejb.tomcat » loader » [javadoc | source]
    1   /**
    2    *
    3    * Licensed to the Apache Software Foundation (ASF) under one or more
    4    * contributor license agreements.  See the NOTICE file distributed with
    5    * this work for additional information regarding copyright ownership.
    6    * The ASF licenses this file to You under the Apache License, Version 2.0
    7    * (the "License"); you may not use this file except in compliance with
    8    * the License.  You may obtain a copy of the License at
    9    *
   10    *     http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    *  Unless required by applicable law or agreed to in writing, software
   13    *  distributed under the License is distributed on an "AS IS" BASIS,
   14    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   15    *  See the License for the specific language governing permissions and
   16    *  limitations under the License.
   17    */
   18   package org.apache.openejb.tomcat.loader;
   19   
   20   import java.io.File;
   21   import java.util.Properties;
   22   
   23   import org.apache.openejb.loader.Embedder;
   24   import org.apache.openejb.loader.SystemInstance;
   25   
   26   /**
   27    * This class should only be loadded and used via reflection from TomcatEmbedder. 
   28    */
   29   class TomcatHook {
   30       @SuppressWarnings({"UnusedDeclaration"})
   31       private static void hook(Properties properties) {
   32           // verify properties and make sure it contains the openejb.war property
   33           if (properties == null) throw new NullPointerException("properties is null");
   34                   if (!properties.containsKey("openejb.war")) {
   35               throw new IllegalArgumentException("properties must contain the openejb.war property");
   36           }
   37           // get the openejb directory (under webapps) using the openejb.war property
   38           File openejbWar = new File(properties.getProperty("openejb.war"));
   39           if (!openejbWar.isDirectory()) {
   40               throw new IllegalArgumentException("openejb.war is not a directory: " + openejbWar);
   41           }
   42           // if SystemInstance is already initialized, then return
   43           if (SystemInstance.isInitialized()) {
   44               return;
   45           }
   46           // set the openejb.loader property to tomcat-system
   47           properties.setProperty("openejb.loader", "tomcat-system");
   48           
   49           // get the value of catalina.home and set it to openejb.home
   50           String catalinaHome = System.getProperty("catalina.home");
   51           properties.setProperty("openejb.home", catalinaHome);
   52           System.setProperty("openejb.home", catalinaHome);
   53   
   54           //get the value of catalina.base and set it to openejb.base
   55           String catalinaBase = System.getProperty("catalina.base");
   56           properties.setProperty("openejb.base", catalinaBase);
   57           System.setProperty("openejb.base", catalinaBase);
   58           
   59           //TODO: why do we need this, this was already set. Thats how we create the File openejbWar
   60           System.setProperty("openejb.war", openejbWar.getAbsolutePath());
   61           // set the property openejb.libs to contain the absolute path of the lib directory of openejb webapp
   62           File libDir = new File(openejbWar, "lib");
   63           String libPath = libDir.getAbsolutePath();
   64           properties.setProperty("openejb.libs", libPath);
   65   
   66           // System.setProperty("tomcat.version", "x.y.z.w");
   67           // System.setProperty("tomcat.built", "mmm dd yyyy hh:mm:ss");
   68           // set the System properties, tomcat.version, tomcat.built
   69           try {
   70               Properties tomcatServerInfo = new Properties();
   71               ClassLoader classLoader = TomcatHook.class.getClassLoader();
   72               tomcatServerInfo.load(classLoader.getResourceAsStream("org/apache/catalina/util/ServerInfo.properties"));
   73   
   74               String serverNumber = tomcatServerInfo.getProperty("server.number");
   75               if (serverNumber == null) {
   76                   // Tomcat5 only has server.info
   77                   String serverInfo = tomcatServerInfo.getProperty("server.info");
   78                   if (serverInfo != null) {
   79                       int slash = serverInfo.indexOf('/');
   80                       serverNumber = serverInfo.substring(slash + 1);
   81                   }
   82               }
   83               if (serverNumber != null) {
   84                   System.setProperty("tomcat.version", serverNumber);
   85               }
   86   
   87               String serverBuilt = tomcatServerInfo.getProperty("server.built");
   88               if (serverBuilt != null) {
   89                   System.setProperty("tomcat.built", serverBuilt);
   90               }
   91           } catch (Throwable e) {
   92           }
   93   
   94           try {
   95               // create the loader
   96               SystemInstance.init(properties);
   97               Embedder embedder = new Embedder("org.apache.openejb.tomcat.catalina.TomcatLoader");
   98               embedder.init(properties);
   99           } catch (Exception e) {
  100               e.printStackTrace();
  101           }
  102       }
  103   }

Save This Page
Home » openejb-3.1.2-src » org.apache.openejb.tomcat » loader » [javadoc | source]