KickJava   Java API By Example, From Geeks To Geeks.

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


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  * PersistenceFieldElement.java
26  *
27  * Created on February 29, 2000, 1:11 PM
28  */

29
30 package com.sun.jdo.api.persistence.model.jdo;
31
32 import java.util.ArrayList JavaDoc;
33
34 import com.sun.jdo.api.persistence.model.ModelException;
35
36 /* TODO:
37     1. throw (Model or IllegalArgument)Exception on set illegal constant values?
38         also applies to PersistenceClass, Relationship classes
39     2. document default values for all constants (should that go in impl docs?)
40         also applies to PersistenceClass, Relationship classes
41  */

42
43 /**
44  *
45  * @author raccah
46  * @version %I%
47  */

48 public class PersistenceFieldElement extends PersistenceMemberElement
49 {
50     /** Constant representing a persistent field modifier. */
51     public static final int PERSISTENT = 0;
52
53     /** Constant representing a derived field modifier. */
54     public static final int DERIVED = 1;
55
56     /** Constant representing a transient field modifier. This constant is
57      * only here for comparison purposes, it will not be returned by
58      * <code>getPersistenceType</code> since there will be no instance of
59      * this class for transient fields.
60      */

61     public static final int TRANSIENT = 2;
62
63     /** Create new PersistenceFieldElement with no implementation.
64      * This constructor should only be used for cloning and archiving.
65      */

66     public PersistenceFieldElement ()
67     {
68         this(null, null);
69     }
70
71     /** Create new PersistenceFieldElement with the provided implementation. The
72      * implementation is responsible for storing all properties of the object.
73      * @param impl the implementation to use
74      * @param declaringClass the class to attach to
75      */

76     public PersistenceFieldElement (PersistenceFieldElement.Impl impl,
77         PersistenceClassElement declaringClass)
78     {
79         super(impl, declaringClass);
80     }
81
82     /** @return implemetation factory for this field
83      */

84     final Impl getFieldImpl () { return (Impl)getImpl(); }
85
86     /** Get the persistence type of this field element.
87      * @return the persistence type, one of {@link #PERSISTENT} or
88      * {@link #DERIVED}
89      */

90     public int getPersistenceType ()
91     {
92         return getFieldImpl().getPersistenceType();
93     }
94
95     /** Set the persistence type of this field element.
96      * @param type - an integer indicating the persistence type, one of:
97      * {@link #PERSISTENT} or {@link #DERIVED}
98      * @exception ModelException if impossible
99      */

100     public void setPersistenceType (int type) throws ModelException
101     {
102         getFieldImpl().setPersistenceType(type);
103     }
104
105     /** Determines whether this field element is read sensitive or not.
106      * This value is only used if <code>getPersistenceType</code> returns
107      * <code>DERIVED</code>
108      * @return <code>true</code> if the field is read sensitive,
109      * <code>false</code> if it is not or if the persistence type is not derived
110      * @see #isWriteSensitive
111      * @see #setPersistenceType
112      * @see #DERIVED
113      */

114     public boolean isReadSensitive ()
115     {
116         return ((getPersistenceType() == DERIVED) &&
117             getFieldImpl().isReadSensitive());
118     }
119
120     /** Set whether this field element is read sensitive or not.
121      * @param flag - if <code>true</code> and this is a derived field, the field
122      * element is marked as read sensitive; otherwise, it is not
123      * This value is only used if <code>getPersistenceType</code> returns
124      * <code>DERIVED</code>
125      * @exception ModelException if impossible
126      * @see #setWriteSensitive
127      * @see #setPersistenceType
128      * @see #DERIVED
129      */

130     public void setReadSensitive (boolean flag) throws ModelException
131     {
132         getFieldImpl().setReadSensitive(flag);
133     }
134
135     /** Determines whether this field element is write sensitive or not.
136      * This value is only used if <code>getPersistenceType</code> returns
137      * <code>DERIVED</code>
138      * @return <code>true</code> if the field is write sensitive,
139      * <code>false</code> if it is not or if the persistence type is not derived
140      * @see #isReadSensitive
141      * @see #setPersistenceType
142      * @see #DERIVED
143      */

144     public boolean isWriteSensitive ()
145     {
146         return ((getPersistenceType() == DERIVED) &&
147             getFieldImpl().isWriteSensitive());
148     }
149
150     /** Set whether this field element is write sensitive or not.
151      * @param flag - if <code>true</code> and this is a derived field, the field
152      * element is marked as write sensitive; otherwise, it is not
153      * This value is only used if <code>getPersistenceType</code> returns
154      * <code>DERIVED</code>
155      * @exception ModelException if impossible
156      * @see #setReadSensitive
157      * @see #setPersistenceType
158      * @see #DERIVED
159      */

160     public void setWriteSensitive (boolean flag) throws ModelException
161     {
162         getFieldImpl().setWriteSensitive(flag);
163     }
164
165     /** Determines whether this field element is a key field or not.
166      * @return <code>true</code> if the field is a key field,
167      * <code>false</code> otherwise
168      * @see PersistenceClassElement#getKeyClass
169      */

170     public boolean isKey () { return getFieldImpl().isKey(); }
171
172     /** Set whether this field element is a key field or not.
173      * @param flag - if <code>true</code>, the field element is marked
174      * as a key field; otherwise, it is not
175      * @exception ModelException if impossible
176      * @see PersistenceClassElement#getKeyClass
177      */

178     public void setKey (boolean flag) throws ModelException
179     {
180         getFieldImpl().setKey(flag);
181     }
182
183     //================== ConcurrencyGroups ===============================
184
// convenience method to access ConcurrencyGroupElements
185

186     /** Returns the array of concurrency groups to which this field belongs.
187      * @return the concurrency groups in which this field participates
188      * @see PersistenceClassElement#getConcurrencyGroups
189      */

190     public ConcurrencyGroupElement[] getConcurrencyGroups ()
191     {
192         ConcurrencyGroupElement[] groups = getDeclaringClass().
193             getConcurrencyGroups();
194         int i, count = ((groups != null) ? groups.length : 0);
195         ArrayList JavaDoc myGroups = new ArrayList JavaDoc(count);
196
197         for (i = 0; i < count; i++)
198         {
199             ConcurrencyGroupElement group = groups[i];
200
201             if (group.containsField(this))
202                 myGroups.add(group);
203         }
204         
205         count = myGroups.size();
206
207         return ((ConcurrencyGroupElement[])myGroups.toArray(
208             new ConcurrencyGroupElement[count]));
209     }
210
211     /** Computes the field number of this field element.
212      * @return the field number of this field, -1 if it cannot be found
213      */

214     public int getFieldNumber ()
215     {
216         // for later - take into account the class
217
// get/setFieldInheritanceFlag behavior (i.e. might need to climb
218
// inheritance hierarchy
219
PersistenceFieldElement[] fields = getDeclaringClass().getFields();
220         int i, count = ((fields != null) ? fields.length : 0);
221
222         for (i = 0; i < count; i++)
223             if (equals(fields[i]))
224                 return i;
225
226         return -1;
227     }
228
229     /* won't be used now -- we will compute this number whenever it is requested
230     public void setFieldNumber (int fieldNumber) {} */

231
232     /** Pluggable implementation of the storage of field element properties.
233      * @see PersistenceFieldElement#PersistenceFieldElement
234      */

235     public interface Impl extends PersistenceMemberElement.Impl
236     {
237         /** Get the persistence type of this field element.
238          * @return the persistence type, one of {@link #PERSISTENT} or
239          * {@link #DERIVED}
240          */

241         public int getPersistenceType ();
242
243         /** Set the persistence type of this field element.
244          * @param type - an integer indicating the persistence type, one of:
245          * {@link #PERSISTENT} or {@link #DERIVED}
246          * @exception ModelException if impossible
247          */

248         public void setPersistenceType (int type) throws ModelException;
249
250         /** Determines whether this field element is read sensitive or not.
251          * This value is only used if <code>getPersistenceType</code> returns
252          * <code>DERIVED</code>
253          * @return <code>true</code> if the field is read sensitive,
254          * <code>false</code> if it is not or if the persistence type is not
255          * derived
256          * @see #isWriteSensitive
257          * @see #setPersistenceType
258          * @see #DERIVED
259          *
260          */

261         public boolean isReadSensitive ();
262
263         /** Set whether this field element is read sensitive or not.
264          * @param flag - if <code>true</code> and this is a derived field, the
265          * field element is marked as read sensitive; otherwise, it is not
266          * This value is only used if <code>getPersistenceType</code> returns
267          * <code>DERIVED</code>
268          * @exception ModelException if impossible
269          * @see #setWriteSensitive
270          * @see #setPersistenceType
271          * @see #DERIVED
272          */

273         public void setReadSensitive (boolean flag) throws ModelException;
274
275         /** Determines whether this field element is write sensitive or not.
276          * This value is only used if <code>getPersistenceType</code> returns
277          * <code>DERIVED</code>
278          * @return <code>true</code> if the field is write sensitive,
279          * <code>false</code> if it is not or if the persistence type is not
280          * derived
281          * @see #isReadSensitive
282          * @see #setPersistenceType
283          * @see #DERIVED
284          *
285          */

286         public boolean isWriteSensitive ();
287
288         /** Set whether this field element is write sensitive or not.
289          * @param flag - if <code>true</code> and this is a derived field, the
290          * field element is marked as write sensitive; otherwise, it is not
291          * This value is only used if <code>getPersistenceType</code> returns
292          * <code>DERIVED</code>
293          * @exception ModelException if impossible
294          * @see #setReadSensitive
295          * @see #setPersistenceType
296          * @see #DERIVED
297          */

298         public void setWriteSensitive (boolean flag) throws ModelException;
299
300         /** Determines whether this field element is a key field or not.
301          * @return <code>true</code> if the field is a key field,
302          * <code>false</code> otherwise
303          * @see PersistenceClassElement#getKeyClass
304          */

305         public boolean isKey ();
306
307         /** Set whether this field element is a key field or not.
308          * @param flag - if <code>true</code>, the field element is marked
309          * as a key field; otherwise, it is not
310          * @exception ModelException if impossible
311          * @see PersistenceClassElement#getKeyClass
312          */

313         public void setKey (boolean flag) throws ModelException;
314     }
315 }
316
Popular Tags