You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by "Hoang, Hai" <Ha...@coair.com> on 2002/03/27 18:24:43 UTC
Initialize Torque In Tomcat
You can use the following class to initialize the decoupled torque with
Tomcat.
Make sure you've the listener in the web.xml
<listener>
<listener-class>com.htg.base.listener.TurbineContextListener</listener-class
>
</listener>.
package com.htg.base.listener;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.torque.Torque;
import org.apache.fulcrum.*;
import org.apache.stratum.configuration.*;
public final class TurbineContextListener
implements ServletContextListener
{
public void contextInitialized(ServletContextEvent event)
{
/* This method is called when the servlet context is
initialized(when the Web Application is deployed).
You can initialize servlet context related data
here.
In this case we initializing Torque
*/
System.out.println("initializing torque...");
String webappRoot =
event.getServletContext().getRealPath("");
try
{
Torque.init(webappRoot +
"/WEB-INF/conf/Torque.properties");
}
catch (Exception e)
{
e.printStackTrace();
}
System.out.println("initializing fulcrum...");
try
{
Configuration configuration = (Configuration) new
PropertiesConfiguration(
webappRoot + "/WEB-INF/conf/fulcrum.properties");
ServiceManager serviceManager = TurbineServices.getManager();
serviceManager.setApplicationRoot(webappRoot);
serviceManager.setConfiguration(configuration);
serviceManager.init();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void contextDestroyed(ServletContextEvent event)
{
/* This method is invoked when the Servlet Context
(the Web Application) is undeployed or
WebLogic Server shuts down.
*/
System.out.println("destroying context");
}
}