[jboss-cvs] JBossCache/src-50/org/jboss/cache/pojo/impl ...

Manik Surtani msurtani at jboss.com
Tue Jan 2 13:26:06 EST 2007


  User: msurtani
  Date: 07/01/02 13:26:06

  Modified:    src-50/org/jboss/cache/pojo/impl  PojoCacheImpl.java
  Log:
  Cleaned up cache factory
  
  Revision  Changes    Path
  1.28      +46 -33    JBossCache/src-50/org/jboss/cache/pojo/impl/PojoCacheImpl.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: PojoCacheImpl.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/impl/PojoCacheImpl.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -b -r1.27 -r1.28
  --- PojoCacheImpl.java	16 Nov 2006 06:46:58 -0000	1.27
  +++ PojoCacheImpl.java	2 Jan 2007 18:26:06 -0000	1.28
  @@ -10,14 +10,16 @@
   import EDU.oswego.cs.dl.util.concurrent.CopyOnWriteArraySet;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.jboss.aop.Advised;
  +import org.jboss.aop.proxy.ClassProxy;
  +import org.jboss.cache.Cache;
   import org.jboss.cache.CacheException;
  +import org.jboss.cache.CacheSPI;
   import org.jboss.cache.Fqn;
   import org.jboss.cache.Version;
  -import org.jboss.cache.Cache;
  -import org.jboss.cache.CacheSPI;
   import org.jboss.cache.config.Configuration;
  -import org.jboss.cache.factories.XmlConfigurationParser;
   import org.jboss.cache.factories.DefaultCacheFactory;
  +import org.jboss.cache.factories.XmlConfigurationParser;
   import org.jboss.cache.pojo.CachedType;
   import org.jboss.cache.pojo.PojoCache;
   import org.jboss.cache.pojo.PojoCacheException;
  @@ -27,8 +29,6 @@
   import org.jboss.cache.pojo.annotation.Find;
   import org.jboss.cache.pojo.observable.Observer;
   import org.jboss.cache.pojo.observable.Subject;
  -import org.jboss.aop.proxy.ClassProxy;
  -import org.jboss.aop.Advised;
   
   import java.lang.reflect.Field;
   import java.util.Collection;
  @@ -42,7 +42,7 @@
    * Implementation class for PojoCache interface
    *
    * @author Ben Wang
  - * @version $Id: PojoCacheImpl.java,v 1.27 2006/11/16 06:46:58 bwang Exp $
  + * @version $Id: PojoCacheImpl.java,v 1.28 2007/01/02 18:26:06 msurtani Exp $
    */
   public class PojoCacheImpl implements PojoCache, Observer
   {
  @@ -73,10 +73,11 @@
   //         cache_.setConfiguration(new XmlConfigurationParser().parseFile(configStr));
   
            XmlConfigurationParser parser = new XmlConfigurationParser();
  -         Configuration expected = parser.parseFile( configStr );
  +         Configuration expected = parser.parseFile(configStr);
   
            init(expected, toStart);
  -      } catch (Exception e)
  +      }
  +      catch (Exception e)
         {
            e.printStackTrace();
            throw new PojoCacheException("PojoTreeCache: " + e);
  @@ -92,8 +93,9 @@
      {
         try
         {
  -         cache_ = (CacheSPI)DefaultCacheFactory.createCache(config, toStart);
  -      } catch (Exception e)
  +         cache_ = (CacheSPI) DefaultCacheFactory.getInstance().createCache(config, toStart);
  +      }
  +      catch (Exception e)
         {
            e.printStackTrace();
            throw new PojoCacheException("PojoTreeCache: " + e);
  @@ -102,7 +104,10 @@
         delegate_ = new PojoCacheDelegate(this, this);
      }
   
  -   public CacheSPI getUnderlyingCache() { return cache_; }
  +   public CacheSPI getUnderlyingCache()
  +   {
  +      return cache_;
  +   }
   
      public Object attach(String id, Object pojo) throws PojoCacheException
      {
  @@ -116,15 +121,16 @@
         {
            Object obj = putObject(id, pojo);
            return obj;
  -      } catch (CacheException e)
  +      }
  +      catch (CacheException e)
         {
            e.printStackTrace();
            throw new PojoCacheException("PojoTreeCache: " + e);
         }
      }
   
  -   /** This public API is called from internal package only.
  -    *
  +   /**
  +    * This public API is called from internal package only.
       */
      public Object putObject(Fqn id, Object pojo)
              throws CacheException
  @@ -133,7 +139,7 @@
   
         // Maybe this is the same instance already.
         obj = delegate_.putObjectI(id, pojo);
  -      if(obj != null) return obj;
  +      if (obj != null) return obj;
   
         notifyAttach(pojo, true);
         obj = delegate_.putObjectII(id, pojo);
  @@ -152,13 +158,14 @@
         try
         {
            Object pojo = find(id); // TODO need optimization here since it will be redundant here
  -         if(pojo == null) return pojo;
  +         if (pojo == null) return pojo;
   
            notifyDetach(pojo, true);
            Object obj = removeObject(id);
            notifyDetach(pojo, false);
            return obj;
  -      } catch (CacheException e)
  +      }
  +      catch (CacheException e)
         {
            e.printStackTrace();  // TODO
            throw new PojoCacheException("PojoTreeCache: " + e);
  @@ -187,7 +194,8 @@
         try
         {
            return getObject(id);
  -      } catch (CacheException e)
  +      }
  +      catch (CacheException e)
         {
            e.printStackTrace();  // TODO
            throw new PojoCacheException("PojoTreeCache: " + e);
  @@ -209,12 +217,13 @@
      public Map findAll(Fqn id) throws PojoCacheException
      {
         // Should produce "/"
  -      if(id == null) id = Fqn.fromString(null);
  +      if (id == null) id = Fqn.fromString(null);
   
         try
         {
            return delegate_.findObjects(id);
  -      } catch (CacheException e)
  +      }
  +      catch (CacheException e)
         {
            e.printStackTrace();  // TODO
            throw new PojoCacheException("PojoTreeCache: " + e);
  @@ -232,7 +241,8 @@
         try
         {
            cache_.create();
  -      } catch (Exception e)
  +      }
  +      catch (Exception e)
         {
            throw new PojoCacheException("PojoCache create exception", e);
         }
  @@ -242,7 +252,7 @@
   
      public void start() throws PojoCacheException
      {
  -      if(!hasCreate_)
  +      if (!hasCreate_)
         {
            create();
         }
  @@ -251,7 +261,8 @@
         {
            log_.info("PojoCache version: " + getVersion());
            cache_.start();
  -      } catch (Exception e)
  +      }
  +      catch (Exception e)
         {
            e.printStackTrace();
            throw new PojoCacheException("PojoCacheImpl: " + e);
  @@ -302,7 +313,7 @@
      public Cache getCache()
      {
         // TODO Need to return the real Cache interface later on.
  -      return (Cache)cache_;
  +      return (Cache) cache_;
      }
   
      /**
  @@ -336,18 +347,19 @@
            type = new CachedType(clazz);
            cachedTypes_.put(clazz, type);
            return type;
  -      } else
  +      }
  +      else
         {
            return type;
         }
      }
   
  -
      /********************************************************************************
       * Internal API for event notification
       ********************************************************************************/
      /**
       * Callback for Observable to notify of field modification
  +    *
       * @param subject
       */
      public void fireChange(Subject subject, Field modifiedField, boolean pre)
  @@ -356,15 +368,15 @@
         if (hasListeners)
         {
            for (Iterator it = listeners.iterator(); it.hasNext();)
  -            ((PojoCacheListener) it.next()).modify((Object)subject, modifiedField, pre, isLocal);
  +            ((PojoCacheListener) it.next()).modify((Object) subject, modifiedField, pre, isLocal);
         }
   
      }
   
      private void notifyAttach(Object pojo, boolean pre)
      {
  -      if(pojo == null) return;
  -      if(!shouldNotify(pojo)) return;
  +      if (pojo == null) return;
  +      if (!shouldNotify(pojo)) return;
   
         boolean isLocal = true; // TODO Not yet supported. Always true now.
         if (hasListeners)
  @@ -376,8 +388,8 @@
   
      private void notifyDetach(Object pojo, boolean pre)
      {
  -      if(pojo == null) return;
  -      if(!shouldNotify(pojo)) return;
  +      if (pojo == null) return;
  +      if (!shouldNotify(pojo)) return;
   
         boolean isLocal = true; // TODO Not yet supported. Always true now.
         if (hasListeners)
  @@ -389,12 +401,13 @@
   
      /**
       * Decide whether we want to emit notification event or not.
  +    *
       * @param pojo
       */
      private boolean shouldNotify(Object pojo)
      {
         // Not Advised or not Collection
  -      if(!(pojo instanceof Advised) &&
  +      if (!(pojo instanceof Advised) &&
                 !(pojo instanceof ClassProxy || pojo instanceof Collection ||
                 pojo instanceof Map))
         {
  
  
  



More information about the jboss-cvs-commits mailing list