KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > api > persistence > model > jdo > impl > PersistenceElementImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * PersistenceElementImpl.java
26  *
27  * Created on March 1, 2000, 5:01 PM
28  */

29
30 package com.sun.jdo.api.persistence.model.jdo.impl;
31
32 import java.beans.*;
33
34 import com.sun.jdo.api.persistence.model.ModelException;
35 import com.sun.jdo.api.persistence.model.ModelVetoException;
36 import com.sun.jdo.api.persistence.model.jdo.PersistenceElement;
37 import com.sun.jdo.api.persistence.model.jdo.PersistenceElementProperties;
38
39 /* TODO:
40     1. way to get to declaring class from here?
41  */

42
43 /**
44  *
45  * @author raccah
46  * @version %I%
47  */

48 public abstract class PersistenceElementImpl extends Object JavaDoc
49     implements PersistenceElement.Impl, PersistenceElementProperties
50 {
51     /** Element */
52     PersistenceElement _element;
53
54     /** Property change support */
55     private PropertyChangeSupport _support;
56
57     /** Vetoable change support */
58     private transient VetoableChangeSupport _vetoableSupport;
59
60     /** Name of the element. */
61     private String JavaDoc _name;
62
63     /** Create new PersistenceElementImpl with no corresponding name. This
64      * constructor should only be used for cloning and archiving.
65      */

66     public PersistenceElementImpl ()
67     {
68         this(null);
69     }
70
71     /** Creates new PersistenceElementImpl with the corresponding name
72      * @param name the name of the element
73      */

74     public PersistenceElementImpl (String JavaDoc name)
75     {
76         super();
77         _name = name;
78     }
79
80     /** Called to attach the implementation to a specific
81      * element. Will be called in the element's constructor.
82      * Allows implementors of this interface to store a reference to the
83      * holder class, useful for implementing the property change listeners.
84      *
85      * @param element the element to attach to
86      */

87     public void attachToElement (PersistenceElement element)
88     {
89         _element = element;
90     }
91
92     /** Fires property change event.
93      * @param name property name
94      * @param o old value
95      * @param n new value
96      */

97     protected void firePropertyChange (String JavaDoc name, Object JavaDoc o, Object JavaDoc n)
98     {
99         if (_support != null)
100             _support.firePropertyChange(name, o, n);
101     }
102
103     /** Add a property change listener.
104      * @param l the listener to add
105      */

106     public synchronized void addPropertyChangeListener
107         (PropertyChangeListener l)
108     {
109         if (_support == null)
110         {
111             synchronized(this)
112             {
113                 // new test under synchronized block
114
if (_support == null)
115                     _support = new PropertyChangeSupport(_element);
116             }
117         }
118
119         _support.addPropertyChangeListener(l);
120     }
121
122     /** Remove a property change listener.
123      * @param l the listener to remove
124      */

125     public synchronized void removePropertyChangeListener (
126         PropertyChangeListener l)
127     {
128         if (_support != null)
129             _support.removePropertyChangeListener(l);
130     }
131
132     /** Fires vetoable change event.
133      * @param name property name
134      * @param o old value
135      * @param n new value
136      * @exception PropertyVetoException when the change is vetoed by a listener
137      */

138     protected void fireVetoableChange (String JavaDoc name, Object JavaDoc o, Object JavaDoc n)
139         throws PropertyVetoException
140     {
141         if (_vetoableSupport != null)
142             _vetoableSupport.fireVetoableChange(name, o, n);
143     }
144
145     /** Add a vetoable change listener.
146      * @param l the listener to add
147      */

148     public synchronized void addVetoableChangeListener
149         (VetoableChangeListener l)
150     {
151         if (_vetoableSupport == null)
152             _vetoableSupport = new VetoableChangeSupport(_element);
153
154         _vetoableSupport.addVetoableChangeListener(l);
155     }
156
157     /** Remove a vetoable change listener.
158      * @param l the listener to remove
159      */

160     public synchronized void removeVetoableChangeListener (
161         VetoableChangeListener l)
162     {
163         if (_vetoableSupport != null)
164             _vetoableSupport.removeVetoableChangeListener(l);
165     }
166
167     /** Get the name of this persistence element.
168      * @return the name
169      */

170     public String JavaDoc getName () { return _name; }
171
172     /** Set the name of this persistence element.
173      * @param name the name
174      * @exception ModelException if impossible
175      */

176     public void setName (String JavaDoc name) throws ModelException
177     {
178         String JavaDoc old = getName();
179
180         try
181         {
182             fireVetoableChange(PROP_NAME, old, name);
183             _name = name;
184             firePropertyChange(PROP_NAME, old, name);
185         }
186         catch (PropertyVetoException e)
187         {
188             throw new ModelVetoException(e);
189         }
190     }
191 }
192
Popular Tags