KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > excalibur > cache > AbstractCache


1 /*
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE.txt file.
7  */

8 package org.apache.avalon.excalibur.cache;
9
10 import java.util.ArrayList JavaDoc;
11 import java.util.Iterator JavaDoc;
12
13 /**
14  *
15  * @author <a HREF="mailto:colus@apache.org">Eung-ju Park</a>
16  */

17 public abstract class AbstractCache
18     implements Cache
19 {
20     protected ArrayList JavaDoc m_listeners;
21
22     public AbstractCache()
23     {
24         m_listeners = new ArrayList JavaDoc();
25     }
26
27     public void addListener( final CacheListener listener )
28     {
29         m_listeners.add( listener );
30     }
31
32     public void removeListener( final CacheListener listener )
33     {
34         m_listeners.remove( listener );
35     }
36
37     protected void notifyAdded( final Object JavaDoc key, final Object JavaDoc value )
38     {
39         final CacheEvent event = new CacheEvent( this, key, value );
40
41         final int s = m_listeners.size();
42         for ( int i = 0; i < s; i++ )
43         {
44             ((CacheListener)m_listeners.get( i )).added( event );
45         }
46     }
47
48     protected void notifyRemoved( final Object JavaDoc key, final Object JavaDoc value )
49     {
50         final CacheEvent event = new CacheEvent( this, key, value );
51
52         final int s = m_listeners.size();
53         for ( int i = 0; i < s; i++ )
54         {
55             ((CacheListener)m_listeners.get( i )).removed( event );
56         }
57     }
58 }
59
Popular Tags