FileDocCategorySizeDatePackage
VersionedObjectInterceptor.javaAPI DocJBoss 4.2.13190Fri Jul 13 21:02:32 BST 2007org.jboss.aspects.versioned

VersionedObjectInterceptor

public class VersionedObjectInterceptor extends Object implements org.jboss.aop.advice.Interceptor
This interceptor handles chooses an object to invoke on based on the transaction
author
Bill Burke
version
$Revision: 57186 $

Fields Summary
protected Logger
log
Logging instance
private TransactionManager
tm
Constructors Summary
public VersionedObjectInterceptor(TransactionManager tm)

     
   
      this.tm = tm;
   
Methods Summary
public java.lang.StringgetName()

 return "VersionedObjectInterceptor"; 
public java.lang.Objectinvoke(org.jboss.aop.joinpoint.Invocation invocation)

      Transaction tx = tm.getTransaction();
      VersionedObject manager = (VersionedObject)invocation.getMetaData(Versioned.VERSIONED, Versioned.VERSIONED_OBJECT);

      Object version = manager.getVersion(tx);
      if (version != null)
      {
         invocation.setTargetObject(version);
         return invocation.invokeNext();
      }

      boolean isReadonly = false;
      if (invocation instanceof MethodInvocation)
      {
         String readonly = (String)invocation.getMetaData(Versioned.VERSIONED, Versioned.READONLY);
         if (readonly != null)
         {
            isReadonly = Boolean.getBoolean(readonly.toLowerCase());
         }
      }
      else if (invocation instanceof FieldReadInvocation)
      {
         isReadonly = true;
      }
      else if (invocation instanceof FieldWriteInvocation)
      {
         isReadonly = false;
      }
      if (isReadonly) return invocation.invokeNext();

      // Ok, we're in a tx, we're not readonly, there is no previous version, so create another
      
      version = manager.createVersion(tx);
      invocation.setTargetObject(version);
      return invocation.invokeNext();