ClassTypepublic class ClassType extends Type
Fields Summary |
---|
protected TypeTable | typetabThe 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 FieldInfo | getFieldInfo(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.List | getKeyFieldNames()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 boolean | isCompatibleWith(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).
boolean result = false;
if (type instanceof ClassType)
{
result = ((ClassType)type).clazz.isAssignableFrom(clazz);
}
return result;
| public boolean | isOrderable()Returns whether this represents a type with an
defined order.
Type comparable = typetab.checkType("java.lang.Comparable"); //NOI18N
return isCompatibleWith(comparable);
| public boolean | isPersistenceCapable()Returns true if this is defined as persistence capable class.
return (pce != null);
|
|