FileDocCategorySizeDatePackage
MethodClassExtractor.javaAPI DocGlassfish v2 API9372Tue May 22 16:54:16 BST 2007oracle.toplink.essentials.descriptors

MethodClassExtractor

public class MethodClassExtractor extends ClassExtractor

Purpose: Used to allow complex inheritance support. Typically class indicators are used to define inheritance in the database, however in complex cases the class type may be determined through another mechanism. The method calls a static method on the descriptor class to determine the class to use for the database row.

see
oracle.toplink.essentials.descriptors.InheritancePolicy#setClassExtractor(ClassExtrator)

Fields Summary
protected transient ClassDescriptor
descriptor
protected String
classExtractionMethodName
protected transient Method
classExtractionMethod
Constructors Summary
Methods Summary
public java.lang.ClassextractClassFromRow(oracle.toplink.essentials.sessions.Record row, oracle.toplink.essentials.sessions.Session session)
INTERNAL Extract/compute the class from the database row and return the class. Map is used as the public interface to database row, the key is the field name, the value is the database value.

        Class classForRow;

        try {
            Object[] arguments = new Object[1];
            arguments[0] = row;
            if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
                try {
                    classForRow = (Class)AccessController.doPrivileged(new PrivilegedMethodInvoker(getClassExtractionMethod(), null, arguments));
                } catch (PrivilegedActionException exception) {
                    Exception throwableException = exception.getException();
                    if (throwableException instanceof IllegalAccessException) {
                        throw DescriptorException.illegalAccessWhileInvokingRowExtractionMethod((AbstractRecord)row, getClassExtractionMethod(), getDescriptor(), throwableException);
                    } else {
                        throw DescriptorException.targetInvocationWhileInvokingRowExtractionMethod((AbstractRecord)row, getClassExtractionMethod(), getDescriptor(), throwableException);
                    }
                }
            } else {
                classForRow = (Class)PrivilegedAccessHelper.invokeMethod(getClassExtractionMethod(), null, arguments);
            }
        } catch (IllegalAccessException exception) {
            throw DescriptorException.illegalAccessWhileInvokingRowExtractionMethod((AbstractRecord)row, getClassExtractionMethod(), getDescriptor(), exception);
        } catch (InvocationTargetException exception) {
            throw DescriptorException.targetInvocationWhileInvokingRowExtractionMethod((AbstractRecord)row, getClassExtractionMethod(), getDescriptor(), exception);
        }

        return classForRow;
    
public java.lang.reflect.MethodgetClassExtractionMethod()
INTERNAL: Return all the classExtractionMethod

        return classExtractionMethod;
    
public java.lang.StringgetClassExtractionMethodName()
PUBLIC: A class extraction method can be registered with the descriptor to override the default inheritance mechanism. This allows for the class indicator field to not be used, and a user defined one instead. The method registered must be a static method on the class that the descriptor is for, the method must take DatabaseRow as argument, and must return the class to use for that row. This method will be used to decide which class to instantiate when reading from the database. It is the application's responsiblity to populate any typing information in the database required to determine the class from the row. If this method is used then the class indicator field and mapping cannot be used, also the descriptor's withAllSubclasses and onlyInstances expressions must also be setup correctly.

        return classExtractionMethodName;
    
protected oracle.toplink.essentials.descriptors.ClassDescriptorgetDescriptor()
INTERNAL: Return the descriptor.

        return descriptor;
    
public voidinitialize(oracle.toplink.essentials.descriptors.ClassDescriptor descriptor, oracle.toplink.essentials.sessions.Session session)
INTERNAL: Setup the default classExtractionMethod, or if one was specified by the user make sure it is valid.

        setDescriptor(descriptor);
        Class[] declarationParameters = new Class[1];
        declarationParameters[0] = ClassConstants.DatabaseRow_Class;

        try {
            setClassExtractionMethod(Helper.getDeclaredMethod(descriptor.getJavaClass(), getClassExtractionMethodName(), declarationParameters));
        } catch (NoSuchMethodException ignore) {
            declarationParameters[0] = ClassConstants.Record_Class;
            try {
                setClassExtractionMethod(Helper.getDeclaredMethod(descriptor.getJavaClass(), getClassExtractionMethodName(), declarationParameters));
            } catch (NoSuchMethodException exception) {
                throw DescriptorException.noSuchMethodWhileInitializingClassExtractionMethod(getClassExtractionMethodName(), descriptor, exception);
            }
        } catch (SecurityException exception) {
            throw DescriptorException.securityWhileInitializingClassExtractionMethod(getClassExtractionMethodName(), descriptor, exception);
        }

        // CR#2818667 Ensure the method is static.
        if (!Modifier.isStatic(getClassExtractionMethod().getModifiers())) {
            throw DescriptorException.classExtractionMethodMustBeStatic(getClassExtractionMethodName(), descriptor);
        }
    
protected voidsetClassExtractionMethod(java.lang.reflect.Method classExtractionMethod)
INTERNAL:

        this.classExtractionMethod = classExtractionMethod;
    
public voidsetClassExtractionMethodName(java.lang.String staticClassClassExtractionMethod)
PUBLIC: A class extraction method can be registered with the descriptor to override the default inheritance mechanism. This allows for the class indicator field to not be used, and a user defined one instead. The method registered must be a static method on the class that the descriptor is for, the method must take DatabaseRow as argument, and must return the class to use for that row. This method will be used to decide which class to instantiate when reading from the database. It is the application's responsiblity to populate any typing information in the database required to determine the class from the row. If this method is used then the class indicator field and mapping cannot be used, also the descriptor's withAllSubclasses and onlyInstances expressions must also be setup correctly.

        this.classExtractionMethodName = staticClassClassExtractionMethod;
    
protected voidsetDescriptor(oracle.toplink.essentials.descriptors.ClassDescriptor descriptor)
INTERNAL: Set the descriptor.

        this.descriptor = descriptor;