View Javadoc

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