1 64 65 70 package com.jcorporate.expresso.core.jsdkapi; 71 72 import com.jcorporate.expresso.core.misc.ConfigManager; 73 import com.jcorporate.expresso.core.misc.SerializableString; 74 import com.jcorporate.expresso.kernel.util.ClassLocator; 75 76 import javax.servlet.ServletException ; 77 import javax.servlet.http.HttpServletRequest ; 78 import java.io.Serializable ; 79 import java.util.Enumeration ; 80 81 82 92 public class GenericSession { 93 94 private GenericSession() { 95 } 97 private static boolean classLoaded = false; 100 101 private static APIAwareSession mySession = null; 106 107 private static final java.lang.String thisClass = GenericSession.class.getName(); 109 110 private static final java.lang.String ServletAPI2_2Session = 112 "com.jcorporate.expresso.core.jsdkapi.ServletAPI2_2Session"; 113 114 121 public synchronized static void setAttribute(HttpServletRequest req, 122 String code, String value) 123 throws ServletException { 124 125 SerializableString ss = new SerializableString(value); 127 128 if (classLoaded == false) { 130 loadClass(); 131 } 132 133 mySession.setAttribute(req, code, ss); 135 } 136 137 138 147 public synchronized static String getAttributeString(HttpServletRequest req, 148 String code) 149 throws ServletException { 150 151 if (classLoaded == false) { 153 loadClass(); 154 } 155 156 Object o = mySession.getAttribute(req, code); 157 158 if (o == null) { 159 return ""; 160 } 161 162 return o.toString(); 163 164 179 } 180 181 182 190 public static Object getAttribute(HttpServletRequest req, String code) 191 throws ServletException { 192 if (classLoaded == false) { 193 loadClass(); 194 } 195 196 return mySession.getAttribute(req, code); 197 } 198 199 200 206 public synchronized static void invalidate(HttpServletRequest req) 207 throws ServletException { 208 209 if (classLoaded == false) { 211 loadClass(); 212 } 213 214 mySession.invalidate(req); 216 } 217 218 219 227 public synchronized static void setAttribute(HttpServletRequest req, 228 String code, Serializable s) 229 throws ServletException { 230 231 if (classLoaded == false) { 233 loadClass(); 234 } 235 236 mySession.setAttribute(req, code, s); 238 } 239 240 241 248 public synchronized static void removeAttribute(HttpServletRequest req, 249 String code) 250 throws ServletException { 251 252 if (classLoaded == false) { 254 loadClass(); 255 } 256 257 mySession.removeAttribute(req, code); 259 } 260 261 262 269 public static Enumeration getAttributeNames(HttpServletRequest req) 270 throws ServletException { 271 272 if (classLoaded == false) { 274 loadClass(); 275 } 276 277 return mySession.getAttributeNames(req); 279 } 280 281 282 289 public static String getId(HttpServletRequest req) 290 throws ServletException { 291 292 if (classLoaded == false) { 294 loadClass(); 295 } 296 297 return mySession.getId(req); 299 } 300 301 302 309 public synchronized static String getContextPath(HttpServletRequest req) 310 throws ServletException { 311 312 313 if (classLoaded == false) { 315 loadClass(); 316 } 317 318 return mySession.getContextPath(req); 320 } 321 322 323 331 private static void loadClass() 332 throws ServletException { 333 334 String myName = thisClass + "loadClass()"; 336 337 try { 338 String apiVersion = ConfigManager.getServletAPIVersion(); 339 Class c = null; 340 341 c = ClassLocator.loadClass(ServletAPI2_2Session); 343 344 mySession = (APIAwareSession) c.newInstance(); 345 346 } catch (ClassNotFoundException cn) { 348 throw new ServletException (myName + 349 ":APIAwareSession class not found:" + 350 cn.getMessage()); 351 } catch (InstantiationException ie) { 352 throw new ServletException (myName + 353 ":APIAwareSession class cannot be instantiated:" + 354 ie.getMessage()); 355 } catch (IllegalAccessException iae) { 356 throw new ServletException (myName + 357 ":Illegal access loading APIAwareSession object:" + 358 iae.getMessage()); 359 } 360 361 classLoaded = true; 363 } 364 365 366 } 367 | Popular Tags |