KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > spi > persistence > support > sqlstore > query > util > type > FieldInfo


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  * FieldInfo.java
26  *
27  * Created on May 2, 2000
28  */

29
30 package com.sun.jdo.spi.persistence.support.sqlstore.query.util.type;
31
32 import java.lang.reflect.Field JavaDoc;
33 import java.lang.reflect.Modifier JavaDoc;
34 import java.util.ResourceBundle JavaDoc;
35
36 import com.sun.jdo.api.persistence.model.jdo.PersistenceFieldElement;
37 import com.sun.jdo.api.persistence.model.jdo.RelationshipElement;
38 import com.sun.jdo.api.persistence.support.JDOFatalInternalException;
39 import com.sun.jdo.spi.persistence.utility.I18NHelper;
40
41 /**
42  *
43  */

44 public class FieldInfo
45 {
46     /**
47      * The name of the field.
48      */

49     protected String JavaDoc name;
50
51     /**
52      * The corresponding classType object.
53      */

54     protected ClassType classType;
55     
56     /**
57      * The reflection representation of the field.
58      */

59     protected Field JavaDoc field;
60
61     /**
62      * JDO model representation
63      */

64     protected PersistenceFieldElement pfe;
65
66     /**
67      * I18N support
68      */

69     protected final static ResourceBundle JavaDoc messages = I18NHelper.loadBundle(
70         "com.sun.jdo.spi.persistence.support.sqlstore.query.Bundle", // NOI18N
71
FieldInfo.class.getClassLoader());
72
73     /**
74      *
75      */

76     public FieldInfo (Field JavaDoc field, ClassType classType)
77     {
78         this.name = field.getName();
79         this.classType = classType;
80         this.field = field;
81         this.pfe = (classType.pce != null) ? classType.pce.getField(this.name) : null;
82     }
83
84     /**
85      * Checks whether this field is defined as persistent field.
86      * @return true if the field is defined as persistent;
87      * false otherwise.
88      */

89     public boolean isPersistent()
90     {
91         if (pfe != null)
92         {
93             return pfe.getPersistenceType() == PersistenceFieldElement.PERSISTENT;
94         }
95         return false;
96     }
97     
98     /**
99      * Checks whether this field is defined with the public modifier.
100      * @return true if the field is defined as public;
101      * false otherwise.
102      */

103     public boolean isPublic()
104     {
105         return (field != null) && Modifier.isPublic(field.getModifiers());
106     }
107     /**
108      * Checks whether this field is defined with the static modifier.
109      * @return true if the field is defined as static;
110      * false otherwise.
111      */

112     public boolean isStatic()
113     {
114         return (field != null) && Modifier.isStatic(field.getModifiers());
115     }
116     
117     /**
118      *
119      */

120     public Field JavaDoc getField ()
121     {
122         return field;
123     }
124     
125     /**
126      *
127      */

128     public String JavaDoc getName ()
129     {
130         return name;
131     }
132     
133     /**
134      * Returns the Type representation of the type of the field.
135      * @return field type
136      */

137     public Type getType()
138     {
139         if (field == null)
140             return classType.typetab.errorType;
141         
142         Type ret = classType.typetab.checkType(field.getType());
143         if (ret == null)
144             ret = classType.typetab.errorType;
145         return ret;
146             
147     }
148
149     /**
150      * Return the field number in the case of a field of a persistence capable class.
151      */

152     public int getFieldNumber()
153     {
154         if (pfe != null)
155         {
156             int index = pfe.getFieldNumber();
157             if (index < 0)
158                 throw new JDOFatalInternalException(I18NHelper.getMessage(
159                     messages, "query.util.type.fieldinfo.getfieldnumber.invalidfieldno", //NO18N
160
String.valueOf(index), name));
161             return index;
162         }
163         else
164         {
165             throw new JDOFatalInternalException(I18NHelper.getMessage(
166                 messages, "query.util.type.fieldinfo.getfieldnumber.missingfieldelement", //NO18N
167
name));
168         }
169     }
170
171     /**
172      * @return true if the field is a relationship field
173      */

174     public boolean isRelationship()
175     {
176         return ((pfe != null) && (pfe instanceof RelationshipElement));
177     }
178
179     /**
180      * @return the associated class (meaning the "other side") of the relationship;
181      * or null if this does not denote a relationship field.
182      */

183     public Type getAssociatedClass()
184     {
185         Type associatedClass = null;
186         if ((pfe != null) && (pfe instanceof RelationshipElement))
187         {
188             String JavaDoc className = ((RelationshipElement)pfe).getElementClass();
189             associatedClass = classType.typetab.checkType(className);
190         }
191         return associatedClass;
192     }
193     
194 }
195
Popular Tags