KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > api > persistence > enhancer > impl > FieldAction


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 package com.sun.jdo.api.persistence.enhancer.impl;
26
27 import java.util.Map JavaDoc;
28 import java.util.Enumeration JavaDoc;
29
30 import com.sun.jdo.api.persistence.enhancer.classfile.ClassFile;
31 import com.sun.jdo.api.persistence.enhancer.classfile.ClassField;
32 import com.sun.jdo.api.persistence.enhancer.classfile.VMConstants;
33 import com.sun.jdo.api.persistence.enhancer.classfile.Descriptor;
34
35 import com.sun.jdo.api.persistence.enhancer.util.Support;
36 import com.sun.jdo.api.persistence.enhancer.util.InternalError;
37
38 //@olsen: added import
39
import com.sun.jdo.api.persistence.enhancer.meta.JDOMetaData;
40
41
42 //@olsen: cosmetics
43
//@olsen: moved: this class -> package impl
44
//@olsen: subst: [iI]Persistent -> [pP]ersistenceCapable
45
//@olsen: subst: jdo/ -> com/sun/forte4j/persistence/internal/
46
//@olsen: subst: /* ... */ -> // ...
47
//@olsen: subst: isKnownPersistent -> JDOMetaData.isSecondClassObjectType
48
//@olsen: subst: FilterEnv -> Environment
49
//@olsen: dropped parameter 'Environment env', use association instead
50
//@olsen: subst: Hashtable -> Map, HashMap
51
//@olsen: subst: absolut jdo types and names -> constants from JDOMetaData
52
//@olsen: subst: theClass, classAction -> ca
53
//@olsen: added: support for I18N
54
//@olsen: subst: FilterError -> UserException, affirm()
55
//@olsen: removed: proprietary support for FieldNote
56
//@olsen: removed: proprietary support for IndexableField
57
//@olsen: removed: support for IgnoreTransientField, AddedTransientField
58
//@olsen: removed: old, disabled ODI code
59

60 //^olsen: clean-up fieldTypeInfo
61
//^olsen: remove proprietary support for ClassInfo
62

63 /**
64  * FieldAction contains the annotation related information specific
65  * to a single field of a class.
66  */

67 final class FieldAction
68     extends Support
69     implements VMConstants {
70
71     /* The field which we contain information about */
72     //@olsen: made final
73
private ClassField theField;
74
75     /* The parent ClassAction of this FieldAction */
76     //@olsen: made final
77
private ClassAction ca;
78
79     /* Central repository for the options and classes */
80     //@olsen: added association
81
//@olsen: made final
82
private final Environment env;
83
84     /* true if this persistent field is primary key. */
85     //@olsen: added field
86
private boolean fieldIsPrimaryKey;
87
88     /* true if this persistent field's value is a second class object. */
89     //@olsen: added field
90
private boolean fieldIsMutableSCO;
91
92     /* true if this is a non-static, non-final, non-transient field
93      * and the declared type appears to be perisistence-capable.
94      * This is not valid until the check method runs */

95     private boolean fieldIsPersistent;
96
97     /* zero for a non-array - otherwise, the number of array dimensions in
98      * the type of the field. */

99     private int nFieldArrayDims;
100
101     /* Name of class or interface type, or base type of array */
102     private String JavaDoc fieldClassName;
103
104     /* Information about the type of the field. Used to determine how
105      * to initialize, flush, clear, etc. */

106     private FieldTypeInfo fieldTypeInfo;
107
108     /* The persistent field index for this method */
109 //@olsen: disabled feature
110
/*
111     private int fieldIndex = -1;
112 */

113
114     /**
115      * Constructor.
116      */

117     //@olsen: added parameter 'env' for association
118
FieldAction(ClassAction ca,
119                 ClassField field,
120                 Environment env) {
121         this.ca = ca;
122         this.theField = field;
123         this.env = env;
124     }
125
126     // package accessors
127

128     /**
129      * Get the VM type descriptor field string for the field type
130      */

131     String JavaDoc typeDescriptor() {
132         return theField.signature().asString();
133     }
134
135     /**
136      * Get the VM type name field string for the field type
137      * This is the same as the type descriptor except when it is
138      * a non-array class - in this case, the leading 'L' and trailing
139      * ';' need to be removed.
140      */

141     String JavaDoc typeName() {
142         String JavaDoc typeDesc = typeDescriptor();
143         if (typeDesc.charAt(0) == 'L')
144             return typeDesc.substring(1, typeDesc.length() - 1);
145         return typeDesc;
146     }
147
148     /**
149      * Get the field index for this field.
150      * The index must have previously been set.
151      */

152 //@olsen: disabled feature
153
/*
154     int index() {
155         if (fieldIndex < 0)
156             throw new InternalError("The field index has not yet been set");
157         return fieldIndex;
158     }
159 */

160
161     /**
162      * Set the field index for this field.
163      */

164 //@olsen: disabled feature
165
/*
166     void setIndex(int idx) {
167         fieldIndex = idx;
168     }
169 */

170
171     /**
172      * Is this persistent field primary key?
173      */

174     //@olsen: added method
175
boolean isPrimaryKey() {
176         return fieldIsPrimaryKey;
177     }
178
179     /**
180      * Is this persistent field's value is a second class object?
181      */

182     //@olsen: added method
183
boolean isMutableSCO() {
184         return fieldIsMutableSCO;
185     }
186
187     /**
188      * Is this field one which is stored persistently? This can only
189      * be true for non-static, non-final fields.
190      */

191     boolean isPersistent() {
192         return fieldIsPersistent;
193     }
194
195     /**
196      * Return the name of the field
197      */

198     String JavaDoc fieldName() {
199         return theField.name().asString();
200     }
201
202     /**
203      * Is the field a synthetic field?
204      * This is a java 1.1'ism for nested classes
205      */

206     boolean isSynthetic() {
207         return theField.attributes().findAttribute("Synthetic") != null;//NOI18N
208
}
209
210     /**
211      * Return the name of the static method on class Field which
212      * will create a Field of the appropriate type.
213      */

214     String JavaDoc createMethod() {
215         return fieldTypeInfo.fieldCreateMethod;
216     }
217
218     /**
219      * Return the type signature of the static method on class Field which
220      * will create a Field of the appropriate type.
221      */

222     String JavaDoc createMethodSig() {
223         return fieldTypeInfo.fieldCreateMethodSig;
224     }
225
226     /**
227      * Return the name of the static method on class GenericObject which
228      * will set the field value.
229      */

230     String JavaDoc setMethod() {
231         return fieldTypeInfo.fieldSetMethod;
232     }
233
234     /**
235      * Return the type signature of the static method on class GenericObject
236      * which will set the field value.
237      */

238     String JavaDoc setMethodSig() {
239         return fieldTypeInfo.fieldSetMethodSig;
240     }
241
242     /**
243      * Return the type of arg expected by the set method.
244      */

245     int setMethodArg() {
246         return fieldTypeInfo.fieldSetArgType;
247     }
248
249     /**
250      * Return the name of the static method on class GenericObject which
251      * will get the field value.
252      */

253     String JavaDoc getMethod() {
254         return fieldTypeInfo.fieldGetMethod;
255     }
256
257     /**
258      * Return the type signature of the static method on class GenericObject
259      * which will get the field value.
260      */

261     String JavaDoc getMethodSig() {
262         return fieldTypeInfo.fieldGetMethodSig;
263     }
264
265     /**
266      * Return the return type of the get method.
267      */

268     int getMethodReturn() {
269         return fieldTypeInfo.fieldGetReturnType;
270     }
271
272     /**
273      * For references fields, return the base type class name if a class
274      * or interface, else null.
275      */

276     String JavaDoc fieldClassName() {
277         return fieldClassName;
278     }
279
280     /**
281      * For array fields, return the number of dimensions in the array type
282      * else 0.
283      */

284     int nDims () {
285         return nFieldArrayDims;
286     }
287
288     /**
289      * Examine the field to decide what actions are required
290      */

291     void check() {
292         //@olsen: improved control flow
293
//@olsen: dropped code computing persistence information;
294
// used JDO meta data instead
295

296         String JavaDoc sig = theField.signature().asString();
297         fieldTypeInfo = FieldTypeInfo.determineFieldType(sig, env);
298
299         final String JavaDoc className = ca.className();
300         final String JavaDoc userClass = ca.userClassName();
301         final String JavaDoc fieldName = theField.name().asString();
302         final String JavaDoc fullFieldName = userFieldName();
303
304         //@olsen: added shortcut
305
final JDOMetaData jdoMetaData = env.getJDOMetaData();
306
307         //@olsen: use JDO meta data to decide whether a field is persistent
308
//@olsen: subst: fieldShouldBeTransient -> !fieldShouldBePersistent
309
final boolean fieldShouldBePersistent
310             = jdoMetaData.isPersistentField(className, fieldName);
311         //@olsen: added println() for debugging
312
if (false) {
313             System.out.println("FieldAction.check(): field "//NOI18N
314
+ className + "/" + fieldName//NOI18N
315
+ " should be persistent = "//NOI18N
316
+ fieldShouldBePersistent);
317         }
318
319         //@olsen: initialized property from JDO meta data
320
fieldIsPrimaryKey
321             = jdoMetaData.isPrimaryKeyField(className, fieldName);
322         //@olsen: added println() for debugging
323
if (false) {
324             System.out.println("FieldAction.check(): field "//NOI18N
325
+ className + "/" + fieldName//NOI18N
326
+ " is primary key = "//NOI18N
327
+ fieldIsPrimaryKey);
328         }
329
330         //@olsen: initialized property from JDO meta data
331
fieldIsMutableSCO
332             = jdoMetaData.isMutableSecondClassObjectType(typeName());
333         //@olsen: added println() for debugging
334
if (false) {
335             System.out.println("FieldAction.check(): field "//NOI18N
336
+ className + "/" + fieldName//NOI18N
337
+ " is mutable SCO = "//NOI18N
338
+ fieldIsMutableSCO);
339         }
340
341         nFieldArrayDims = 0;
342         while (sig.charAt(nFieldArrayDims) == '[')
343             nFieldArrayDims++;
344
345         // If the base type is a class type, compute the class name
346
if (sig.charAt(nFieldArrayDims) == 'L')
347             fieldClassName = sig.substring(nFieldArrayDims+1, sig.length()-1);
348
349         // check for transient field
350
if (!fieldShouldBePersistent) {
351             // done with transient field
352
return;
353         }
354
355         //@olsen: dropped code ...
356

357         // check for static field
358
affirm(!theField.isStatic(),
359                ("The field " + fullFieldName//NOI18N
360
+ " is a static field which cannot be made persistent."));//NOI18N
361

362         // check for final field
363
affirm(!theField.isFinal(),
364                ("The field " + fullFieldName +//NOI18N
365
" is a final field which cannot be made persistent."));//NOI18N
366

367         // check for target type
368
affirm((fieldClassName == null
369                 || jdoMetaData.isSecondClassObjectType(fieldClassName)
370                 || jdoMetaData.isPersistenceCapableClass(fieldClassName)),
371                ("The field " + fullFieldName//NOI18N
372
+ " cannot be made persistent because of a non-primitive, "//NOI18N
373
+ " non-sco, or non-pc target type " + fieldClassName));//NOI18N
374

375         fieldIsPersistent = true;
376     }
377
378     /**
379      * Retarget class references according to the class name mapping
380      * table.
381      */

382 //@olsen: disabled feature
383
/*
384     void retarget(Map classTranslations) {
385         if (fieldClassName != null) {
386             String mapTo = (String)classTranslations.get(fieldClassName);
387             if (mapTo != null)
388                 fieldClassName = mapTo;
389         }
390     }
391 */

392
393     /**
394      * Return a user consumable field name
395      */

396     String JavaDoc userFieldName() {
397         return ca.userClassName() + "." + theField.name().asString();//NOI18N
398
}
399
400     /**
401      * Return a user consumable signature
402      */

403     private String JavaDoc userSig(String JavaDoc vmSig) {
404         // Stub: just return vm sig for now
405
return Descriptor.userFieldSig(vmSig);
406     }
407 }
408
409
410 class FieldTypeInfo
411     extends Support
412     implements VMConstants {
413
414     /* Name and type signature of the Field.create method */
415     String JavaDoc fieldCreateMethod;
416     String JavaDoc fieldCreateMethodSig;
417
418     /* Name and type signature of the GenericObject.get method */
419     String JavaDoc fieldGetMethod;
420     String JavaDoc fieldGetMethodSig;
421     int fieldGetReturnType;
422
423     /* Name and type signature of the GenericObject.set method */
424     String JavaDoc fieldSetMethod;
425     String JavaDoc fieldSetMethodSig;
426     int fieldSetArgType;
427
428     // constructor
429

430     private FieldTypeInfo(String JavaDoc createName, String JavaDoc createSig,
431                           String JavaDoc setName, String JavaDoc setSig, int argType,
432                           String JavaDoc getName, String JavaDoc getSig, int returnType) {
433         fieldCreateMethod = createName;
434         fieldCreateMethodSig = createSig;
435         fieldGetMethod = getName;
436         fieldGetMethodSig = getSig;
437         fieldGetReturnType = returnType;
438         fieldSetMethod = setName;
439         fieldSetMethodSig = setSig;
440         fieldSetArgType = argType;
441     }
442
443     static private FieldTypeInfo byteInfo =
444     new FieldTypeInfo("createByte", "(Ljava/lang/String;)Lcom/sun/forte4j/persistence/internal/Field;",//NOI18N
445
"setByteField", "(IBLcom/sun/forte4j/persistence/internal/ClassInfo;)V", T_BYTE,//NOI18N
446
"getByteField", "(ILcom/sun/forte4j/persistence/internal/ClassInfo;)B", T_BYTE);//NOI18N
447

448     static private FieldTypeInfo charInfo =
449     new FieldTypeInfo("createChar", "(Ljava/lang/String;)Lcom/sun/forte4j/persistence/internal/Field;",//NOI18N
450
"setCharField", "(ICLcom/sun/forte4j/persistence/internal/ClassInfo;)V", T_CHAR,//NOI18N
451
"getCharField", "(ILcom/sun/forte4j/persistence/internal/ClassInfo;)C", T_CHAR);//NOI18N
452

453     static private FieldTypeInfo shortInfo =
454     new FieldTypeInfo("createShort", "(Ljava/lang/String;)Lcom/sun/forte4j/persistence/internal/Field;",//NOI18N
455
"setShortField", "(ISLcom/sun/forte4j/persistence/internal/ClassInfo;)V", T_SHORT,//NOI18N
456
"getShortField", "(ILcom/sun/forte4j/persistence/internal/ClassInfo;)S", T_SHORT);//NOI18N
457

458     static private FieldTypeInfo intInfo =
459     new FieldTypeInfo("createInt", "(Ljava/lang/String;)Lcom/sun/forte4j/persistence/internal/Field;",//NOI18N
460
"setIntField", "(IILcom/sun/forte4j/persistence/internal/ClassInfo;)V", T_INT,//NOI18N
461
"getIntField", "(ILcom/sun/forte4j/persistence/internal/ClassInfo;)I", T_INT);//NOI18N
462

463     static private FieldTypeInfo longInfo =
464     new FieldTypeInfo("createLong", "(Ljava/lang/String;)Lcom/sun/forte4j/persistence/internal/Field;",//NOI18N
465
"setLongField", "(IJLcom/sun/forte4j/persistence/internal/ClassInfo;)V", T_LONG,//NOI18N
466
"getLongField", "(ILcom/sun/forte4j/persistence/internal/ClassInfo;)J", T_LONG);//NOI18N
467

468     static private FieldTypeInfo floatInfo =
469     new FieldTypeInfo("createFloat", "(Ljava/lang/String;)Lcom/sun/forte4j/persistence/internal/Field;",//NOI18N
470
"setFloatField", "(IFLcom/sun/forte4j/persistence/internal/ClassInfo;)V", T_FLOAT,//NOI18N
471
"getFloatField", "(ILcom/sun/forte4j/persistence/internal/ClassInfo;)F", T_FLOAT);//NOI18N
472

473     static private FieldTypeInfo doubleInfo =
474     new FieldTypeInfo("createDouble", "(Ljava/lang/String;)Lcom/sun/forte4j/persistence/internal/Field;",//NOI18N
475
"setDoubleField", "(IDLcom/sun/forte4j/persistence/internal/ClassInfo;)V", T_DOUBLE,//NOI18N
476
"getDoubleField", "(ILcom/sun/forte4j/persistence/internal/ClassInfo;)D", T_DOUBLE);//NOI18N
477

478     static private FieldTypeInfo booleanInfo =
479     new FieldTypeInfo("createBoolean", "(Ljava/lang/String;)Lcom/sun/forte4j/persistence/internal/Field;",//NOI18N
480
"setBooleanField", "(IZLcom/sun/forte4j/persistence/internal/ClassInfo;)V", T_BOOLEAN,//NOI18N
481
"getBooleanField", "(ILcom/sun/forte4j/persistence/internal/ClassInfo;)Z", T_BOOLEAN);
482
483     static private FieldTypeInfo classInfo =
484     new FieldTypeInfo("createClass", "(Ljava/lang/String;Ljava/lang/String;)Lcom/sun/forte4j/persistence/internal/Field;",//NOI18N
485
"setClassField", "(ILjava/lang/Object;Lcom/sun/forte4j/persistence/internal/ClassInfo;)V", TC_OBJECT,//NOI18N
486
"getClassField", "(ILcom/sun/forte4j/persistence/internal/ClassInfo;)Ljava/lang/Object;", TC_OBJECT);//NOI18N
487

488 //@olsen: disabled feature
489
/*
490     //@olsen: don't distinguish between class and interface types
491     static private FieldTypeInfo interfaceInfo =
492     new FieldTypeInfo("createInterface", "(Ljava/lang/String;Ljava/lang/String;)Lcom/sun/forte4j/persistence/internal/Field;",
493                       "setInterfaceField", "(ILjava/lang/Object;Lcom/sun/forte4j/persistence/internal/ClassInfo;)V", TC_OBJECT,
494                       "getInterfaceField", "(ILcom/sun/forte4j/persistence/internal/ClassInfo;)Ljava/lang/Object;", TC_OBJECT);
495 */

496
497     static private FieldTypeInfo stringInfo =
498     new FieldTypeInfo("createString", "(Ljava/lang/String;)Lcom/sun/forte4j/persistence/internal/Field;",//NOI18N
499
"setStringField", "(ILjava/lang/String;Lcom/sun/forte4j/persistence/internal/ClassInfo;)V", TC_STRING,//NOI18N
500
"getStringField", "(ILcom/sun/forte4j/persistence/internal/ClassInfo;)Ljava/lang/String;", TC_STRING);//NOI18N
501

502     static private FieldTypeInfo byteArrayInfo =
503     new FieldTypeInfo("createByteArray", "(Ljava/lang/String;I)Lcom/sun/forte4j/persistence/internal/Field;",//NOI18N
504
"setArrayField", "(ILjava/lang/Object;Lcom/sun/forte4j/persistence/internal/ClassInfo;)V", TC_OBJECT,//NOI18N
505
"getArrayField", "(ILcom/sun/forte4j/persistence/internal/ClassInfo;)Ljava/lang/Object;", TC_OBJECT);//NOI18N
506

507     static private FieldTypeInfo charArrayInfo =
508     new FieldTypeInfo("createCharArray", "(Ljava/lang/String;I)Lcom/sun/forte4j/persistence/internal/Field;",//NOI18N
509
"setArrayField", "(ILjava/lang/Object;Lcom/sun/forte4j/persistence/internal/ClassInfo;)V", TC_OBJECT,//NOI18N
510
"getArrayField", "(ILcom/sun/forte4j/persistence/internal/ClassInfo;)Ljava/lang/Object;", TC_OBJECT);//NOI18N
511

512     static private FieldTypeInfo shortArrayInfo =
513     new FieldTypeInfo("createShortArray", "(Ljava/lang/String;I)Lcom/sun/forte4j/persistence/internal/Field;",//NOI18N
514
"setArrayField", "(ILjava/lang/Object;Lcom/sun/forte4j/persistence/internal/ClassInfo;)V", TC_OBJECT,//NOI18N
515
"getArrayField", "(ILcom/sun/forte4j/persistence/internal/ClassInfo;)Ljava/lang/Object;", TC_OBJECT);//NOI18N
516

517     static private FieldTypeInfo intArrayInfo =
518     new FieldTypeInfo("createIntArray", "(Ljava/lang/String;I)Lcom/sun/forte4j/persistence/internal/Field;",//NOI18N
519
"setArrayField", "(ILjava/lang/Object;Lcom/sun/forte4j/persistence/internal/ClassInfo;)V", TC_OBJECT,//NOI18N
520
"getArrayField", "(ILcom/sun/forte4j/persistence/internal/ClassInfo;)Ljava/lang/Object;", TC_OBJECT);//NOI18N
521

522     static private FieldTypeInfo longArrayInfo =
523     new FieldTypeInfo("createLongArray", "(Ljava/lang/String;I)Lcom/sun/forte4j/persistence/internal/Field;",//NOI18N
524
"setArrayField", "(ILjava/lang/Object;Lcom/sun/forte4j/persistence/internal/ClassInfo;)V", TC_OBJECT,//NOI18N
525
"getArrayField", "(ILcom/sun/forte4j/persistence/internal/ClassInfo;)Ljava/lang/Object;", TC_OBJECT);//NOI18N
526

527     static private FieldTypeInfo floatArrayInfo =
528     new FieldTypeInfo("createFloatArray", "(Ljava/lang/String;I)Lcom/sun/forte4j/persistence/internal/Field;",//NOI18N
529
"setArrayField", "(ILjava/lang/Object;Lcom/sun/forte4j/persistence/internal/ClassInfo;)V", TC_OBJECT,//NOI18N
530
"getArrayField", "(ILcom/sun/forte4j/persistence/internal/ClassInfo;)Ljava/lang/Object;", TC_OBJECT);//NOI18N
531

532     static private FieldTypeInfo doubleArrayInfo =
533     new FieldTypeInfo("createDoubleArray", "(Ljava/lang/String;I)Lcom/sun/forte4j/persistence/internal/Field;",//NOI18N
534
"setArrayField", "(ILjava/lang/Object;Lcom/sun/forte4j/persistence/internal/ClassInfo;)V", TC_OBJECT,//NOI18N
535
"getArrayField", "(ILcom/sun/forte4j/persistence/internal/ClassInfo;)Ljava/lang/Object;", TC_OBJECT);//NOI18N
536

537     static private FieldTypeInfo booleanArrayInfo =
538     new FieldTypeInfo("createBooleanArray", "(Ljava/lang/String;I)Lcom/sun/forte4j/persistence/internal/Field;",//NOI18N
539
"setArrayField", "(ILjava/lang/Object;Lcom/sun/forte4j/persistence/internal/ClassInfo;)V", TC_OBJECT,//NOI18N
540
"getArrayField", "(ILcom/sun/forte4j/persistence/internal/ClassInfo;)Ljava/lang/Object;", TC_OBJECT);//NOI18N
541

542     static private FieldTypeInfo classArrayInfo =
543     new FieldTypeInfo("createClassArray", "(Ljava/lang/String;Ljava/lang/String;I)Lcom/sun/forte4j/persistence/internal/Field;",//NOI18N
544
"setArrayField", "(ILjava/lang/Object;Lcom/sun/forte4j/persistence/internal/ClassInfo;)V", TC_OBJECT,//NOI18N
545
"getArrayField", "(ILcom/sun/forte4j/persistence/internal/ClassInfo;)Ljava/lang/Object;", TC_OBJECT);//NOI18N
546

547     static private FieldTypeInfo interfaceArrayInfo =
548     new FieldTypeInfo("createInterfaceArray", "(Ljava/lang/String;Ljava/lang/String;I)Lcom/sun/forte4j/persistence/internal/Field;",//NOI18N
549
"setArrayField", "(ILjava/lang/Object;Lcom/sun/forte4j/persistence/internal/ClassInfo;)V", TC_OBJECT,//NOI18N
550
"getArrayField", "(ILcom/sun/forte4j/persistence/internal/ClassInfo;)Ljava/lang/Object;", TC_OBJECT);//NOI18N
551

552     static private FieldTypeInfo stringArrayInfo =
553     new FieldTypeInfo("createStringArray", "(Ljava/lang/String;I)Lcom/sun/forte4j/persistence/internal/Field;",//NOI18N
554
"setArrayField", "(ILjava/lang/Object;Lcom/sun/forte4j/persistence/internal/ClassInfo;)V", TC_OBJECT,//NOI18N
555
"getArrayField", "(ILcom/sun/forte4j/persistence/internal/ClassInfo;)Ljava/lang/Object;", TC_OBJECT);//NOI18N
556

557
558     static FieldTypeInfo determineFieldType(String JavaDoc sig,
559                                             Environment env) {
560         switch (sig.charAt(0)) {
561         case 'B': // byte
562
return byteInfo;
563         case 'C': // char
564
return charInfo;
565         case 'D': // double
566
return doubleInfo;
567         case 'F': // float
568
return floatInfo;
569         case 'I': // int
570
return intInfo;
571         case 'J': // long
572
return longInfo;
573         case 'S': // short
574
return shortInfo;
575         case 'Z': // boolean
576
return booleanInfo;
577         case 'L': // class or interface
578
if (sig.equals("Ljava/lang/String;"))//NOI18N
579
return stringInfo;
580             {
581 //@olsen: disabled feature
582
//@olsen: don't distinguish between class and interface types
583
//@olsen: don't read-in classes here!
584
/*
585                 ClassControl cc
586                     = env.findClass(sig.substring(1, sig.length()-1));
587                 // Don't sweat it if we don't find the class - it's the
588                 // responsibility of the caller to check that
589                 if (cc != null && cc.classFile().isInterface())
590                     return interfaceInfo;
591 */

592                 return classInfo;
593             }
594         case '[': // array
595
int baseTypeIndex = findArrayBaseType(sig);
596             switch (sig.charAt(baseTypeIndex)) {
597             case 'B': // byte
598
return byteArrayInfo;
599             case 'C': // char
600
return charArrayInfo;
601             case 'D': // double
602
return doubleArrayInfo;
603             case 'F': // float
604
return floatArrayInfo;
605             case 'I': // int
606
return intArrayInfo;
607             case 'J': // long
608
return longArrayInfo;
609             case 'S': // short
610
return shortArrayInfo;
611             case 'Z': // boolean
612
return booleanArrayInfo;
613             case 'L': // class or interface
614
if (sig.substring(baseTypeIndex).equals("Ljava/lang/String;"))//NOI18N
615
return stringArrayInfo;
616                 {
617 //@olsen: disabled feature
618
//@olsen: don't distinguish between class and interface types
619
//@olsen: don't read-in classes here!
620
/*
621                     ClassControl cc
622                         = env.findClass(sig.substring(baseTypeIndex+1,
623                                                       sig.length()-1));
624                     // Don't sweat it if we don't find the class - it's the
625                     // responsibility of the caller to check that
626                     if (cc != null && cc.classFile().isInterface())
627                         return interfaceArrayInfo;
628 */

629                     return classArrayInfo;
630                 }
631             default:
632                 throw new InternalError JavaDoc("Missing case");//NOI18N
633
}
634
635         default:
636             throw new InternalError JavaDoc("Missing case");//NOI18N
637
}
638     }
639
640     private static int findArrayBaseType(String JavaDoc sig) {
641         int idx = 0;
642         while (sig.charAt(idx) == '[')
643             idx++;
644         return idx;
645     }
646 }
647
648
Popular Tags