Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 110   Methods: 7
NCLOC: 54   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
StaticFieldInterceptor.java 0% 0% 0% 0%
coverage
 1    /*
 2    * JBoss, the OpenSource J2EE webOS
 3    *
 4    * Distributable under LGPL license.
 5    * See terms of license at gnu.org.
 6    */
 7    package org.jboss.cache.pojo.interceptors;
 8   
 9    import org.apache.commons.logging.Log;
 10    import org.apache.commons.logging.LogFactory;
 11    import org.jboss.aop.advice.Interceptor;
 12    import org.jboss.aop.joinpoint.Invocation;
 13    import org.jboss.cache.CacheSPI;
 14    import org.jboss.cache.Fqn;
 15    import org.jboss.cache.pojo.impl.InternalConstant;
 16    import org.jboss.cache.pojo.impl.PojoCacheImpl;
 17   
 18    import java.lang.reflect.Field;
 19   
 20    /**
 21    * interceptor to intercept for static field replication.
 22    *
 23    * @author Ben Wang
 24    */
 25   
 26    public class StaticFieldInterceptor implements Interceptor
 27    {
 28    private final Log log_ = LogFactory.getLog(StaticFieldInterceptor.class);
 29    private PojoCacheImpl pCache_;
 30    private Fqn fqn_;
 31    private String name_;
 32    private String key_;
 33   
 34  0 public StaticFieldInterceptor()
 35    {
 36    }
 37   
 38  0 public String getName()
 39    {
 40  0 if (name_ == null)
 41    {
 42  0 this.name_ = "StaticFieldInterceptor on [" + fqn_ + "]";
 43    }
 44  0 return name_;
 45    }
 46   
 47  0 public Object invoke(Invocation invocation) throws Throwable
 48    {
 49    /*
 50    // Kind of ad hoc now. MethodInvocation should not invoke this.
 51    if(invocation instanceof MethodInvocation)
 52    return invocation.invokeNext();
 53   
 54    needInit(((FieldInvocation)invocation).getField());
 55    if (invocation instanceof FieldWriteInvocation)
 56    {
 57    FieldInvocation fieldInvocation =
 58    (FieldInvocation) invocation;
 59   
 60    Advisor advisor = fieldInvocation.getAdvisor();
 61    Field field = fieldInvocation.getField();
 62    if(log_.isTraceEnabled())
 63    {
 64    log_.trace("invoke(): field write interception for fqn: " +fqn_ + " and field: " +field);
 65    }
 66   
 67    // Only if this field is replicatable. static, transient and final are not.
 68    Object value = ((FieldWriteInvocation) fieldInvocation).getValue();
 69   
 70    cache_.put(fqn_, key_, value);
 71    Object obj = fieldInvocation.getTargetObject();
 72    } else if (invocation instanceof FieldReadInvocation)
 73    {
 74    FieldInvocation fieldInvocation =
 75    (FieldInvocation) invocation;
 76    Field field = fieldInvocation.getField();
 77    Advisor advisor = fieldInvocation.getAdvisor();
 78    return cache_.get(fqn_, key_);
 79    }
 80    */
 81  0 return invocation.invokeNext();
 82   
 83    }
 84   
 85  0 private void needInit(Field field)
 86    {
 87  0 if (pCache_ == null)
 88    {
 89  0 String cn = field.getDeclaringClass().getName();
 90  0 fqn_ = Fqn.fromString(InternalConstant.JBOSS_INTERNAL_STATIC + "/" + cn);
 91  0 key_ = field.getName();
 92    }
 93    }
 94   
 95  0 boolean isChildOf(Fqn parentFqn)
 96    {
 97  0 return fqn_.isChildOf(parentFqn);
 98    }
 99   
 100  0 public Fqn getFqn()
 101    {
 102  0 return fqn_;
 103    }
 104   
 105  0 public void setFqn(Fqn fqn)
 106    {
 107  0 this.fqn_ = fqn;
 108    }
 109   
 110    }