1 23 package org.enhydra.barracuda.discRack; 24 25 import java.io.*; 26 import java.util.*; 27 import java.net.*; 28 import javax.servlet.*; 29 import javax.servlet.http.*; 30 31 import com.lutris.appserver.server.Application; 32 import com.lutris.appserver.server.Enhydra; 33 import com.lutris.appserver.server.StandardApplication; 34 import com.lutris.logging.StandardLogger; 35 import com.lutris.util.Config; 36 import com.lutris.util.ConfigFile; 37 38 import org.enhydra.barracuda.core.event.*; 39 import org.enhydra.barracuda.core.event.helper.*; 40 import org.apache.log4j.*; 41 42 import org.enhydra.barracuda.discRack.pres.screens.*; 43 45 47 76 public class DiscRackGateway extends ApplicationGateway { 77 78 public static final String ENHYDRA_APPLICATION = DiscRackGateway.class.getName()+"EnhydraApplication"; 80 protected static Logger logger = Logger.getLogger(DiscRackGateway.class.getName()); 81 82 private static final String CONFIG_FILE = "ConfFile"; 84 private LoginScreen lnkLoginScreen; private RegistrationScreen lnkRegistrationScreen; private DiscScreen lnkDiscScreen; 89 90 91 96 public void initializeLocal() { 97 setUpEnhydraApplication(); 100 101 this.specifyEventGateways(new LoginScreen()); 103 this.specifyEventGateways(new RegistrationScreen()); 104 this.specifyEventGateways(new DiscScreen()); 105 } 106 107 108 115 private void setUpEnhydraApplication() { 117 ServletContext context = this.getServletConfig().getServletContext(); 119 Application app = (Application) context.getAttribute(ENHYDRA_APPLICATION); 120 121 if (app==null) { 123 try { 124 if (logger.isDebugEnabled()) logger.debug("Creating underlying Enhydra Application"); 126 app = new DiscRackApplication(); 127 128 app.setLogChannel(new StandardLogger(true).getChannel("")); 130 131 String configFile = this.getServletConfig().getInitParameter(CONFIG_FILE); 133 134 if (logger.isDebugEnabled()) logger.debug("Config:"+configFile); 135 136 140 String is = context.getRealPath(configFile); 141 File isf = new File (is); 142 143 Config conf = new ConfigFile(isf).getConfig(); 144 if (logger.isDebugEnabled()) logger.debug("Got Config file:"+conf); 145 146 app.startup(conf); 148 if (logger.isDebugEnabled()) logger.debug("Started app:"+app); 149 150 context.setAttribute(ENHYDRA_APPLICATION, app); 152 } catch(Exception e) { 153 System.out.println("Error setting up Enhydra Application:"+e); 154 e.printStackTrace(); 155 } 156 } 157 } 158 159 162 public void handleDefault (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 163 ServletContext context = this.getServletConfig().getServletContext(); 164 Application app = (Application) context.getAttribute(ENHYDRA_APPLICATION); 165 try { 166 if (logger.isDebugEnabled()) logger.debug("\n\n"+req.getRequestURI()+" @"+Integer.toHexString(req.hashCode())); 167 Enhydra.register(app); 168 super.handleDefault(req, resp); 169 } finally { 170 Enhydra.unRegister(); 171 } 172 } 173 174 class DiscRackApplication extends StandardApplication { 175 176 } 177 178 } 179 | Popular Tags |