Coverage report

  %line %branch
org.apache.jetspeed.components.portletregistry.RegistryApplicationCache
0% 
0% 

 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  * 
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.jetspeed.components.portletregistry;
 18  
 
 19  
 import java.util.List;
 20  
 import java.util.Properties;
 21  
 
 22  
 import org.apache.jetspeed.cache.CacheElement;
 23  
 import org.apache.jetspeed.cache.DistributedCacheObject;
 24  
 import org.apache.jetspeed.cache.JetspeedCache;
 25  
 import org.apache.jetspeed.cache.impl.EhCacheElementImpl;
 26  
 import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
 27  
 import org.apache.ojb.broker.Identity;
 28  
 import org.apache.ojb.broker.PersistenceBroker;
 29  
 import org.apache.ojb.broker.cache.ObjectCache;
 30  
 
 31  
 /**
 32  
  * OJB cache 
 33  
  * 
 34  
  * @author dtaylor
 35  
  *
 36  
  */
 37  
 public class RegistryApplicationCache implements ObjectCache
 38  
 {
 39  
     private static JetspeedCache oidCache;
 40  
     private static JetspeedCache nameCache;    
 41  
     private static PortletRegistry registry;
 42  0
     private static List listeners = null;
 43  
 
 44  
     public RegistryApplicationCache(PersistenceBroker broker, Properties props)
 45  0
     {
 46  0
     }
 47  
        
 48  
     public synchronized static void cacheInit(PortletRegistry r, JetspeedCache o, JetspeedCache n, List l)
 49  
     {
 50  0
         registry = r;
 51  0
         oidCache = o;
 52  0
         nameCache = n;
 53  0
         listeners = l;
 54  0
     }
 55  
 
 56  
     public Object lookup(Identity oid)
 57  
     {
 58  0
         return cacheLookup(oid);
 59  
     }    
 60  
     public synchronized static Object cacheLookup(Identity oid)
 61  
     {
 62  0
         CacheElement element = oidCache.get(oid);
 63  0
         if (element != null)
 64  
         {
 65  0
             return element.getContent();
 66  
         }
 67  0
         return null;
 68  
     }    
 69  
     
 70  
     /* (non-Javadoc)
 71  
      * @see org.apache.ojb.broker.cache.ObjectCache#cache(org.apache.ojb.broker.Identity, java.lang.Object)
 72  
      */
 73  
     public void cache(Identity oid, Object obj)
 74  
     {
 75  0
         cacheAdd(oid, obj);
 76  0
     }
 77  
     public synchronized static void cacheAdd(Identity oid, Object obj)
 78  
     {        
 79  0
         oidCache.remove(oid);
 80  0
         CacheElement entry = new EhCacheElementImpl(oid, obj);
 81  0
         oidCache.put(entry);
 82  
         
 83  0
         MutablePortletApplication pa = (MutablePortletApplication)obj;
 84  0
         DistributedCacheObject wrapper = new RegistryCacheObjectWrapper(oid, pa.getName());
 85  0
         nameCache.remove(pa.getName());
 86  0
         CacheElement nameEntry = nameCache.createElement(pa.getName(), wrapper);
 87  0
         nameCache.put(nameEntry);
 88  
                
 89  0
         if (listeners != null)
 90  
         {        
 91  0
             for (int ix=0; ix < listeners.size(); ix++)
 92  
             {
 93  0
                 RegistryEventListener listener = (RegistryEventListener)listeners.get(ix);
 94  0
                 listener.applicationUpdated((MutablePortletApplication)obj);
 95  
             }
 96  
         }
 97  0
     }
 98  
     
 99  
     /* (non-Javadoc)
 100  
      * @see org.apache.ojb.broker.cache.ObjectCache#clear()
 101  
      */
 102  
     public void clear()
 103  
     {
 104  0
         cacheClear();
 105  0
     }
 106  
     public synchronized static void cacheClear()
 107  
     {
 108  0
         oidCache.clear();
 109  0
         nameCache.clear();
 110  0
     }
 111  
 
 112  
 
 113  
     /* (non-Javadoc)
 114  
      * @see org.apache.ojb.broker.cache.ObjectCache#remove(org.apache.ojb.broker.Identity)
 115  
      */
 116  
     public void remove(Identity oid)
 117  
     {
 118  0
         cacheRemove(oid);
 119  0
     }
 120  
     /**
 121  
      * cacheRemove
 122  
      *
 123  
      * Remove identified object from object and node caches.
 124  
      *
 125  
      * @param oid object identity
 126  
      */
 127  
     public synchronized static void cacheRemove(Identity oid)
 128  
     {
 129  0
         MutablePortletApplication pd = (MutablePortletApplication)cacheLookup(oid);
 130  0
         if (pd == null)
 131  0
             return;
 132  
         
 133  0
         oidCache.remove(oid);
 134  0
         nameCache.remove(pd.getName());
 135  
         
 136  0
         if (listeners != null)
 137  
         {
 138  0
             for (int ix=0; ix < listeners.size(); ix++)
 139  
             {
 140  0
                 RegistryEventListener listener = (RegistryEventListener)listeners.get(ix);
 141  0
                 listener.applicationRemoved(pd);
 142  
             }        
 143  
         }
 144  
 
 145  0
     }
 146  
 
 147  
     public synchronized static void cacheRemoveQuiet(String key, RegistryCacheObjectWrapper w)
 148  
     {
 149  0
         RegistryCacheObjectWrapper wrapper = w;
 150  0
         if (wrapper == null)
 151  
         {
 152  0
             wrapper = (RegistryCacheObjectWrapper)nameCache.get(key);
 153  0
             if (wrapper == null)
 154  0
                 return;
 155  
         }
 156  0
         Identity oid = wrapper.getId();      
 157  
         
 158  0
         MutablePortletApplication pd = (MutablePortletApplication)cacheLookup(oid);
 159  0
         if (pd == null)
 160  0
             return;
 161  
         
 162  0
         oidCache.removeQuiet(oid);
 163  0
         nameCache.removeQuiet(pd.getName());        
 164  0
     }
 165  
    
 166  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.