FileDocCategorySizeDatePackage
ClassType.javaAPI DocGlassfish v2 API8051Fri May 04 22:35:08 BST 2007com.sun.jdo.spi.persistence.support.sqlstore.query.util.type

ClassType

public class ClassType extends Type
author
Michael Bouschen
version
0.1

Fields Summary
protected TypeTable
typetab
The associated type table.
protected Map
fieldInfos
protected com.sun.jdo.api.persistence.model.jdo.PersistenceClassElement
pce
Constructors Summary
public ClassType(String name, Class clazz, int enumType, TypeTable typetab)

        super(name, clazz, enumType);
        this.typetab = typetab;
        this.fieldInfos = new HashMap();
        // get JDO model element if available
        ClassLoader classLoader = clazz.getClassLoader();
        if (classLoader != null)
        {
            try
            {
                this.pce = typetab.model.getPersistenceClass(name, classLoader);
            }
            catch (IllegalArgumentException ex)
            {
                // IllegalArgumentException indicates class loader problem
                throw new JDOFatalUserException(ex.getMessage());
            }
        }
    
public ClassType(String name, Class clazz, TypeTable typetab)

        this(name, clazz, FieldTypeEnumeration.NOT_ENUMERATED, typetab);
    
Methods Summary
public FieldInfogetFieldInfo(java.lang.String fieldName)
Return FieldInfo object for the field with the specified name.

        synchronized(fieldInfos) {
            FieldInfo fieldInfo = (FieldInfo)fieldInfos.get(fieldName);
            if (fieldInfo == null)
            {
                // NOTE, no inheritance!
                final Class cl = clazz;
                Field field = (Field) AccessController.doPrivileged(new PrivilegedAction()
                    {
                        public Object run ()
                        {
                            try
                            {
                                return cl.getDeclaredField(fieldName);
                            }
                            catch (NoSuchFieldException ex)
                            {
                                return null; // do nothing, just return null
                            }
                        }
                    });

                if (field != null)
                {
                    fieldInfo = new FieldInfo(field, this);
                    fieldInfos.put(fieldName, fieldInfo);
                }
            }
            return fieldInfo;
        }
    
public FieldInfo[]getFieldInfos()
Returns an array of fieldInfos for all declared fields.

        // Initialize the fieldInfos map with the field declared for this class.
        // NOTE, this code does not work for inheritance!
        //Field[] fields = clazz.getDeclaredFields();

        final Class cl = clazz;

        Field[] fields =  (Field[]) AccessController.doPrivileged(new PrivilegedAction() {
                                public Object run () {
                                        return cl.getDeclaredFields();
                                }
                        });

        synchronized(fieldInfos) {
            for (int i = 0; i < fields.length; i++)
            {
                String fieldName = fields[i].getName();
                FieldInfo fieldInfo = (FieldInfo)fieldInfos.get(fieldName);
                if (fieldInfo == null)
                    fieldInfos.put(fieldName, new FieldInfo(fields[i], this));
            }
        }
        return (FieldInfo[])fieldInfos.values().toArray(new FieldInfo[0]);
    
public java.util.ListgetKeyFieldNames()
Return the list of key field names

        if (pce != null)
        {
            PersistenceFieldElement[] persistentFields = pce.getFields();
            List names = new ArrayList();
            for (int i = 0; i < persistentFields.length; i++)
            {
                if (persistentFields[i].isKey())
                    names.add(persistentFields[i].getName());
            }
            return names;
        }
        return null;
    
public booleanisCompatibleWith(Type type)
Checks the compatibility of this with the specified type. A ClassType object is compatible to errorType, to the type of null (NullType), to itself and to a super class (direct or indirect).

param
type type for compatibility check
return
true if this is compatible with type; false otherwise.
see
Type#isCompatibleWith(Type)

        boolean result = false;
        if (type instanceof ClassType)
        {
            result = ((ClassType)type).clazz.isAssignableFrom(clazz);
        }
        return result;
    
public booleanisOrderable()
Returns whether this represents a type with an defined order.

return
true if an order is defined for this; false otherwise.

        Type comparable = typetab.checkType("java.lang.Comparable"); //NOI18N
        return isCompatibleWith(comparable);
        
public booleanisPersistenceCapable()
Returns true if this is defined as persistence capable class.

return
true if this is a persistence capable class; false otherwise.

        return (pce != null);