KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > beans > SynchronizedIndexedBeanProperty


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.beans;
8
9
10 import java.util.ArrayList JavaDoc;
11 import java.util.Iterator JavaDoc;
12 import java.util.List JavaDoc;
13
14
15 /**
16  * This class is identical to its parent except that it is
17  * thread safe.
18  *
19  * @author Brian Pontarelli
20  */

21 public class SynchronizedIndexedBeanProperty extends IndexedBeanProperty {
22
23     /**
24      * Constructs a new instance of the thread safe IndexedBeanProperty.
25      */

26     protected SynchronizedIndexedBeanProperty() throws BeanException {
27         super();
28     }
29
30     /**
31      * Constructs a new instance of the thread safe IndexedBeanProperty.
32      */

33     public SynchronizedIndexedBeanProperty(String JavaDoc propertyName, Class JavaDoc beanClass)
34     throws BeanException {
35         super(propertyName, beanClass);
36     }
37
38     /**
39      * Constructs a new instance of the thread safe IndexedBeanProperty.
40      */

41     public SynchronizedIndexedBeanProperty(String JavaDoc propertyName, String JavaDoc beanClass)
42     throws BeanException {
43         super(propertyName, beanClass);
44     }
45
46
47     /**
48      * This method is the same as the {@link
49      * BaseBeanProperty#addPropertyListener(PropertyListener) addPropertyListener()}
50      * method in the {@link BaseBeanProperty BaseBeanProperty} class, except that
51      * it is thread safe.
52      */

53     public void addPropertyListener(PropertyListener listener) {
54         synchronized (super.propertyListeners) {
55             super.addPropertyListener(listener);
56         }
57     }
58
59     /**
60      * This method is the same as the {@link
61      * BaseBeanProperty#removePropertyListener(PropertyListener)
62      * removePropertyListener()} method in the {@link BaseBeanProperty
63      * BaseBeanProperty} class, except that it is thread safe.
64      */

65     public void removePropertyListener(PropertyListener listener) {
66         synchronized (super.propertyListeners) {
67             super.removePropertyListener(listener);
68         }
69     }
70
71     /**
72      * Synchronized get property listeners method. Since this must also safety the
73      * fireEvent method, this makes a clone of the list and returns the iterator for
74      * the clone
75      */

76     public Iterator JavaDoc getPropertyListeners() {
77         synchronized (super.propertyListeners) {
78             List JavaDoc newList = (List JavaDoc) ((ArrayList JavaDoc) super.propertyListeners).clone();
79             return newList.iterator();
80         }
81     }
82
83     /**
84      * This method is the same as the {@link BaseBeanProperty#hasPropertyListeners()
85      * hasPropertyListeners()} method in the {@link BaseBeanProperty BaseBeanProperty}
86      * class, except that it is thread safe.
87      */

88     public boolean hasPropertyListeners() {
89         synchronized (super.propertyListeners) {
90             return super.hasPropertyListeners();
91         }
92     }
93
94     /**
95      * This method is the same as the {@link
96      * BaseBeanProperty#addConversionListener(ConversionListener)
97      * addConversionListener()} method in the {@link BaseBeanProperty
98      * BaseBeanProperty} class, except that it is thread safe.
99      */

100     public void addConversionListener(ConversionListener listener) {
101         synchronized (super.conversionListeners) {
102             super.addConversionListener(listener);
103         }
104     }
105
106     /**
107      * This method is the same as the {@link
108      * BaseBeanProperty#removeConversionListener(ConversionListener)
109      * removeConversionListener()} method in the {@link BaseBeanProperty
110      * BaseBeanProperty} class, except that it is thread safe.
111      */

112     public void removeConversionListener(ConversionListener listener) {
113         synchronized (super.conversionListeners) {
114             super.removeConversionListener(listener);
115         }
116     }
117
118     /**
119      * Synchronized get conversion listeners method. Since this must also safety
120      * the fireEvent method, this makes a clone of the list and returns the
121      * iterator for the clone
122      */

123     public Iterator JavaDoc getConversionListeners() {
124         synchronized (super.conversionListeners) {
125             List JavaDoc newList = (List JavaDoc) ((ArrayList JavaDoc) super.conversionListeners).clone();
126             return newList.iterator();
127         }
128     }
129
130     /**
131      * This method is the same as the {@link BaseBeanProperty#hasConversionListeners()
132      * hasConversionListeners()} method in the {@link BaseBeanProperty
133      * BaseBeanProperty} class, except that it is thread safe.
134      */

135     public boolean hasConversionListeners() {
136         synchronized (super.conversionListeners) {
137             return super.hasConversionListeners();
138         }
139     }
140 }
141
Popular Tags