FileDocCategorySizeDatePackage
WeavedObjectBasicIndirectionPolicy.javaAPI DocGlassfish v2 API8135Tue May 22 16:54:36 BST 2007oracle.toplink.essentials.internal.indirection

WeavedObjectBasicIndirectionPolicy

public class WeavedObjectBasicIndirectionPolicy extends BasicIndirectionPolicy
INTERNAL: A WeavedObjectBasicIndirectionPolicy is used by OneToOne mappings that are LAZY through weaving and which use Property(method) access. It extends BasicIndirection by providing the capability of calling the set method that was initially mapped in addition to the set method for the weaved valueholder in order to coordinate the value of the underlying property with the value stored in the valueholder
author
Tom Ware

Fields Summary
protected String
setMethodName
protected Method
setMethod
Constructors Summary
public WeavedObjectBasicIndirectionPolicy(String setMethodName)

 // lazily initialized set method based on the set method name
    
       
        super();
        this.setMethodName = setMethodName;
    
Methods Summary
public java.lang.ObjectgetRealAttributeValueFromObject(java.lang.Object object, java.lang.Object attribute)
INTERNAL: Return the "real" attribute value, as opposed to any wrapper. This will trigger the wrapper to instantiate the value. In a weaved policy, this will also call the initial setter method to coordinate the values of the valueholder with the underlying data

        Object value = super.getRealAttributeValueFromObject(object, attribute);
        // Provide the indirection policy with a callback that allows it to do any updates it needs as the result of getting the value
        updateValueInObject(object, value, attribute);
        return value;
    
protected java.lang.reflect.MethodgetSetMethod()
This method will lazily initialize the set method Lazy initialization occurs to that we are not required to have a handle on the actual class that we are using until runtime. This helps to satisfy the weaving requirement that demands that we avoid loading domain classes into the main class loader until after weaving occurs.

return

        if (setMethod == null){
            ForeignReferenceMapping sourceMapping = (ForeignReferenceMapping)mapping;
            // The parameter type for the set method must always be the return type of the get method.
            Class[] parameterTypes = new Class[1];
            parameterTypes[0] = sourceMapping.getReferenceClass();
            try {
                setMethod = Helper.getDeclaredMethod(sourceMapping.getDescriptor().getJavaClass(), setMethodName, parameterTypes);
            } catch (NoSuchMethodException e){
                throw DescriptorException.errorAccessingSetMethodOfEntity(sourceMapping.getDescriptor().getJavaClass(), setMethodName ,sourceMapping.getDescriptor(), e);
            }
        }
        return setMethod;
    
public voidsetRealAttributeValueInObject(java.lang.Object target, java.lang.Object attributeValue)
INTERNAL: Set the value of the appropriate attribute of target to attributeValue. In this case, place the value inside the target's ValueHolder.

        Object[] parameters = new Object[1];
        parameters[0] = attributeValue;
        try {
            if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
                try {
                    AccessController.doPrivileged(new PrivilegedMethodInvoker(getSetMethod(), target, parameters));
                } catch (PrivilegedActionException exception) {
                    Exception throwableException = exception.getException();
                    if (throwableException instanceof IllegalAccessException) {
                        throw DescriptorException.illegalAccessWhileSettingValueThruMethodAccessor(setMethod.getName(), attributeValue, throwableException);
                    } else {
                        throw DescriptorException.targetInvocationWhileSettingValueThruMethodAccessor(setMethod.getName(), attributeValue, throwableException);
                     }
                }
            } else {
                PrivilegedAccessHelper.invokeMethod(getSetMethod(), target, parameters);
            }
        } catch (IllegalAccessException exception) {
            throw DescriptorException.illegalAccessWhileSettingValueThruMethodAccessor(setMethod.getName(), attributeValue, exception);
        } catch (IllegalArgumentException exception) {
              throw DescriptorException.illegalArgumentWhileSettingValueThruMethodAccessor(setMethod.getName(), attributeValue, exception);
        } catch (InvocationTargetException exception) {
            throw DescriptorException.targetInvocationWhileSettingValueThruMethodAccessor(setMethod.getName(), attributeValue, exception);
        }
    
public voidupdateValueInObject(java.lang.Object object, java.lang.Object value, java.lang.Object attributeValue)
Coordinate the valueholder for this mapping with the underlying property by calling the initial setter method

        setRealAttributeValueInObject(object, value);
        ((WeavedAttributeValueHolderInterface)attributeValue).setIsCoordinatedWithProperty(true);