KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > api > persistence > model > jdo > PersistenceMemberElement


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  * PersistenceMemberElement.java
26  *
27  * Created on February 29, 2000, 12:50 PM
28  */

29
30 package com.sun.jdo.api.persistence.model.jdo;
31
32 /**
33  *
34  * @author raccah
35  * @version %I%
36  */

37 public abstract class PersistenceMemberElement extends PersistenceElement
38 {
39     /** the class to which this element belongs */
40     private PersistenceClassElement _declaringClass;
41
42     /** Create new PersistenceMemberElement with no implementation.
43      * This constructor should only be used for cloning and archiving.
44      */

45     public PersistenceMemberElement ()
46     {
47         this(null, null);
48     }
49
50     /** Create new PersistenceMemberElement with the provided implementation. The
51      * implementation is responsible for storing all properties of the object.
52      * @param impl the implementation to use
53      * @param declaringClass the class to attach to
54      */

55     protected PersistenceMemberElement (PersistenceMemberElement.Impl impl,
56         PersistenceClassElement declaringClass)
57     {
58         super(impl);
59         _declaringClass = declaringClass;
60     }
61
62     /** @return the current implementation.
63      */

64     final Impl getMemberImpl () { return (Impl)getImpl(); }
65
66     /** Get the declaring class.
67      * @return the class that owns this member element, or <code>null</code>
68      * if the element is not attached to any class
69      */

70     public PersistenceClassElement getDeclaringClass ()
71     {
72         return _declaringClass;
73     }
74
75     //=============== extra set methods needed for xml archiver ==============
76

77     /** Set the declaring class of this member element. This method should
78      * only be used internally and for cloning and archiving.
79      * @param declaringClass the declaring class of this member element
80      */

81     public void setDeclaringClass (PersistenceClassElement declaringClass)
82     {
83         _declaringClass = declaringClass;
84     }
85
86     /** Overrides PersistenceElement's <code>equals</code> method to add
87      * comparison of the name of the declaring class this persistence element.
88      * The method returns <code>false</code> if obj does not have a declaring
89      * class with the same name as this persistence element.
90      * @return <code>true</code> if this object is the same as the obj argument;
91      * <code>false</code> otherwise.
92      * @param obj the reference object with which to compare.
93      */

94     public boolean equals (Object JavaDoc obj)
95     {
96         if (super.equals(obj) && (obj instanceof PersistenceMemberElement))
97         {
98             PersistenceClassElement declaringClass = getDeclaringClass();
99             PersistenceClassElement objDeclaringClass =
100                 ((PersistenceMemberElement)obj).getDeclaringClass();
101
102             return ((declaringClass == null) ? (objDeclaringClass == null) :
103                 declaringClass.equals(objDeclaringClass));
104         }
105
106         return false;
107     }
108
109     /** Overrides PersistenceElement's <code>hashCode</code> method to add
110      * the hashCode of this persistence element's declaring class.
111      * @return a hash code value for this object.
112      */

113     public int hashCode ()
114     {
115         PersistenceClassElement declaringClass = getDeclaringClass();
116
117         return (super.hashCode() +
118             ((declaringClass == null) ? 0 : declaringClass.hashCode()));
119     }
120
121     /** Pluggable implementation of member elements.
122      * @see PersistenceMemberElement
123      */

124     public interface Impl extends PersistenceElement.Impl { }
125 }
126
127
Popular Tags