KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > java > classpath > support > PathResourceBase


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.spi.java.classpath.support;
20
21
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.beans.PropertyChangeEvent JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import org.netbeans.spi.java.classpath.PathResourceImplementation;
27
28 /**
29  * This class provides a base class for PathResource implementations
30  * @since org.netbeans.api.java/1 1.4
31  */

32 public abstract class PathResourceBase implements PathResourceImplementation {
33
34     private ArrayList JavaDoc<PropertyChangeListener JavaDoc> pListeners;
35
36
37     /**
38      * Adds property change listener.
39      * The listener is notified when the roots of the PathResource are changed.
40      * @param listener
41      */

42     public synchronized final void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
43         if (this.pListeners == null)
44             this.pListeners = new ArrayList JavaDoc<PropertyChangeListener JavaDoc> ();
45         this.pListeners.add (listener);
46     }
47
48     /**
49      * Removes PropertyChangeListener
50      * @param listener
51      */

52     public synchronized final void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
53         if (this.pListeners == null)
54             return;
55         this.pListeners.remove (listener);
56     }
57
58     /**
59      * Fires PropertyChangeEvent
60      * @param propName name of property
61      * @param oldValue old property value or null
62      * @param newValue new property value or null
63      */

64     protected final void firePropertyChange (String JavaDoc propName, Object JavaDoc oldValue, Object JavaDoc newValue) {
65         PropertyChangeListener JavaDoc[] _listeners;
66         synchronized (this) {
67             if (this.pListeners == null)
68                 return;
69             _listeners = this.pListeners.toArray(new PropertyChangeListener JavaDoc[this.pListeners.size()]);
70         }
71         PropertyChangeEvent JavaDoc event = new PropertyChangeEvent JavaDoc (this, propName, oldValue, newValue);
72         for (PropertyChangeListener JavaDoc l : _listeners) {
73             l.propertyChange (event);
74         }
75     }
76 }
77
Popular Tags