1 17 18 package org.objectweb.jac.aspects.session; 19 20 import java.util.*; 21 import org.aopalliance.intercept.ConstructorInvocation; 22 import org.aopalliance.intercept.MethodInvocation; 23 import org.apache.log4j.Logger; 24 import org.objectweb.jac.core.*; 25 import org.objectweb.jac.util.*; 26 27 35 36 public class PerSessionObjectWrapper extends Wrapper { 37 static Logger logger = Logger.getLogger("session"); 38 39 Hashtable sessionObjects = new Hashtable(); 40 41 public PerSessionObjectWrapper(AspectComponent ac) { 42 super(ac); 43 } 44 45 56 57 public Object handlePerSessionObject(Interaction interaction) { 58 59 logger.debug("handling per-session object for " + interaction.wrappee); 60 61 String sid = (String ) attr( "Session.sid" ); 62 63 if ( sid == null || sid.startsWith("Swing") ) { 64 logger.debug("session is not defined by client"); 65 return proceed(interaction); 66 } 67 68 logger.debug("found session " + sid); 69 70 Object sessionObject = null; 71 72 if ( sessionObjects.containsKey( sid ) ) { 73 sessionObject = sessionObjects.get( sid ); 74 } else { 75 logger.debug("cloning object " + interaction.wrappee); 78 sessionObject = Wrapping.clone(interaction.wrappee); 79 sessionObjects.put(sid,sessionObject); 80 } 81 82 Object result = null; 83 if( sessionObject == interaction.wrappee ) { 84 logger.warn(interaction.wrappee+ 87 " is a session object and is wrapped."); 88 result = proceed(interaction); 89 } else { 90 logger.debug(interaction.wrappee+" forwarding to session object " + 93 sessionObject+"."+interaction.method); 94 result = interaction.invoke(sessionObject); 95 } 96 return result; 97 } 98 99 public Object invoke(MethodInvocation invocation) throws Throwable { 100 return handlePerSessionObject((Interaction) invocation); 101 } 102 103 public Object construct(ConstructorInvocation invocation) 104 throws Throwable { 105 throw new Exception ("Wrapper "+this+" does not support construction interception."); 106 } 107 108 } 109 | Popular Tags |