FileDocCategorySizeDatePackage
CloneCopyPolicy.javaAPI DocGlassfish v2 API10601Tue May 22 16:54:18 BST 2007oracle.toplink.essentials.descriptors.copying

CloneCopyPolicy

public class CloneCopyPolicy extends AbstractCopyPolicy

Purpose: Creates a clone through a clone method.

Fields Summary
protected String
methodName
Allow for clone method to be specified.
protected String
workingCopyMethodName
protected transient Method
method
protected transient Method
workingCopyMethod
Constructors Summary
public CloneCopyPolicy()

        super();
    
Methods Summary
public java.lang.ObjectbuildClone(java.lang.Object domainObject, oracle.toplink.essentials.sessions.Session session)
Clone through calling the clone method.

        // Must allow for null clone method for 9.0.4 deployment XML.
        if (this.getMethodName() == null) {
            return getDescriptor().getObjectBuilder().buildNewInstance();
        }
        try {
            if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
                try {
                    return AccessController.doPrivileged(new PrivilegedMethodInvoker(this.getMethod(), domainObject, new Object[0]));
                } catch (PrivilegedActionException exception) {
                    Exception throwableException = exception.getException();
                    if (throwableException instanceof IllegalAccessException) {
                        throw DescriptorException.illegalAccessWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), throwableException);
                    } else {
                        throw DescriptorException.targetInvocationWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), throwableException);

                    }
                }
            } else {
                return PrivilegedAccessHelper.invokeMethod(this.getMethod(), domainObject, new Object[0]);
            }
        } catch (IllegalAccessException exception) {
            throw DescriptorException.illegalAccessWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), exception);
        } catch (InvocationTargetException exception) {
            throw DescriptorException.targetInvocationWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), exception);
        }
    
public java.lang.ObjectbuildWorkingCopyClone(java.lang.Object domainObject, oracle.toplink.essentials.sessions.Session session)
Clone through the workingCopyClone method, or if not specified the clone method.

        if (this.getWorkingCopyMethodName() == null) {
            //not implemented to perform special operations.
            return this.buildClone(domainObject, session);
        }

        try {
            if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
                try {
                    return AccessController.doPrivileged(new PrivilegedMethodInvoker(this.getWorkingCopyMethod(), domainObject, new Object[0]));
                } catch (PrivilegedActionException exception) {
                    Exception throwableException = exception.getException();
                    if (throwableException instanceof IllegalAccessException) {
                        throw DescriptorException.illegalAccessWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), throwableException);
                    } else {
                        throw DescriptorException.targetInvocationWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), throwableException);
                    }
                }
            } else {
                return PrivilegedAccessHelper.invokeMethod(this.getWorkingCopyMethod(), domainObject, new Object[0]);
            }
        
        } catch (IllegalAccessException exception) {
            throw DescriptorException.illegalAccessWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), exception);
        } catch (InvocationTargetException exception) {
            throw DescriptorException.targetInvocationWhileCloning(domainObject, this.getMethodName(), this.getDescriptor(), exception);
        }
    
public java.lang.ObjectbuildWorkingCopyCloneFromRow(oracle.toplink.essentials.sessions.Record row, oracle.toplink.essentials.queryframework.ObjectBuildingQuery query)
Create a new instance, unless a workingCopyClone method is specified, then build a new instance and clone it.

        // For now must preserve CMP code which builds heavy clones with a context.
        // Also preserve for clients who use the copy policy.
        ObjectBuilder builder = getDescriptor().getObjectBuilder();
        if (getWorkingCopyMethodName() != null) {
            Object original = builder.buildNewInstance();
            builder.buildAttributesIntoShallowObject(original, (AbstractRecord)row, query);
            return buildWorkingCopyClone(original, query.getSession());
        } else {
            return builder.buildNewInstance();
        }
    
public booleanbuildsNewInstance()
Return false as a shallow clone is returned, not a new instance.

        return getMethodName() == null;
    
protected java.lang.reflect.MethodgetMethod()
Return the clone method.

        return method;
    
public java.lang.StringgetMethodName()
Return the clone method name.

        return methodName;
    
protected java.lang.reflect.MethodgetWorkingCopyMethod()
Return the workingCopyClone method. This is used to clone within a unit of work.

        return workingCopyMethod;
    
public java.lang.StringgetWorkingCopyMethodName()
Return the workingCopyClone method name. This is used to clone within a unit of work.

        return workingCopyMethodName;
    
public voidinitialize(oracle.toplink.essentials.sessions.Session session)
Validate and build the methods.

        try {
            // Must allow for null clone method for 9.0.4 deployment XML.
            if (this.getMethodName() != null) {
                this.setMethod(Helper.getDeclaredMethod(this.getDescriptor().getJavaClass(), this.getMethodName(), new Class[0]));
            }
        } catch (NoSuchMethodException exception) {
            session.getIntegrityChecker().handleError(DescriptorException.noSuchMethodWhileInitializingCopyPolicy(this.getMethodName(), this.getDescriptor(), exception));
        } catch (SecurityException exception) {
            session.getIntegrityChecker().handleError(DescriptorException.securityWhileInitializingCopyPolicy(this.getMethodName(), this.getDescriptor(), exception));
        }
        if (this.getWorkingCopyMethodName() != null) {
            try {
                this.setWorkingCopyMethod(Helper.getDeclaredMethod(this.getDescriptor().getJavaClass(), this.getWorkingCopyMethodName(), new Class[0]));
            } catch (NoSuchMethodException exception) {
                session.getIntegrityChecker().handleError(DescriptorException.noSuchMethodWhileInitializingCopyPolicy(this.getMethodName(), this.getDescriptor(), exception));
            } catch (SecurityException exception) {
                session.getIntegrityChecker().handleError(DescriptorException.securityWhileInitializingCopyPolicy(this.getMethodName(), this.getDescriptor(), exception));
            }
        }
    
protected voidsetMethod(java.lang.reflect.Method method)
Set the clone method.

        this.method = method;
    
public voidsetMethodName(java.lang.String methodName)
Set the clone method name.

        this.methodName = methodName;
    
protected voidsetWorkingCopyMethod(java.lang.reflect.Method method)
Set the workingCopyClone method. This is used to clone within a unit of work.

        this.workingCopyMethod = method;
    
public voidsetWorkingCopyMethodName(java.lang.String methodName)
Set the workingCopyClone method name. This is used to clone within a unit of work.

        this.workingCopyMethodName = methodName;
    
public java.lang.StringtoString()

        return Helper.getShortClassName(this) + "(" + this.getMethodName() + ")";