/** Copyright (c) Oracle Corporation 1998. All Rights Reserved. */ package oracle.jbo.html.jsp; import java.io.PrintWriter; import java.io.OutputStream; import java.io.FileInputStream; import java.io.InputStream; import java.util.Vector; import java.util.Enumeration; import java.util.StringTokenizer; import java.util.Properties; import java.util.Hashtable; import javax.naming.*; import oracle.jbo.*; import oracle.jbo.domain.TypeFactory; import oracle.jdeveloper.html.*; import oracle.jdeveloper.cm.ConnectionManager; import oracle.jdeveloper.cm.ConnectionDescriptor; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.jsp.*; import oracle.jbo.common.ampool.*; /** ** This class provides the main interface for DataWebBeans to use the Application Module Pool. ** ** View implementation of JSPApplicationRegistry ** ** @author Juan Oropeza ** @version PUBLIC ** **/ public class JSPApplicationRegistry extends WebBeanImpl { static JSPApplicationRegistry instance = new JSPApplicationRegistry(); static PoolMgr poolManager = PoolMgr.getInstance(); /** ** Constructor, this should not be called directly **/ public JSPApplicationRegistry() { } /** ** Returns the singleton instance of the registry class. **/ static public JSPApplicationRegistry getInstance() { return instance; } /** ** Returns the user data associated with the named pool. The user data is a convenient palce for storing ** and retrieving application-specific information shared by all application instances that are part of the ** named pool. **/ static synchronized public Hashtable getAppSettings(String sAppName) { ApplicationPool pool = poolManager.getPool(sAppName); return (Hashtable)pool.getUserData(); } /** ** This is a convenience method for returning an Application Module back to the pool. This method ** will find the ApplicationInstance associated with the Application Module and check it in to the pool. **/ static synchronized public void returnAppModuleInstance(String AppName , ApplicationModule am) { SessionTimeOutHandler handler = (SessionTimeOutHandler)getInstance().session.getValue(AppName + "_timeouthandler"); getInstance().session.removeValue(AppName + "_timeouthandler"); } /** ** Locates the application pool and check out a new application module. You can use the ** returnAppModuleInstance() method to return the Application Module back to the pool. **/ static synchronized public ApplicationModule getApplication(String AppName) throws Exception { ApplicationPool pool = poolManager.getPool(AppName); ApplicationModule instance = pool.checkout(); SessionTimeOutHandler handler = new SessionTimeOutHandler(AppName , instance); getInstance().session.putValue(AppName + "_timeouthandler", handler); return instance; } /** ** Convenience method for defining a new application pool from a property file. This also transfers some system ** specific variables to the JSP Session object. **/ static synchronized public void registerApplicationFromPropertyFile(HttpSession session, String sPropFileName) { if(poolManager.isPoolCreated(sPropFileName)) return; registerApplicationFromPropertyFile(sPropFileName); Hashtable settings = getAppSettings(sPropFileName); int nTimeOut = 300; if (settings != null) { // see if we have a setting for the session timeout String sTimeOut; if(settings.get("HttpSessionTimeOut") != null) { sTimeOut = (String)settings.get("HttpSessionTimeOut"); if(sTimeOut != null) { nTimeOut = Integer.parseInt(sTimeOut); } } if(settings.get("ImageBase") != null) session.putValue("ImageBase", settings.get("ImageBase")); if(settings.get("CSSURL") != null) session.putValue("CSSURL",settings.get("CSSURL")); } try { if(session.getMaxInactiveInterval() != nTimeOut) { session.setMaxInactiveInterval(nTimeOut); System.err.println("*******" + sPropFileName + " - Session timeout is:" + nTimeOut); } } catch(java.lang.NoSuchMethodError ex) { System.err.println("*******" + sPropFileName + " - Session timeout using default value"); } // place default renderers into session, these will not be // exposed via config file session.putValue("oracle_ord_im_OrdImageDomain_Renderer", "oracle.ord.im.OrdBuildURL"); session.putValue("oracle_ord_im_OrdAudioDomain_Renderer","oracle.ord.im.OrdBuildURL"); session.putValue("oracle_ord_im_OrdVideoDomain_Renderer","oracle.ord.im.OrdBuildURL"); session.putValue("oracle_ord_im_OrdVirDomain_Renderer", "oracle.ord.im.OrdBuildURL"); session.putValue("oracle_ord_im_OrdImageDomain_EditRenderer", "oracle.ord.html.FileUploadField"); session.putValue("oracle_ord_im_OrdAudioDomain_EditRenderer", "oracle.ord.html.FileUploadField"); session.putValue("oracle_ord_im_OrdVideoDomain_EditRenderer", "oracle.ord.html.FileUploadField"); session.putValue("oracle_ord_im_OrdVirDomain_EditRenderer", "oracle.ord.html.FileUploadField"); } /** ** Creates a new application pool from the contents of a property file. Please look at the ConnectionInfo class ** for documentation of what should be contained in the property file. **/ static synchronized public void registerApplicationFromPropertyFile(String sPropFileName) { try { String sConnectUrl; String sAppModuleClass; if(!poolManager.isPoolCreated(sPropFileName)) { // open up the property file String sConfigPath = sPropFileName + ".properties"; // find the property file in the classpath System.out.println("Loading from CLASSPATH " + sConfigPath); InputStream in = ClassLoader.getSystemResourceAsStream(sConfigPath); if(in == null) { throw new RuntimeException("JSP Registry could not locate runtime property file:" + sConfigPath); } // load up the properties file Properties props = new Properties(); props.load(in); in.close(); ConnectionInfo connectInfo = new ConnectionInfo(props); ApplicationPool pool = poolManager.createPool(sPropFileName , connectInfo.getPoolClass(), connectInfo.getAppModuleClass(), connectInfo.getConnectionUrl(), connectInfo.getConnectionSettings()); pool.setUserName(connectInfo.sUserName); pool.setPassword(connectInfo.sPassword); pool.setUserData(props); } } catch (Exception ex) { ex.printStackTrace(); throw new RuntimeException(ex.toString()); } } }