1 20 package org.enhydra.barracuda.examples.ex3; 21 22 import java.io.*; 23 import java.util.*; 24 import java.net.*; 25 import javax.servlet.*; 26 import javax.servlet.http.*; 27 28 import org.enhydra.barracuda.core.event.*; 29 import org.apache.log4j.*; 30 import org.enhydra.barracuda.examples.ex3.events.*; 31 33 34 45 public class TestScreen extends DefaultEventGateway { 46 47 protected static final Logger logger = Logger.getLogger(TestScreen.class.getName()); 49 50 private ListenerFactory levelFactory = new DefaultListenerFactory() {public BaseEventListener getInstance() {return new LevelHandler();} public String getListenerID() {return getID(LevelHandler.class);}}; 52 private ListenerFactory renderFactory = new DefaultListenerFactory() {public BaseEventListener getInstance() {return new RenderTestHandler();} public String getListenerID() {return getID(RenderTestHandler.class);}}; 53 54 56 59 public TestScreen() { 60 specifyLocalEventInterests(levelFactory, Level1Event.class); 62 specifyLocalEventInterests(levelFactory, Level2Event.class); 63 specifyLocalEventInterests(levelFactory, Level3Event.class); 64 specifyLocalEventInterests(levelFactory, Level4Event.class); 65 specifyLocalEventInterests(levelFactory, Level5Event.class); 66 specifyLocalEventInterests(levelFactory, Level6Event.class); 67 specifyLocalEventInterests(levelFactory, Level7Event.class); 68 specifyLocalEventInterests(levelFactory, Level8Event.class); 69 specifyLocalEventInterests(levelFactory, Level9Event.class); 70 specifyLocalEventInterests(levelFactory, Level10Event.class); 71 specifyLocalEventInterests(renderFactory, RenderTestScreenEvent.class); 72 } 73 74 75 82 class LevelHandler extends DefaultBaseEventListener { 83 public void handleControlEvent(ControlEventContext context) throws EventException, ServletException, IOException { 84 BaseEvent event = context.getEvent(); 86 DispatchQueue queue = context.getQueue(); 87 88 logger.debug("Handling event:"+event); 91 BaseEvent newEvent = new RenderTestScreenEvent(); 92 newEvent.setSource(event); 93 queue.addEvent(newEvent); 94 } 95 } 96 97 98 105 class RenderTestHandler extends DefaultBaseEventListener { 106 public void handleViewEvent(ViewEventContext context) throws EventException, ServletException, IOException { 107 BaseEvent event = context.getEvent(); 109 HttpServletResponse resp = context.getResponse(); 110 111 resp.setHeader("Cache-Control","max-age=0"); 114 resp.setDateHeader("Last-Modified", System.currentTimeMillis()); 115 116 resp.setContentType("text/html"); 118 PrintWriter out = resp.getWriter(); 119 120 String title = "Simple Test Screen"; 122 out.println ("<html>"); 123 out.println (" <head>"); 124 out.println (" <title>"+title+"</title>"); 125 out.println (" </head>"); 126 out.println (" <body>"); 127 out.println (" <font face=\"Arial\">"); 128 129 out.println (" <p>"+title); 131 132 out.println (" </font>"); 134 out.println (" </body>"); 135 out.println ("</html>"); 136 } 137 } 138 } 139 140 | Popular Tags |