FileDocCategorySizeDatePackage
TypeHelperImpl.javaAPI DocGlassfish v2 API9632Tue May 22 16:54:40 BST 2007oracle.toplink.essentials.internal.parsing

TypeHelperImpl

public class TypeHelperImpl extends BasicTypeHelperImpl implements TypeHelper
INTERNAL

Purpose: Implement type helper methods specified by TypeHelper. This implementation uses Class instances to represent a type.

Fields Summary
private final AbstractSession
session
The session.
private final ClassLoader
classLoader
The class loader used to resolve type names.
Constructors Summary
public TypeHelperImpl(AbstractSession session, ClassLoader classLoader)

        this.session = session;
        this.classLoader = classLoader;
    
Methods Summary
private oracle.toplink.essentials.descriptors.ClassDescriptorgetDescriptor(java.lang.Object type)
Returns the class descriptor if the specified non-null type is a class object.

        ClassDescriptor desc = null;
        if (type instanceof Class) {
            desc = session.getDescriptor((Class)type);
        } else if (type instanceof ClassDescriptor) {
            desc = (ClassDescriptor)type;
        }
        return desc;
    
private java.lang.ObjectgetType(oracle.toplink.essentials.mappings.DatabaseMapping mapping)

        if (mapping == null) {
            return null;
        }
        Object type = null;
        if (mapping.isForeignReferenceMapping()) {
            ClassDescriptor descriptor = mapping.getReferenceDescriptor();
            type = descriptor == null ? null : descriptor.getJavaClass();
        } else if (mapping.isAggregateMapping()) {
            // Return the ClassDescriptor as the type representation in case
            // of an embeeded. This makese sure that any property or field
            // access of the embedded uses the correct mapping information and
            // not the shell of the descriptors as stored by the session.
            type = ((AggregateMapping)mapping).getReferenceDescriptor();
        } else {
            type = mapping.getAttributeClassification();
        }
        return type;
    
public booleanisCollectionValuedRelationship(java.lang.Object ownerClass, java.lang.String attribute)
Returns true if the specified attribute denotes a collection valued relationship attribute.

        DatabaseMapping mapping = 
            resolveAttributeMapping(ownerClass, attribute);
        return (mapping != null) && 
            (mapping.isOneToManyMapping() || mapping.isManyToManyMapping());
    
public booleanisEmbeddable(java.lang.Object type)
Returns true if the specified type denotes an embedded class.

        ClassDescriptor desc = getDescriptor(type);
        return (desc != null) && desc.isAggregateDescriptor();
    
public booleanisEmbeddedAttribute(java.lang.Object ownerClass, java.lang.String attribute)
Returns true if the specified type denotes an embedded attribute.

        DatabaseMapping mapping = 
            resolveAttributeMapping(ownerClass, attribute);
        return (mapping != null) && mapping.isAggregateMapping();
    
public booleanisEntityClass(java.lang.Object type)
Returns true if the specified type denotes an entity class.

        ClassDescriptor desc = getDescriptor(type);
        return (desc != null) && !desc.isAggregateDescriptor();
    
public booleanisRelationship(java.lang.Object ownerClass, java.lang.String attribute)
Returns true if the specified attribute denotes a single valued or collection valued relationship attribute.

        DatabaseMapping mapping = 
            resolveAttributeMapping(ownerClass, attribute);
        return (mapping != null) && 
               (mapping.isObjectReferenceMapping() || 
                mapping.isOneToManyMapping() || 
                mapping.isManyToManyMapping());
    
public booleanisSimpleStateAttribute(java.lang.Object ownerClass, java.lang.String attribute)
Returns true if the specified type denotes a simple state attribute.

        DatabaseMapping mapping = 
            resolveAttributeMapping(ownerClass, attribute);
        return (mapping != null) && mapping.isDirectToFieldMapping();
    
public booleanisSingleValuedRelationship(java.lang.Object ownerClass, java.lang.String attribute)
Returns true if the specified attribute denotes a single valued relationship attribute.

        DatabaseMapping mapping = 
            resolveAttributeMapping(ownerClass, attribute);
        return (mapping != null) && mapping.isObjectReferenceMapping();
    
public java.lang.ObjectresolveAttribute(java.lang.Object ownerClass, java.lang.String attribute)
Returns the type of the attribute with the specified name in the specified owner class.

        DatabaseMapping mapping = 
            resolveAttributeMapping(ownerClass, attribute);
        return getType(mapping);
    
private oracle.toplink.essentials.mappings.DatabaseMappingresolveAttributeMapping(java.lang.Object ownerClass, java.lang.String attr)
Returns the mapping for the specified attribute of the psecified class. The method returns null if the class is not known or if the class does not have an attribute of the specified name.

        ClassDescriptor desc = getDescriptor(ownerClass);
        return (desc == null) ? null : desc.getMappingForAttributeName(attr);
    
public java.lang.ObjectresolveEnumConstant(java.lang.Object type, java.lang.String constant)
Returns the enum constant if the specified type denotes an enum type and the specified constant denotes a constant of the enum type.

        Class clazz = getJavaClass(type);
        Object[] constants = clazz.getEnumConstants();
        if (constants != null) {
            for (int i = 0; i < constants.length; i++) {
                if (constant.equals(constants[i].toString())) {
                    return constants[i];
                }
            }
        }
        return null;
    
public java.lang.ObjectresolveSchema(java.lang.String schemaName)
Returns the type of the class corresponding to the spcified abstract schema type.

        ClassDescriptor descriptor = session.getDescriptorForAlias(schemaName);
        return (descriptor != null) ? descriptor.getJavaClass() : null;
    
public java.lang.ObjectresolveTypeName(java.lang.String typeName)
Returns a type representation for the specified type name or null if there is no such type.

        try {
            if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
                try {
                    return (Class)AccessController.doPrivileged(
                        new PrivilegedClassForName(typeName, true, classLoader));
                } catch (PrivilegedActionException exception) {
                    return null;
                }
            } else {
                return PrivilegedAccessHelper.getClassForName(typeName, true, classLoader);
            }
        } catch (ClassNotFoundException ex) {
            return null;
        }