01: package org.apache.commons.events.observable;
02:
03: import org.apache.commons.collections.Buffer;
04:
05: /**
06: * <p>
07: * Decorates a <code>Buffer</code> implementation with a <b>bound
08: * property</b> named "collection".
09: * </p>
10: * <p>
11: * Each modifying method call made on this <code>Buffer</code> is
12: * handled as a change to the "collection" property. This
13: * facility serves to notify subscribers of a change to the buffer
14: * but does not allow users the option of vetoing the change. To
15: * gain the ability to veto the change, use a {@link ConstrainedBuffer}
16: * decorater.
17: * </p>
18: * @since Commons Events 1.0
19: * @author Stephen Colebourne, Bryce Nordgren
20: */
21: public class BoundBuffer extends BoundCollection implements Buffer {
22:
23: // Constructors
24: //-----------------------------------------------------------------------
25: protected BoundBuffer(final Buffer source,
26: final CollectionChangeEventFactory eventFactory) {
27:
28: super (source, eventFactory);
29: }
30:
31: protected BoundBuffer(final Buffer source) {
32: super (source);
33: }
34:
35: // Factory methods
36: //-----------------------------------------------------------------------
37: public static BoundBuffer decorate(final Buffer source,
38: final CollectionChangeEventFactory eventFactory) {
39:
40: return new BoundBuffer(source, eventFactory);
41: }
42:
43: public static BoundBuffer decorate(final Buffer source) {
44: return new BoundBuffer(source);
45: }
46:
47: // Utility methods
48: //-----------------------------------------------------------------------
49: private Buffer getBuffer() {
50: return (Buffer) (getCollection());
51: }
52:
53: // Buffer API (methods which do not change the collection)
54: //-----------------------------------------------------------------------
55: public Object get() {
56: return getBuffer().get();
57: }
58:
59: // Decorated Buffer methods
60: //-----------------------------------------------------------------------
61: public Object remove() {
62: // relay request to wrapped buffer
63: Object element = getBuffer().remove();
64:
65: // construct and fire event.
66: CollectionChangeEvent evt = eventFactory.createRemoveNext(
67: element, true);
68: firePropertyChange(evt);
69:
70: return element;
71: }
72: }
|