KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > dbschema > jdbcimpl > DBElementImpl


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
20 package org.netbeans.modules.dbschema.jdbcimpl;
21
22 import java.beans.*;
23
24 import org.netbeans.modules.dbschema.*;
25
26 abstract class DBElementImpl implements DBElement.Impl, DBElementProperties {
27
28     /** Element */
29     DBElement element;
30
31     protected DBIdentifier _name;
32
33     /** Property change support */
34     transient private PropertyChangeSupport support;
35
36     /** Creates new DBElementImpl */
37     public DBElementImpl () {
38     }
39
40     /** Creates new DBElementImpl with the specified name */
41     public DBElementImpl (String JavaDoc name) {
42         if (name != null)
43             _name = DBIdentifier.create(name);
44     }
45
46     /** Called to attach the implementation to a specific
47     * element. Will be called in the element's constructor.
48     * Allows implementors of this interface to store a reference to the
49     * holder class, useful for implementing the property change listeners.
50     *
51     * @param element the element to attach to
52     */

53     public void attachToElement(DBElement el) {
54         element = el;
55     }
56   
57     /** Get the name of this element.
58     * @return the name
59     */

60     public DBIdentifier getName() {
61         return _name;
62     }
63
64     /** Set the name of this element.
65     * @param name the name
66     * @throws DBException if impossible
67     */

68     public void setName(DBIdentifier name) throws DBException {
69         _name = name;
70     }
71     
72     protected boolean comp(Object JavaDoc obj1, Object JavaDoc obj2) {
73         if (obj1 == null || obj2 == null) {
74             if (obj1 == obj2)
75                 return true;
76         } else
77             if (obj1.equals(obj2))
78                 return true;
79             
80         return false;
81     }
82   
83     /** Fires property change event.
84      * @param name property name
85      * @param o old value
86      * @param n new value
87      */

88     protected final void firePropertyChange (String JavaDoc name, Object JavaDoc o, Object JavaDoc n) {
89         if (support != null)
90             support.firePropertyChange(name, o, n);
91     }
92   
93     /** Add a property change listener.
94     * @param l the listener to add
95     */

96     public synchronized void addPropertyChangeListener(PropertyChangeListener l) {
97         if (support == null)
98             synchronized (this) {
99                 // new test under synchronized block
100
if (support == null)
101                     support = new PropertyChangeSupport(element);
102             }
103
104         support.addPropertyChangeListener(l);
105     }
106   
107     /** Remove a property change listener.
108     * @param l the listener to remove
109     */

110     public void removePropertyChangeListener(PropertyChangeListener l) {
111         if (support != null)
112             support.removePropertyChangeListener(l);
113     }
114 }
115
Popular Tags