FileDocCategorySizeDatePackage
FieldAction.javaAPI DocGlassfish v2 API27098Fri May 04 22:34:38 BST 2007com.sun.jdo.api.persistence.enhancer.impl

FieldAction

public final class FieldAction extends com.sun.jdo.api.persistence.enhancer.util.Support implements com.sun.jdo.api.persistence.enhancer.classfile.VMConstants
FieldAction contains the annotation related information specific to a single field of a class.

Fields Summary
private com.sun.jdo.api.persistence.enhancer.classfile.ClassField
theField
private ClassAction
ca
private final Environment
env
private boolean
fieldIsPrimaryKey
private boolean
fieldIsMutableSCO
private boolean
fieldIsPersistent
private int
nFieldArrayDims
private String
fieldClassName
private FieldTypeInfo
fieldTypeInfo
Constructors Summary
FieldAction(ClassAction ca, com.sun.jdo.api.persistence.enhancer.classfile.ClassField field, Environment env)
Constructor.

        this.ca = ca;
        this.theField = field;
        this.env = env;
    
Methods Summary
voidcheck()
Examine the field to decide what actions are required

        //@olsen: improved control flow
        //@olsen: dropped code computing persistence information;
        //        used JDO meta data instead

        String sig = theField.signature().asString();
        fieldTypeInfo = FieldTypeInfo.determineFieldType(sig, env);

        final String className = ca.className();
        final String userClass = ca.userClassName();
        final String fieldName = theField.name().asString();
        final String fullFieldName = userFieldName();

        //@olsen: added shortcut
        final JDOMetaData jdoMetaData = env.getJDOMetaData();

        //@olsen: use JDO meta data to decide whether a field is persistent
        //@olsen: subst: fieldShouldBeTransient -> !fieldShouldBePersistent
        final boolean fieldShouldBePersistent
            = jdoMetaData.isPersistentField(className, fieldName);
        //@olsen: added println() for debugging
        if (false) {
            System.out.println("FieldAction.check(): field "//NOI18N
                               + className + "/" + fieldName//NOI18N
                               + " should be persistent = "//NOI18N
                               + fieldShouldBePersistent);
        }

        //@olsen: initialized property from JDO meta data
        fieldIsPrimaryKey
            = jdoMetaData.isPrimaryKeyField(className, fieldName);
        //@olsen: added println() for debugging
        if (false) {
            System.out.println("FieldAction.check(): field "//NOI18N
                               + className + "/" + fieldName//NOI18N
                               + " is primary key = "//NOI18N
                               + fieldIsPrimaryKey);
        }

        //@olsen: initialized property from JDO meta data
        fieldIsMutableSCO
            = jdoMetaData.isMutableSecondClassObjectType(typeName());
        //@olsen: added println() for debugging
        if (false) {
            System.out.println("FieldAction.check(): field "//NOI18N
                               + className + "/" + fieldName//NOI18N
                               + " is mutable SCO = "//NOI18N
                               + fieldIsMutableSCO);
        }

        nFieldArrayDims = 0;
        while (sig.charAt(nFieldArrayDims) == '[")
            nFieldArrayDims++;

        // If the base type is a class type, compute the class name
        if (sig.charAt(nFieldArrayDims) == 'L")
            fieldClassName = sig.substring(nFieldArrayDims+1, sig.length()-1);

        // check for transient field
        if (!fieldShouldBePersistent) {
            // done with transient field
            return;
        }

        //@olsen: dropped code ...

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

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

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

        fieldIsPersistent = true;
    
java.lang.StringcreateMethod()
Return the name of the static method on class Field which will create a Field of the appropriate type.

        return fieldTypeInfo.fieldCreateMethod;
    
java.lang.StringcreateMethodSig()
Return the type signature of the static method on class Field which will create a Field of the appropriate type.

        return fieldTypeInfo.fieldCreateMethodSig;
    
java.lang.StringfieldClassName()
For references fields, return the base type class name if a class or interface, else null.

        return fieldClassName;
    
java.lang.StringfieldName()
Return the name of the field

        return theField.name().asString();
    
java.lang.StringgetMethod()
Return the name of the static method on class GenericObject which will get the field value.

        return fieldTypeInfo.fieldGetMethod;
    
intgetMethodReturn()
Return the return type of the get method.

        return fieldTypeInfo.fieldGetReturnType;
    
java.lang.StringgetMethodSig()
Return the type signature of the static method on class GenericObject which will get the field value.

        return fieldTypeInfo.fieldGetMethodSig;
    
booleanisMutableSCO()
Is this persistent field's value is a second class object?

        return fieldIsMutableSCO;
    
booleanisPersistent()
Is this field one which is stored persistently? This can only be true for non-static, non-final fields.

        return fieldIsPersistent;
    
booleanisPrimaryKey()
Is this persistent field primary key?

        return fieldIsPrimaryKey;
    
booleanisSynthetic()
Is the field a synthetic field? This is a java 1.1'ism for nested classes

        return theField.attributes().findAttribute("Synthetic") != null;//NOI18N
    
intnDims()
For array fields, return the number of dimensions in the array type else 0.

        return nFieldArrayDims;
    
java.lang.StringsetMethod()
Return the name of the static method on class GenericObject which will set the field value.

        return fieldTypeInfo.fieldSetMethod;
    
intsetMethodArg()
Return the type of arg expected by the set method.

        return fieldTypeInfo.fieldSetArgType;
    
java.lang.StringsetMethodSig()
Return the type signature of the static method on class GenericObject which will set the field value.

        return fieldTypeInfo.fieldSetMethodSig;
    
java.lang.StringtypeDescriptor()
Get the VM type descriptor field string for the field type

        return theField.signature().asString();
    
java.lang.StringtypeName()
Get the VM type name field string for the field type This is the same as the type descriptor except when it is a non-array class - in this case, the leading 'L' and trailing ';' need to be removed.

        String typeDesc = typeDescriptor();
        if (typeDesc.charAt(0) == 'L")
            return typeDesc.substring(1, typeDesc.length() - 1);
        return typeDesc;
    
java.lang.StringuserFieldName()
Return a user consumable field name

        return ca.userClassName() + "." + theField.name().asString();//NOI18N
    
private java.lang.StringuserSig(java.lang.String vmSig)
Return a user consumable signature

        // Stub: just return vm sig for now
        return Descriptor.userFieldSig(vmSig);