View Javadoc

1   /*
2    * Copyright 2005 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at 
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software 
11   * distributed under the License is distributed on an "AS IS" BASIS, 
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License.
15   */
16  
17  package org.apache.jdo.impl.model.jdo;
18  
19  import java.util.List;
20  import java.util.ArrayList;
21  import java.beans.PropertyChangeListener;
22  import java.beans.PropertyChangeSupport;
23  import java.beans.PropertyVetoException;
24  import java.beans.VetoableChangeListener;
25  import java.beans.VetoableChangeSupport;
26  
27  import org.apache.jdo.model.jdo.JDOElement;
28  import org.apache.jdo.model.jdo.JDOExtension;
29  
30  /***
31   * This is the super interface for JDO metadata elements, 
32   * such as JDOClass, JDOField and JDORelationship.
33   *
34   * @author Michael Bouschen
35   */
36  public class JDOElementImpl
37      implements JDOElement
38  {
39      /*** List of vendorExtensions. */
40      private List vendorExtensions = new ArrayList();
41  
42      /*** Property change support. */
43      private transient PropertyChangeSupport propertyChangeSupport;
44  
45      /*** Vetoable change support. */
46      private transient VetoableChangeSupport vetoableChangeSupport;
47  
48      /***
49       * Remove the supplied vendor extension from the collection of extensions 
50       * maintained by this JDOElement.
51       */
52      public void removeJDOExtension(JDOExtension vendorExtension)
53      {
54          vendorExtensions.remove(vendorExtension);
55      }
56  
57      /***
58       * Returns the collection of vendor extensions for this JDOElement
59       * in the form of an array.
60       * @return the vendor extensions for this JDOClass
61       */
62      public JDOExtension[] getJDOExtensions()
63      {
64          return (JDOExtension[])vendorExtensions.toArray(
65              new JDOExtension[vendorExtensions.size()]);
66      }
67  
68      /***
69       * Creates a new JDOExtension instance and attaches it to the specified 
70       * JDOElement object.
71       */
72      public JDOExtension createJDOExtension()
73      {
74          JDOExtension jdoExtension = new JDOExtensionImpl();
75          vendorExtensions.add(jdoExtension);
76          return jdoExtension;
77      }
78  
79      /*** 
80       * Fires property change event.
81       * @param name property name
82       * @param o old value
83       * @param n new value
84       */
85      protected void firePropertyChange (String name, Object o, Object n)
86      {
87          if (propertyChangeSupport != null) {
88              propertyChangeSupport.firePropertyChange(name, o, n);
89          }
90      }
91  
92      /*** 
93       * Add a property change listener.
94       * @param l the listener to add
95       */
96      public synchronized void addPropertyChangeListener (PropertyChangeListener l)
97      {
98          if (propertyChangeSupport == null) {
99              propertyChangeSupport = new PropertyChangeSupport(this);
100         }
101         propertyChangeSupport.addPropertyChangeListener(l);
102     }
103 
104     /*** 
105      * Remove a property change listener.
106      * @param l the listener to remove
107      */
108     public synchronized void removePropertyChangeListener(PropertyChangeListener l)
109     {
110         if (propertyChangeSupport != null) {
111             propertyChangeSupport.removePropertyChangeListener(l);
112         }
113     }
114 
115     /*** Fires vetoable change event.
116      * @param name property name
117      * @param o old value
118      * @param n new value
119      * @exception PropertyVetoException when the change is vetoed by a listener
120      */
121     protected void fireVetoableChange (String name, Object o, Object n)
122         throws PropertyVetoException
123     {
124         if (vetoableChangeSupport != null) {
125             vetoableChangeSupport.fireVetoableChange(name, o, n);
126         }
127     }
128 
129     /*** 
130      * Add a vetoable change listener.
131      * @param l the listener to add
132      */
133     public void addVetoableChangeListener(VetoableChangeListener l)
134     {
135         if (vetoableChangeSupport == null) {
136             vetoableChangeSupport = new VetoableChangeSupport(this);
137         }
138         vetoableChangeSupport.addVetoableChangeListener(l);
139     }
140 
141     /*** 
142      * Remove a vetoable change listener.
143      * @param l the listener to remove
144      */
145     public void removeVetoableChangeListener(VetoableChangeListener l)
146     {
147         if (vetoableChangeSupport != null) {
148             vetoableChangeSupport.removeVetoableChangeListener(l);
149         }
150         
151     }
152 }