KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > ejb > cmp3 > metadata > accessors > objects > MetadataAccessibleObject


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
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
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 in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22
package oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.objects;
23
24 import java.lang.reflect.Type JavaDoc;
25 import java.lang.reflect.AnnotatedElement JavaDoc;
26
27 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataHelper;
28
29 /**
30  * Parent object that is used to hold onto a valid EJB 3.0 decorated method
31  * or field.
32  *
33  * @author Guy Pelletier
34  * @since TopLink 10.1.3/EJB 3.0 Preview
35  */

36 public abstract class MetadataAccessibleObject {
37     private String JavaDoc m_name;
38     private Class JavaDoc m_rawClass;
39     private Type JavaDoc m_relationType;
40     private String JavaDoc m_attributeName;
41     private Class JavaDoc m_referenceClass;
42     private AnnotatedElement JavaDoc m_annotatedElement;
43     
44     /**
45      * INTERNAL:
46      */

47     public MetadataAccessibleObject(AnnotatedElement JavaDoc annotatedElement) {
48         m_annotatedElement = annotatedElement;
49     }
50     
51     /**
52      * INTERNAL:
53      * Return the actual field or method.
54      */

55     public AnnotatedElement JavaDoc getAnnotatedElement() {
56         return m_annotatedElement;
57     }
58     
59     /**
60      * INTERNAL:
61      * Set the relation type of this accessible object.
62      */

63     public String JavaDoc getAttributeName() {
64         return m_attributeName;
65     }
66     
67     /**
68      * INTERNAL:
69      * Set the relation type of this accessible object.
70      */

71     public String JavaDoc getName() {
72         return m_name;
73     }
74     
75     /**
76      * INTERNAL:
77      * Return the raw class for this accessible object. E.g. For an accessible
78      * object with a type of java.util.Collection<Employee>, this method will
79      * return java.util.Collection.
80      */

81     public Class JavaDoc getRawClass() {
82         if (m_rawClass == null) {
83             if (MetadataHelper.isGenericCollectionType(m_relationType)) {
84                 // By default, the raw class is equal to the relation
85
// class. But if the relation class is a generic we need to
86
// extract and set the actual raw class from the generic.
87
m_rawClass = MetadataHelper.getRawClassFromGeneric(m_relationType);
88             } else {
89                 m_rawClass = (Class JavaDoc) m_relationType;
90             }
91         }
92         
93         return m_rawClass;
94     }
95     
96     /**
97      * INTERNAL:
98      * Return the reference class for this accessible object.
99      */

100     public Class JavaDoc getReferenceClass() {
101         if (m_referenceClass == null) {
102             if (MetadataHelper.isGenericCollectionType(m_relationType)) {
103                 // By default, the reference class is equal to the relation
104
// class. But if the relation class is a generic we need to
105
// extract and set the actual reference class from the generic.
106
m_referenceClass = MetadataHelper.getReturnTypeFromGeneric(m_relationType);
107             } else {
108                 m_referenceClass = (Class JavaDoc) m_relationType;
109             }
110         }
111         
112         return m_referenceClass;
113     }
114     
115     /**
116      * INTERNAL:
117      * Return the relation type of this accessible object.
118      */

119     public Type JavaDoc getRelationType() {
120         return m_relationType;
121     }
122     
123     /**
124      * INTERNAL:
125      * Set the annotated element for this accessible object.
126      * Once the class loader changes, we need to be able to update our
127      * classes.
128      */

129     public void setAnnotatedElement(AnnotatedElement JavaDoc annotatedElement) {
130         m_annotatedElement = annotatedElement;
131     }
132     
133     /**
134      * INTERNAL:
135      * Set the relation type of this accessible object.
136      */

137     protected void setAttributeName(String JavaDoc attributeName) {
138         m_attributeName = attributeName;
139     }
140     
141     /**
142      * INTERNAL:
143      * Set the relation type of this accessible object.
144      */

145     protected void setName(String JavaDoc name) {
146         m_name = name;
147     }
148     
149     /**
150      * INTERNAL:
151      * Return the reference class for this accessible object.
152      */

153     public void setReferenceClass(Class JavaDoc referenceClass) {
154         m_referenceClass = referenceClass;
155     }
156     
157     /**
158      * INTERNAL:
159      * Set the relation type of this accessible object.
160      */

161     protected void setRelationType(Type JavaDoc relationType) {
162         m_relationType = relationType;
163     }
164 }
165
Popular Tags