Example #1
0
  private TeaServletEngine createTeaServletEngine() throws ServletException {

    TeaServletEngineImpl engine;
    if (mProperties.getBoolean("autocompile", false)) {
      engine = new TeaServletEngineImplDev();
    } else {
      engine = new TeaServletEngineImpl();
    }

    Object tsea = mServletContext.getAttribute(ENGINE_ATTR);

    if (tsea == null || !(tsea instanceof TeaServletEngine[])) {
      tsea = new TeaServletEngine[] {engine};
    } else {
      TeaServletEngine[] old_tsea = (TeaServletEngine[]) tsea;
      int old_length = old_tsea.length;
      tsea = new TeaServletEngine[old_length + 1];
      int i;
      for (i = 0; i < old_length; i++) {
        ((TeaServletEngine[]) tsea)[i + 1] = old_tsea[i];
      }
      ((TeaServletEngine[]) tsea)[0] = engine;
    }
    mServletContext.setAttribute(ENGINE_ATTR, tsea);

    return engine;
  }
Example #2
0
  /**
   * Initializes the TeaServlet. Creates the logger and loads the user's application.
   *
   * @param config the servlet config
   */
  public void init(ServletConfig config) throws ServletException {
    super.init(config);
    mServletConfig = config;

    config.getServletContext().log("Initializing TeaServlet...");

    String ver = System.getProperty("java.version");
    if (ver.startsWith("0.") || ver.startsWith("1.2") || ver.startsWith("1.3")) {
      config.getServletContext().log("The TeaServlet requires Java 1.4 or higher to run properly");
    }

    mServletContext = setServletContext(config);
    mServletName = setServletName(config);

    mProperties = new PropertyMap();
    mSubstitutions = SubstitutionFactory.getDefaults();
    mResourceFactory = new TeaServletResourceFactory(config.getServletContext(), mSubstitutions);

    Enumeration<?> e = config.getInitParameterNames();
    while (e.hasMoreElements()) {
      String key = (String) e.nextElement();
      String value = SubstitutionFactory.substitute(config.getInitParameter(key));

      if (key.equals("debug")) {
        mDebugEnabled = Boolean.parseBoolean(value);
        continue;
      }

      mProperties.put(key, value);
    }

    loadDefaults();
    discoverProperties();
    createListeners();
    createLog(mServletContext);
    mLog.applyProperties(mProperties.subMap("log"));
    createMemoryLog(mLog);

    mInstrumentationEnabled = mProperties.getBoolean("instrumentation.enabled", true);

    Initializer initializer = new Initializer();
    if (mProperties.getBoolean("startup.background", false)) {
      mInitializer = Executors.newSingleThreadExecutor().submit(initializer);
    } else {
      initializer.call();
    }
  }