1 17 18 package org.objectweb.jac.aspects.queue; 19 20 import org.aopalliance.intercept.ConstructorInvocation; 21 import org.aopalliance.intercept.MethodInvocation; 22 import org.objectweb.jac.core.AspectComponent; 23 import org.objectweb.jac.core.Interaction; 24 import org.objectweb.jac.core.Wrapper; 25 import org.objectweb.jac.core.rtti.FieldItem; 26 import org.objectweb.jac.core.rtti.MethodItem; 27 import org.objectweb.jac.util.Log; 28 29 public class MessageQueueWrapper extends Wrapper { 30 MessageQueue mqueue; 31 public MessageQueueWrapper(AspectComponent ac) { 32 super(ac); 33 mqueue = ((MessageQueueAC)ac).getMessageQueue(); 34 } 35 36 public Object fieldChange(Interaction interaction) { 37 Log.trace("mqueue","fieldChange: "+interaction); 38 FieldItem[] fields = null; 39 Object [] previousValues = null; 41 42 if (interaction.method instanceof MethodItem) { 43 fields = ((MethodItem)interaction.method).getWrittenFields(); 44 previousValues = new Object [fields.length]; 45 for (int i=0; i<fields.length; i++) { 46 previousValues[i] = fields[i].get(interaction.wrappee); 47 } 48 } 49 50 Object result = proceed(interaction); 51 52 if (fields!=null) { 53 for (int i=0; i<fields.length; i++) { 54 Object newValue = fields[i].get(interaction.wrappee); 55 if ( (newValue!=null && 56 !newValue.equals(previousValues[i])) || 57 (newValue==null && previousValues[i]!=null) ) 58 { 59 mqueue.fieldChanged(interaction.wrappee,fields[i], 60 previousValues[i], newValue); 61 } 62 } 63 } 64 return result; 65 } 66 67 public Object invoke(MethodInvocation invocation) throws Throwable { 68 return fieldChange((Interaction) invocation); 69 } 70 71 public Object construct(ConstructorInvocation invocation) 72 throws Throwable { 73 throw new Exception ("Wrapper "+this+" does not support construction interception."); 74 } 75 } 76
| Popular Tags
|