1 package org.columba.calendar.store; 19 20 import javax.swing.event.EventListenerList ; 21 22 import org.columba.calendar.model.api.IComponentInfo; 23 import org.columba.calendar.model.api.IComponentInfoList; 24 import org.columba.calendar.store.api.IStoreListener; 25 import org.columba.calendar.store.api.StoreEvent; 26 import org.columba.calendar.store.api.StoreException; 27 28 public abstract class AbstractCalendarStore { 29 30 private EventListenerList listenerList = new EventListenerList (); 31 32 public AbstractCalendarStore() { 33 super(); 34 35 addStorageListener(StoreEventDelegator.getInstance()); 38 39 } 40 41 public abstract IComponentInfo get(Object id) throws StoreException; 42 43 public abstract void add(IComponentInfo basicModel) throws StoreException; 44 45 public void modify(Object id, IComponentInfo basicModel) throws StoreException { 46 if (id == null) 47 throw new IllegalArgumentException ("id == null"); 48 if (basicModel == null) 49 throw new IllegalArgumentException ("basicModel == null"); 50 51 fireItemChanged(id); 52 } 53 54 public void remove(Object id) throws StoreException { 55 if (id == null) 56 throw new IllegalArgumentException ("id == null"); 57 fireItemRemoved(id); 58 } 59 60 public abstract IComponentInfoList getComponentInfoList() 61 throws StoreException; 62 63 public abstract boolean exists(Object id) throws StoreException; 64 65 66 67 70 public void addStorageListener(IStoreListener l) { 71 listenerList.add(IStoreListener.class, l); 72 } 73 74 77 public void removeStorageListener(IStoreListener l) { 78 listenerList.remove(IStoreListener.class, l); 79 } 80 81 85 protected void fireItemAdded(Object uid) { 86 87 StoreEvent e = new StoreEvent(this, uid); 88 Object [] listeners = listenerList.getListenerList(); 90 91 for (int i = listeners.length - 2; i >= 0; i -= 2) { 94 if (listeners[i] == IStoreListener.class) { 95 ((IStoreListener) listeners[i + 1]).itemAdded(e); 96 } 97 } 98 } 99 100 104 protected void fireItemRemoved(Object uid) { 105 106 StoreEvent e = new StoreEvent(this, uid); 107 Object [] listeners = listenerList.getListenerList(); 109 110 for (int i = listeners.length - 2; i >= 0; i -= 2) { 113 if (listeners[i] == IStoreListener.class) { 114 ((IStoreListener) listeners[i + 1]).itemRemoved(e); 115 } 116 } 117 } 118 119 123 protected void fireItemChanged(Object uid) { 124 125 StoreEvent e = new StoreEvent(this, uid); 126 Object [] listeners = listenerList.getListenerList(); 128 129 for (int i = listeners.length - 2; i >= 0; i -= 2) { 132 if (listeners[i] == IStoreListener.class) { 133 ((IStoreListener) listeners[i + 1]).itemChanged(e); 134 } 135 } 136 } 137 } 138 | Popular Tags |