1 22 package org.jboss.aspects.versioned; 23 24 import org.jboss.aop.joinpoint.FieldReadInvocation; 25 import org.jboss.aop.joinpoint.FieldWriteInvocation; 26 import org.jboss.aop.joinpoint.MethodInvocation; 27 import org.jboss.logging.Logger; 28 29 import javax.transaction.Transaction ; 30 import javax.transaction.TransactionManager ; 31 32 39 public class VersionedObjectInterceptor implements org.jboss.aop.advice.Interceptor 40 { 41 44 protected Logger log = Logger.getLogger(this.getClass()); 45 46 private TransactionManager tm; 47 public VersionedObjectInterceptor(TransactionManager tm) 48 { 49 this.tm = tm; 50 } 51 52 public String getName() { return "VersionedObjectInterceptor"; } 53 54 57 public Object invoke(org.jboss.aop.joinpoint.Invocation invocation) throws Throwable 58 { 59 Transaction tx = tm.getTransaction(); 60 VersionedObject manager = (VersionedObject)invocation.getMetaData(Versioned.VERSIONED, Versioned.VERSIONED_OBJECT); 61 62 Object version = manager.getVersion(tx); 63 if (version != null) 64 { 65 invocation.setTargetObject(version); 66 return invocation.invokeNext(); 67 } 68 69 boolean isReadonly = false; 70 if (invocation instanceof MethodInvocation) 71 { 72 String readonly = (String )invocation.getMetaData(Versioned.VERSIONED, Versioned.READONLY); 73 if (readonly != null) 74 { 75 isReadonly = Boolean.getBoolean(readonly.toLowerCase()); 76 } 77 } 78 else if (invocation instanceof FieldReadInvocation) 79 { 80 isReadonly = true; 81 } 82 else if (invocation instanceof FieldWriteInvocation) 83 { 84 isReadonly = false; 85 } 86 if (isReadonly) return invocation.invokeNext(); 87 88 90 version = manager.createVersion(tx); 91 invocation.setTargetObject(version); 92 return invocation.invokeNext(); 93 } 94 95 } 96 | Popular Tags |