KickJava   Java API By Example, From Geeks To Geeks.

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


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  * MappingMemberElementImpl.java
26  *
27  * Created on May 23, 2000, 12:41 AM
28  */

29
30 package com.sun.jdo.api.persistence.model.mapping.impl;
31
32 import java.beans.PropertyVetoException JavaDoc;
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.mapping.*;
37
38 /**
39  *
40  * @author Mark Munro
41  * @author Rochelle Raccah
42  * @version %I%
43  */

44 public abstract class MappingMemberElementImpl extends MappingElementImpl
45     implements MappingMemberElement
46 {
47     /** the class to which this element belongs */
48     MappingClassElement _declaringClass;
49
50     /** Create new MappingMemberElementImpl with no corresponding name or
51      * declaring class. This constructor should only be used for cloning and
52      * archiving.
53      */

54     public MappingMemberElementImpl ()
55     {
56         this(null, null);
57     }
58
59     /** Create new MappingMemberElementImpl with the corresponding name and
60      * declaring class.
61      * @param name the name of the element
62      * @param declaringClass the class to attach to
63      */

64     public MappingMemberElementImpl (String JavaDoc name,
65         MappingClassElement declaringClass)
66     {
67         super(name);
68         _declaringClass = declaringClass;
69     }
70
71     /** Get the declaring class.
72      * @return the class that owns this member element, or <code>null</code>
73      * if the element is not attached to any class
74      */

75     public MappingClassElement getDeclaringClass () { return _declaringClass; }
76
77     /** Overrides MappingElementImpl's <code>equals</code> method to add
78      * comparison of the name of the declaring class this mapping element.
79      * The method returns <code>false</code> if obj does not have a declaring
80      * class with the same name as this mapping element.
81      * @return <code>true</code> if this object is the same as the obj argument;
82      * <code>false</code> otherwise.
83      * @param obj the reference object with which to compare.
84      */

85     public boolean equals (Object JavaDoc obj)
86     {
87         if (super.equals(obj) && (obj instanceof MappingMemberElement))
88         {
89             MappingClassElement declaringClass = getDeclaringClass();
90             MappingClassElement objDeclaringClass =
91                 ((MappingMemberElement)obj).getDeclaringClass();
92
93             return ((declaringClass == null) ? (objDeclaringClass == null) :
94                 declaringClass.equals(objDeclaringClass));
95         }
96
97         return false;
98     }
99
100     /** Overrides MappingElementImpl's <code>hashCode</code> method to add
101      * the hashCode of this mapping element's declaring class.
102      * @return a hash code value for this object.
103      */

104     public int hashCode ()
105     {
106         MappingClassElement declaringClass = getDeclaringClass();
107
108         return (super.hashCode() +
109             ((declaringClass == null) ? 0 : declaringClass.hashCode()));
110     }
111
112     /** Fires property change event. This method overrides that of
113      * MappingElementImpl to update the MappingClassElementImpl's modified
114      * status.
115      * @param name property name
116      * @param o old value
117      * @param n new value
118      */

119     protected final void firePropertyChange (String JavaDoc name, Object JavaDoc o, Object JavaDoc n)
120     {
121         // even though o == null and n == null will signify a change, that
122
// is consistent with PropertyChangeSupport's behavior and is
123
// necessary for this to work
124
boolean noChange = ((o != null) && (n != null) && o.equals(n));
125         MappingClassElement classElement = getDeclaringClass();
126
127         super.firePropertyChange(name, o, n);
128
129         if ((classElement != null) && !noChange)
130             classElement.setModified(true);
131     }
132
133     /** Fires vetoable change event. This method overrides that of
134      * MappingElementImpl to give listeners a chance to block
135      * changes on the mapping class element modified status.
136      * @param name property name
137      * @param o old value
138      * @param n new value
139      * @exception PropertyVetoException when the change is vetoed by a listener
140      */

141     protected final void fireVetoableChange (String JavaDoc name, Object JavaDoc o, Object JavaDoc n)
142         throws PropertyVetoException JavaDoc
143     {
144         // even though o == null and n == null will signify a change, that
145
// is consistent with PropertyChangeSupport's behavior and is
146
// necessary for this to work
147
boolean noChange = ((o != null) && (n != null) && o.equals(n));
148         MappingClassElement classElement = getDeclaringClass();
149
150         super.fireVetoableChange(name, o, n);
151
152         if ((classElement != null) && !noChange)
153         {
154             ((MappingClassElementImpl)classElement).fireVetoableChange(
155                 PROP_MODIFIED, Boolean.FALSE, Boolean.TRUE);
156         }
157     }
158
159     //=============== extra set methods needed for xml archiver ==============
160

161     /** Set the declaring class of this mapping member. This method should
162      * only be used internally and for cloning and archiving.
163      * @param declaringClass the declaring class of this mapping member
164      */

165     public void setDeclaringClass (MappingClassElement declaringClass)
166     {
167         _declaringClass = declaringClass;
168     }
169 }
170
Popular Tags