FileDocCategorySizeDatePackage
InterfaceContainerPolicy.javaAPI DocGlassfish v2 API9994Tue May 22 16:54:40 BST 2007oracle.toplink.essentials.internal.queryframework

InterfaceContainerPolicy

public abstract class InterfaceContainerPolicy extends ContainerPolicy

Purpose: The abstract class for ContainerPolicy's whose container class implements a container interface.

see
CollectionContainerPolicy
see
MapContainerPolicy

Fields Summary
protected Class
containerClass
The concrete container class.
protected String
containerClassName
protected transient Method
cloneMethod
The method which will return a clone of an instance of the containerClass.
Constructors Summary
public InterfaceContainerPolicy()
INTERNAL: Construct a new policy.

        super();
    
public InterfaceContainerPolicy(Class containerClass)
INTERNAL: Construct a new policy for the specified class.

        setContainerClass(containerClass);
    
public InterfaceContainerPolicy(String containerClassName)
INTERNAL: Construct a new policy for the specified class name.

        setContainerClassName(containerClassName);
    
Methods Summary
public java.lang.ObjectcloneFor(java.lang.Object container)
INTERNAL: Return a clone of the specified container.

        if (container == null) {
            return null;
        }

        try {
            return invokeCloneMethodOn(getCloneMethod(), container);
        } catch (IllegalArgumentException ex) {
            // container may be a superclass of the concrete container class
            // so we have to use the right clone method...
            return invokeCloneMethodOn(getCloneMethod(container.getClass()), container);
        }
    
public voidconvertClassNamesToClasses(java.lang.ClassLoader classLoader)
INTERNAL: Convert all the class-name-based settings in this ContainerPolicy to actual class-based settings. This method is used when converting a project that has been built with class names to a project with classes.

param
classLoader

        super.convertClassNamesToClasses(classLoader);
        if (containerClassName == null){
            return;
        }
        Class containerClass = null;
        try{
            if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
                try {
                    containerClass = (Class)AccessController.doPrivileged(new PrivilegedClassForName(containerClassName, true, classLoader));
                } catch (PrivilegedActionException exception) {
                    throw ValidationException.classNotFoundWhileConvertingClassNames(containerClassName, exception.getException());
                }
            } else {
                containerClass = oracle.toplink.essentials.internal.security.PrivilegedAccessHelper.getClassForName(containerClassName, true, classLoader);
            }
        } catch (ClassNotFoundException exc){
            throw ValidationException.classNotFoundWhileConvertingClassNames(containerClassName, exc);
        }
        setContainerClass(containerClass);
    
public java.lang.reflect.MethodgetCloneMethod()
INTERNAL: Return the 'clone()' Method for the container class. Lazy initialization is used, so we can serialize these things.

        if (cloneMethod == null) {
            setCloneMethod(getCloneMethod(getContainerClass()));
        }
        return cloneMethod;
    
protected java.lang.reflect.MethodgetCloneMethod(java.lang.Class javaClass)
INTERNAL: Return the 'clone()' Method for the specified class. Return null if the method does not exist anywhere in the hierarchy

        try {
            // This must not be set "accessible" - clone() must be public, and some JVM's do not allow access to JDK classes.
            if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
                try {
                    return (Method)AccessController.doPrivileged(new PrivilegedGetMethod(javaClass, "clone", (Class[])null, false));
                } catch (PrivilegedActionException exception) {
                    throw QueryException.methodDoesNotExistInContainerClass("clone", javaClass);
                }
            } else {
                return PrivilegedAccessHelper.getMethod(javaClass, "clone", (Class[])null, false);
            }
        } catch (NoSuchMethodException ex) {
            throw QueryException.methodDoesNotExistInContainerClass("clone", javaClass);
        }
    
public java.lang.ClassgetContainerClass()
INTERNAL: Returns the container class to be used with this policy.

        return containerClass;
    
public java.lang.StringgetContainerClassName()

        if ((containerClassName == null) && (containerClass != null)) {
            containerClassName = containerClass.getName();
        }
        return containerClassName;
    
public abstract java.lang.ClassgetInterfaceType()

public booleanhasNext(java.lang.Object iterator)
INTERNAL: Return whether the iterator has more objects,

        return ((Iterator)iterator).hasNext();
    
protected java.lang.ObjectinvokeCloneMethodOn(java.lang.reflect.Method method, java.lang.Object container)
INTERNAL: Invoke the specified clone method on the container, handling the necessary exceptions.

        try {
            if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
                try {
                    return AccessController.doPrivileged(new PrivilegedMethodInvoker(method, container, (Object[])null));
                } catch (PrivilegedActionException exception) {
                    Exception throwableException = exception.getException();
                    if (throwableException instanceof IllegalAccessException) {
                        throw QueryException.cannotAccessMethodOnObject(method, container);
                    } else {
                        throw QueryException.methodInvocationFailed(method, container, throwableException);
                    }
                }
            } else {
                return PrivilegedAccessHelper.invokeMethod(method, container, (Object[])null);
            }
        } catch (IllegalAccessException ex1) {
            throw QueryException.cannotAccessMethodOnObject(method, container);
        } catch (InvocationTargetException ex2) {
            throw QueryException.methodInvocationFailed(method, container, ex2);
        }
    
public booleanisValidContainerType(java.lang.Class containerType)
INTERNAL: Validate the container type.

        return oracle.toplink.essentials.internal.helper.Helper.classImplementsInterface(containerType, getInterfaceType());
    
protected java.lang.Objectnext(java.lang.Object iterator)
INTERNAL: Return the next object on the queue. Valid for some subclasses only.

        return ((Iterator)iterator).next();
    
public voidsetCloneMethod(java.lang.reflect.Method cloneMethod)
INTERNAL: Set the Method that will return a clone of an instance of the containerClass.

        this.cloneMethod = cloneMethod;
    
public voidsetContainerClass(java.lang.Class containerClass)
INTERNAL: Set the class to use as the container.

        this.containerClass = containerClass;
        initializeConstructor();
    
public voidsetContainerClassName(java.lang.String containerClassName)

        this.containerClassName = containerClassName;
    
protected java.lang.ObjecttoStringInfo()

        return this.getContainerClass();