1 16 package org.mortbay.jetty.servlet; 17 18 import java.io.Serializable ; 19 import java.util.AbstractMap ; 20 import java.util.Collections ; 21 import java.util.Enumeration ; 22 import java.util.HashMap ; 23 import java.util.Map ; 24 import java.util.Set ; 25 26 import org.apache.commons.logging.Log; 27 import org.mortbay.log.LogFactory; 28 import org.mortbay.http.HttpContext; 29 import org.mortbay.http.HttpHandler; 30 import org.mortbay.util.LifeCycle; 31 32 33 34 38 public class Holder 39 extends AbstractMap 40 implements LifeCycle, 41 Serializable 42 { 43 private static Log log = LogFactory.getLog(Holder.class); 44 45 46 protected HttpHandler _httpHandler; 47 protected String _name; 48 protected String _displayName; 49 protected String _className; 50 protected Map _initParams; 51 52 protected transient Class _class; 53 54 55 57 protected Holder() 58 {} 59 60 61 protected Holder(HttpHandler httpHandler, 62 String name, 63 String className) 64 { 65 if (name==null || name.length()==0) 66 throw new IllegalArgumentException ("No name for "+className); 67 68 if (className==null || className.length()==0) 69 throw new IllegalArgumentException ("No classname"); 70 71 _httpHandler=httpHandler; 72 _className=className; 73 _name=name; 74 _displayName=name; 75 } 76 77 78 79 public String getName() 80 { 81 return _name; 82 } 83 84 85 public void setDisplayName(String name) 86 { 87 _name=name; 88 } 89 90 91 public String getDisplayName() 92 { 93 return _name; 94 } 95 96 97 public String getClassName() 98 { 99 return _className; 100 } 101 102 103 public HttpHandler getHttpHandler() 104 { 105 return _httpHandler; 106 } 107 108 109 public HttpContext getHttpContext() 110 { 111 if (_httpHandler!=null) 112 return _httpHandler.getHttpContext(); 113 return null; 114 } 115 116 117 public void setInitParameter(String param,String value) 118 { 119 put(param,value); 120 } 121 122 123 public String getInitParameter(String param) 124 { 125 if (_initParams==null) 126 return null; 127 return (String )_initParams.get(param); 128 } 129 130 131 public Map getInitParameters() 132 { 133 return _initParams; 134 } 135 136 137 public Enumeration getInitParameterNames() 138 { 139 if (_initParams==null) 140 return Collections.enumeration(Collections.EMPTY_LIST); 141 return Collections.enumeration(_initParams.keySet()); 142 } 143 144 145 151 public synchronized Set entrySet() 152 { 153 if (_initParams==null) 154 _initParams=new HashMap (3); 155 return _initParams.entrySet(); 156 } 157 158 159 164 public synchronized Object put(Object name,Object value) 165 { 166 if (_initParams==null) 167 _initParams=new HashMap (3); 168 return _initParams.put(name,value); 169 } 170 171 172 177 public synchronized Object get(Object name) 178 { 179 if (_initParams==null) 180 return null; 181 return _initParams.get(name); 182 } 183 184 185 public void start() 186 throws Exception 187 { 188 _class=_httpHandler.getHttpContext().loadClass(_className); 189 if(log.isDebugEnabled())log.debug("Started holder of "+_class); 190 } 191 192 193 public synchronized Object newInstance() 194 throws InstantiationException , 195 IllegalAccessException 196 { 197 if (_class==null) 198 throw new InstantiationException ("No class for "+this); 199 return _class.newInstance(); 200 } 201 202 203 public boolean isStarted() 204 { 205 return _class!=null; 206 } 207 208 209 public void stop() 210 { 211 _class=null; 212 } 213 214 215 public String toString() 216 { 217 return _name; 218 } 219 220 } 221 222 223 224 225 226 | Popular Tags |