Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 203   Methods: 6
NCLOC: 124   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AopUtil.java 63.3% 80.4% 83.3% 74.7%
coverage 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.util;
 8   
 9    import org.apache.commons.logging.Log;
 10    import org.apache.commons.logging.LogFactory;
 11    import org.jboss.aop.Advised;
 12    import org.jboss.aop.InstanceAdvisor;
 13    import org.jboss.aop.advice.Interceptor;
 14    import org.jboss.cache.Cache;
 15    import org.jboss.cache.Fqn;
 16    import org.jboss.cache.Region;
 17    import org.jboss.cache.pojo.impl.InternalConstant;
 18    import org.jboss.cache.pojo.interceptors.dynamic.BaseInterceptor;
 19    import org.jboss.cache.pojo.interceptors.dynamic.CacheFieldInterceptor;
 20    import org.jboss.util.id.GUID;
 21   
 22    import java.io.Serializable;
 23    import java.util.ArrayList;
 24    import java.util.List;
 25   
 26    /**
 27    * Unitlity methods for put, get and remove Collection classes object.
 28    *
 29    * @author Ben Wang
 30    */
 31    public final class AopUtil
 32    {
 33    static final Log log = LogFactory.getLog(AopUtil.class.getName());
 34    public static final String SEPARATOR = "/";
 35   
 36    /**
 37    * Find cache interceptor with exact fqn.
 38    *
 39    * @param advisor
 40    * @param fqn
 41    * @return Interceptor
 42    */
 43  0 static public Interceptor findCacheInterceptor(InstanceAdvisor advisor, Fqn fqn)
 44    {
 45  0 org.jboss.aop.advice.Interceptor[] interceptors = advisor.getInterceptors();
 46    // Step Check for cross references
 47  0 for (int i = 0; i < interceptors.length; i++)
 48    {
 49  0 Interceptor interceptor = interceptors[i];
 50  0 if (interceptor instanceof CacheFieldInterceptor)
 51    {
 52  0 CacheFieldInterceptor inter = (CacheFieldInterceptor) interceptor;
 53  0 if (inter != null && inter.getFqn().equals(fqn))
 54    {
 55  0 return interceptor;
 56    }
 57    }
 58    }
 59  0 return null;
 60    }
 61   
 62    /**
 63    * Find existing cache interceptor. Since there is supposedly only one cache interceptor per
 64    * pojo, this call should suffice. In addition, in cases of cross or circular reference,
 65    * fqn can be different anyway.
 66    *
 67    * @param advisor
 68    * @return Interceptor
 69    */
 70  4476 static public Interceptor findCacheInterceptor(InstanceAdvisor advisor)
 71    {
 72    // TODO we assume there is only one interceptor now.
 73  4476 Interceptor[] interceptors = advisor.getInterceptors();
 74    // Step Check for cross references
 75  4476 for (int i = 0; i < interceptors.length; i++)
 76    {
 77  2207 Interceptor interceptor = interceptors[i];
 78  2207 if (interceptor instanceof CacheFieldInterceptor)
 79    {
 80  2207 return interceptor;
 81    }
 82    }
 83  2269 return null;
 84    }
 85   
 86    /**
 87    * Find existing Collection interceptor. Since there is supposedly only one Collection interceptor per
 88    * instance, this call should suffice. In addition, in cases of cross or circular reference,
 89    * fqn can be different anyway.
 90    *
 91    * @param advisor
 92    * @return Interceptor
 93    */
 94  3066 static public Interceptor findCollectionInterceptor(InstanceAdvisor advisor)
 95    {
 96    // TODO we assume there is only one interceptor now.
 97  3066 Interceptor[] interceptors = advisor.getInterceptors();
 98    // Step Check for cross references
 99  3066 for (int i = 0; i < interceptors.length; i++)
 100    {
 101  3066 Interceptor interceptor = interceptors[i];
 102  3066 if (interceptor instanceof BaseInterceptor)
 103    {
 104  3066 return interceptor;
 105    }
 106    }
 107  0 return null;
 108    }
 109   
 110    /**
 111    * Check whether the object type is valid. An object type is valid if it is either: aspectized,
 112    * Serializable, or primitive type. Otherwise a runtime exception is thrown.
 113    *
 114    * @param obj
 115    */
 116  7640 public static void checkObjectType(Object obj)
 117    {
 118  5 if (obj == null) return;
 119  7635 if (!(obj instanceof Advised))
 120    {
 121  5202 boolean allowedType = (obj instanceof Serializable) || (obj.getClass().isArray() && obj.getClass().getComponentType().isPrimitive());
 122   
 123  5202 if (!allowedType)
 124    {
 125  0 throw new IllegalArgumentException("PojoCache.putObject(): Object type is neither " +
 126    " aspectized nor Serializable nor an array of primitives. Object class name is " + obj.getClass().getName());
 127    }
 128    }
 129    }
 130   
 131   
 132  7476 public static Fqn constructFqn(Fqn baseFqn, Object relative)
 133    {
 134    // TODO Don't know why. But this will fail the CachedSetAopTest clear() method since look up is always
 135    // Null at the last index. But why?
 136    // TODO also see JBCACHE-282
 137  7476 return new Fqn(baseFqn, relative.toString());
 138   
 139    // String tmp = baseFqn.toString() +"/" + relative.toString();
 140    // return Fqn.fromString(tmp);
 141    // Fqn fqn = new Fqn((String)relative);
 142    // return new Fqn(baseFqn, fqn);
 143    }
 144   
 145    /**
 146    * Internal fqn is now structured as:
 147    * a) If no region -- /__JBossInternal__/trueId/__ID__/xxxx
 148    * b) If there is region -- /region/__JBossInternal__/xxx
 149    */
 150  7439 public static Fqn createInternalFqn(Fqn fqn, Cache cache)
 151    {
 152    // Extract the original id as it will be fqn - JBOSS_INTERNAL_ID_SEP
 153    // Also the current fqn can be like: /person/__JBossInternal__/test1/_ID_, for region specific ops
 154  7439 Fqn trueId = null;
 155  7439 if (fqn.hasElement(InternalConstant.JBOSS_INTERNAL_ID_SEP_STRING))
 156    {
 157  5901 List list = new ArrayList();
 158  25347 for (int i = 0; i < fqn.size(); i++)
 159    {
 160  25347 if (fqn.get(i).equals(InternalConstant.JBOSS_INTERNAL_STRING))
 161    {
 162  5901 continue;
 163    }
 164   
 165  19446 if (fqn.get(i).equals(InternalConstant.JBOSS_INTERNAL_ID_SEP_STRING))
 166    {
 167  5901 break;
 168    }
 169  13545 list.add(fqn.get(i));
 170    }
 171  5901 trueId = new Fqn(list);
 172    }
 173    else
 174    {
 175  1538 trueId = fqn;
 176    }
 177   
 178  7439 boolean createIfAbsent = false;
 179  7439 Region region = cache.getRegion(trueId, createIfAbsent);
 180    // Use guid that is cluster-wide unique.
 181  7439 GUID guid = new GUID();
 182   
 183  7439 if (region == null || region.getFqn().equals(Fqn.ROOT))
 184    {
 185    // Move id under JBInternal to promote concurrency
 186  7311 Fqn f0 = new Fqn(InternalConstant.JBOSS_INTERNAL, trueId);
 187  7311 Fqn f = new Fqn(f0, InternalConstant.JBOSS_INTERNAL_ID_SEP);
 188  7311 return new Fqn(f, Fqn.fromString(guid.toString()));
 189    }
 190    else
 191    {
 192    // Create it under region first.
 193  128 Fqn rf = region.getFqn();
 194    // Extract rest of fqn id
 195  128 Fqn childf = trueId.getSubFqn(rf.size(), trueId.size());
 196  128 Fqn f0 = new Fqn(InternalConstant.JBOSS_INTERNAL, childf);
 197  128 Fqn f = new Fqn(f0, InternalConstant.JBOSS_INTERNAL_ID_SEP);
 198  128 Fqn f1 = new Fqn(rf, f);
 199  128 return new Fqn(f1, Fqn.fromString(guid.toString()));
 200    }
 201    }
 202   
 203    }