1 28 29 package com.caucho.server.webapp; 30 31 import com.caucho.config.BuilderProgram; 32 import com.caucho.config.Config; 33 import com.caucho.config.ConfigException; 34 import com.caucho.config.NodeBuilderProgram; 35 import com.caucho.config.types.InitProgram; 36 import com.caucho.util.L10N; 37 38 import javax.servlet.ServletContextAttributeListener ; 39 import javax.servlet.ServletContextListener ; 40 import javax.servlet.ServletRequestAttributeListener ; 41 import javax.servlet.ServletRequestListener ; 42 import javax.servlet.http.HttpSessionActivationListener ; 43 import javax.servlet.http.HttpSessionAttributeListener ; 44 import javax.servlet.http.HttpSessionListener ; 45 46 49 public class Listener { 50 static L10N L = new L10N(Listener.class); 51 52 private Class _listenerClass; 54 55 private Object _object; 57 58 private InitProgram _init; 59 60 63 public void setListenerClass(Class cl) 64 throws ConfigException 65 { 66 Config.checkCanInstantiate(cl); 67 68 if (ServletContextListener .class.isAssignableFrom(cl)) { 69 } 70 else if (ServletContextAttributeListener .class.isAssignableFrom(cl)) { 71 } 72 else if (ServletRequestListener .class.isAssignableFrom(cl)) { 73 } 74 else if (ServletRequestAttributeListener .class.isAssignableFrom(cl)) { 75 } 76 else if (HttpSessionListener .class.isAssignableFrom(cl)) { 77 } 78 else if (HttpSessionAttributeListener .class.isAssignableFrom(cl)) { 79 } 80 else if (HttpSessionActivationListener .class.isAssignableFrom(cl)) { 81 } 82 else 83 throw new ConfigException(L.l("listener-class '{0}' does not implement any web-app listener interface.", 84 cl.getName())); 85 86 _listenerClass = cl; 87 } 88 89 92 public Class getListenerClass() 93 { 94 return _listenerClass; 95 } 96 97 100 public void setInit(InitProgram init) 101 { 102 _init = init; 103 } 104 105 108 public InitProgram getInit() 109 { 110 return _init; 111 } 112 113 116 public Object createListenerObject() 117 throws Exception 118 { 119 if (_object != null) 120 return _object; 121 122 _object = _listenerClass.newInstance(); 123 124 InitProgram init = getInit(); 125 BuilderProgram program; 126 127 if (init != null) 128 program = init.getBuilderProgram(); 129 else 130 program = NodeBuilderProgram.NULL; 131 132 program.configure(_object); 133 program.init(_object); 134 135 return _object; 136 } 137 138 public String toString() 139 { 140 return "Listener[" + _listenerClass + "]"; 141 } 142 } 143 | Popular Tags |