001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.dbschema.jdbcimpl;
043:
044: import java.beans.*;
045:
046: import org.netbeans.modules.dbschema.*;
047:
048: abstract class DBElementImpl implements DBElement.Impl,
049: DBElementProperties {
050:
051: /** Element */
052: DBElement element;
053:
054: protected DBIdentifier _name;
055:
056: /** Property change support */
057: transient private PropertyChangeSupport support;
058:
059: /** Creates new DBElementImpl */
060: public DBElementImpl() {
061: }
062:
063: /** Creates new DBElementImpl with the specified name */
064: public DBElementImpl(String name) {
065: if (name != null)
066: _name = DBIdentifier.create(name);
067: }
068:
069: /** Called to attach the implementation to a specific
070: * element. Will be called in the element's constructor.
071: * Allows implementors of this interface to store a reference to the
072: * holder class, useful for implementing the property change listeners.
073: *
074: * @param element the element to attach to
075: */
076: public void attachToElement(DBElement el) {
077: element = el;
078: }
079:
080: /** Get the name of this element.
081: * @return the name
082: */
083: public DBIdentifier getName() {
084: return _name;
085: }
086:
087: /** Set the name of this element.
088: * @param name the name
089: * @throws DBException if impossible
090: */
091: public void setName(DBIdentifier name) throws DBException {
092: _name = name;
093: }
094:
095: protected boolean comp(Object obj1, Object obj2) {
096: if (obj1 == null || obj2 == null) {
097: if (obj1 == obj2)
098: return true;
099: } else if (obj1.equals(obj2))
100: return true;
101:
102: return false;
103: }
104:
105: /** Fires property change event.
106: * @param name property name
107: * @param o old value
108: * @param n new value
109: */
110: protected final void firePropertyChange(String name, Object o,
111: Object n) {
112: if (support != null)
113: support.firePropertyChange(name, o, n);
114: }
115:
116: /** Add a property change listener.
117: * @param l the listener to add
118: */
119: public synchronized void addPropertyChangeListener(
120: PropertyChangeListener l) {
121: if (support == null)
122: synchronized (this ) {
123: // new test under synchronized block
124: if (support == null)
125: support = new PropertyChangeSupport(element);
126: }
127:
128: support.addPropertyChangeListener(l);
129: }
130:
131: /** Remove a property change listener.
132: * @param l the listener to remove
133: */
134: public void removePropertyChangeListener(PropertyChangeListener l) {
135: if (support != null)
136: support.removePropertyChangeListener(l);
137: }
138: }
|