/** * PUBLIC: * Indirection means that a IndirectContainer (wrapping a ValueHolder) will be put in-between the attribute and the real object. * This allows for an application specific class to be used which wraps the value holder. * The purpose of this is that the domain objects will not require to import the ValueHolderInterface class. * Refer also to transparent indirection for a transparent solution to indirection. */ public void useContainerIndirection(Class containerClass) { ContainerIndirectionPolicy policy = new ContainerIndirectionPolicy(); policy.setContainerClass(containerClass); setIndirectionPolicy(policy); }
/** * INTERNAL: This method can be used when an Indirection Object is required * to be built from a provided ValueHolderInterface object. This may be used * for custom value holder types. Certain policies like the * TransparentIndirectionPolicy may wrap the valueholder in another object. */ public Object buildIndirectObject(ValueHolderInterface valueHolder){ return buildContainer(valueHolder); }
/** * INTERNAL: * Verify that the value of the attribute within an instantiated object * is of the appropriate type for the indirection policy. * In this case, the attribute must be non-null and it must be a * ValueHolderInterface. */ public Object validateAttributeOfInstantiatedObject(Object attributeValue) { if (!(getContainerClass().isInstance(attributeValue))) { throw DescriptorException.valueHolderInstantiationMismatch(attributeValue, this.getMapping()); } return attributeValue; }
/** * Reset the wrapper used to store the value. */ public void reset(Object target) { getMapping().setAttributeValueInObject(target, buildContainer(new ValueHolder())); }
/** * INTERNAL: * Set the value of the appropriate attribute of target to attributeValue. * In this case, place the value inside the target's ValueHolder. */ public void setRealAttributeValueInObject(Object target, Object attributeValue) { IndirectContainer container = (IndirectContainer)this.getMapping().getAttributeValueFromObject(target); container.getValueHolder().setValue(attributeValue); this.getMapping().setAttributeValueInObject(target, container); }
/** * INTERNAL: * Return whether the type is appropriate for the indirection policy. * In this case, the type must either be assignable from IndirectContainer or * allow the conatinerClass to be assigned to it. */ protected boolean typeIsValid(Class attributeType) { return ClassConstants.IndirectContainer_Class.isAssignableFrom(attributeType) || attributeType.isAssignableFrom(getContainerClass()); }
protected void addTransformationMappingLines(NonreflectiveMethodDefinition method, String mappingName, TransformationMapping mapping) { if (!mapping.isWriteOnly()) { if (mapping.getAttributeMethodName() != null) { method.addLine(mappingName + ".setAttributeTransformation(\"" + mapping.getAttributeMethodName() + "\");"); } else { method.addLine(mappingName + ".setAttributeTransformer(new " + mapping.getAttributeTransformerClassName() + "());"); } } Iterator fieldTransformations = mapping.getFieldTransformations().iterator(); while (fieldTransformations.hasNext()) { FieldTransformation trans = (FieldTransformation)fieldTransformations.next(); String fieldName = trans.getFieldName(); if (trans instanceof MethodBasedFieldTransformation) { String methodName = ((MethodBasedFieldTransformation)trans).getMethodName(); method.addLine(mappingName + ".addFieldTransformation(\"" + fieldName + "\", \"" + methodName + "\");"); } else { String transformerClass = ((TransformerBasedFieldTransformation)trans).getTransformerClassName(); method.addLine(mappingName + ".addFieldTransformer(\"" + fieldName + "\", new " + transformerClass + "());"); } } IndirectionPolicy policy = mapping.getIndirectionPolicy(); if (policy instanceof ContainerIndirectionPolicy) { String containerClassName = ((ContainerIndirectionPolicy)policy).getContainerClassName(); method.addLine(mappingName + ".useContainerIndirection(" + containerClassName + ".class);"); } else if (policy instanceof BasicIndirectionPolicy) { method.addLine(mappingName + ".useBasicIndirection();"); } method.addLine(mappingName + ".setIsMutable(" + mapping.isMutable() + ");"); }
/** * INTERNAL: * Return the original indirection object for a unit of work indirection object. */ public Object getOriginalIndirectionObjectForMerge(Object unitOfWorkIndirectionObject, AbstractSession session) { IndirectContainer container = (IndirectContainer) getOriginalIndirectionObject(unitOfWorkIndirectionObject, session); DatabaseValueHolder holder = (DatabaseValueHolder)container.getValueHolder(); if (holder != null && holder.getSession()!= null){ holder.setSession(session); } return container; }
/** * INTERNAL: * Return the reference row for the reference object. * This allows the new row to be built without instantiating * the reference object. * Return null if the object has already been instantiated. */ public AbstractRecord extractReferenceRow(Object referenceObject) { if (this.objectIsInstantiated(referenceObject)) { return null; } else { return ((DatabaseValueHolder)((IndirectContainer)referenceObject).getValueHolder()).getRow(); } }
/** * Build a conatiner with the initialized constructor. * @see initializeContainer */ protected IndirectContainer buildContainer(ValueHolderInterface valueHolder) { try { IndirectContainer container = null; if (getContainerConstructor().getParameterTypes().length == 0) { if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ container = (IndirectContainer)AccessController.doPrivileged(new PrivilegedInvokeConstructor(getContainerConstructor(), new Object[0])); }else{ container = (IndirectContainer)PrivilegedAccessHelper.invokeConstructor(getContainerConstructor(), new Object[0]); } container.setValueHolder(valueHolder); } else { if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ container = (IndirectContainer)AccessController.doPrivileged(new PrivilegedInvokeConstructor(getContainerConstructor(), new Object[] { valueHolder })); }else{ container = (IndirectContainer)PrivilegedAccessHelper.invokeConstructor(getContainerConstructor(), new Object[] { valueHolder }); } } return container; } catch (Exception exception) { throw DescriptorException.invalidIndirectionPolicyOperation(this, "buildContainer constructor (" + getContainerConstructor() + ") Failed: " + exception); } }
/** * Reset the wrapper used to store the value. */ public void reset(Object target) { getMapping().setAttributeValueInObject(target, buildContainer(new ValueHolder())); }
/** * INTERNAL: * Set the value of the appropriate attribute of target to attributeValue. * In this case, place the value inside the target's ValueHolder. */ public void setRealAttributeValueInObject(Object target, Object attributeValue) { IndirectContainer container = (IndirectContainer)this.getMapping().getAttributeValueFromObject(target); container.getValueHolder().setValue(attributeValue); this.getMapping().setAttributeValueInObject(target, container); }
/** * INTERNAL: * Return whether the type is appropriate for the indirection policy. * In this case, the type must either be assignable from IndirectContainer or * allow the conatinerClass to be assigned to it. */ protected boolean typeIsValid(Class attributeType) { return ClassConstants.IndirectContainer_Class.isAssignableFrom(attributeType) || attributeType.isAssignableFrom(getContainerClass()); }
protected void addTransformationMappingLines(NonreflectiveMethodDefinition method, String mappingName, TransformationMapping mapping) { if (!mapping.isWriteOnly()) { if (mapping.getAttributeMethodName() != null) { method.addLine(mappingName + ".setAttributeTransformation(\"" + mapping.getAttributeMethodName() + "\");"); } else { method.addLine(mappingName + ".setAttributeTransformer(new " + mapping.getAttributeTransformerClassName() + "());"); } } Iterator fieldTransformations = mapping.getFieldTransformations().iterator(); while (fieldTransformations.hasNext()) { FieldTransformation trans = (FieldTransformation)fieldTransformations.next(); String fieldName = trans.getFieldName(); if (trans instanceof MethodBasedFieldTransformation) { String methodName = ((MethodBasedFieldTransformation)trans).getMethodName(); method.addLine(mappingName + ".addFieldTransformation(\"" + fieldName + "\", \"" + methodName + "\");"); } else { String transformerClass = ((TransformerBasedFieldTransformation)trans).getTransformerClassName(); method.addLine(mappingName + ".addFieldTransformer(\"" + fieldName + "\", new " + transformerClass + "());"); } } IndirectionPolicy policy = mapping.getIndirectionPolicy(); if (policy instanceof ContainerIndirectionPolicy) { String containerClassName = ((ContainerIndirectionPolicy)policy).getContainerClassName(); method.addLine(mappingName + ".useContainerIndirection(" + containerClassName + ".class);"); } else if (policy instanceof BasicIndirectionPolicy) { method.addLine(mappingName + ".useBasicIndirection();"); } method.addLine(mappingName + ".setIsMutable(" + mapping.isMutable() + ");"); }
/** * INTERNAL: * Return the original indirection object for a unit of work indirection object. */ public Object getOriginalIndirectionObjectForMerge(Object unitOfWorkIndirectionObject, AbstractSession session) { IndirectContainer container = (IndirectContainer) getOriginalIndirectionObject(unitOfWorkIndirectionObject, session); DatabaseValueHolder holder = (DatabaseValueHolder)container.getValueHolder(); if (holder != null && holder.getSession()!= null){ holder.setSession(session); } return container; }
/** * INTERNAL: * Return the reference row for the reference object. * This allows the new row to be built without instantiating * the reference object. * Return null if the object has already been instantiated. */ public AbstractRecord extractReferenceRow(Object referenceObject) { if (this.objectIsInstantiated(referenceObject)) { return null; } else { return ((DatabaseValueHolder)((IndirectContainer)referenceObject).getValueHolder()).getRow(); } }
/** * Build a conatiner with the initialized constructor. * @see initializeContainer */ protected IndirectContainer buildContainer(ValueHolderInterface valueHolder) { try { IndirectContainer container = null; if (getContainerConstructor().getParameterTypes().length == 0) { if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ container = (IndirectContainer)AccessController.doPrivileged(new PrivilegedInvokeConstructor(getContainerConstructor(), new Object[0])); }else{ container = (IndirectContainer)PrivilegedAccessHelper.invokeConstructor(getContainerConstructor(), new Object[0]); } container.setValueHolder(valueHolder); } else { if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ container = (IndirectContainer)AccessController.doPrivileged(new PrivilegedInvokeConstructor(getContainerConstructor(), new Object[] { valueHolder })); }else{ container = (IndirectContainer)PrivilegedAccessHelper.invokeConstructor(getContainerConstructor(), new Object[] { valueHolder }); } } return container; } catch (Exception exception) { throw DescriptorException.invalidIndirectionPolicyOperation(this, "buildContainer constructor (" + getContainerConstructor() + ") Failed: " + exception); } }
/** * INTERNAL: This method can be used when an Indirection Object is required * to be built from a provided ValueHolderInterface object. This may be used * for custom value holder types. Certain policies like the * TransparentIndirectionPolicy may wrap the valueholder in another object. */ public Object buildIndirectObject(ValueHolderInterface valueHolder){ return buildContainer(valueHolder); }
/** * PUBLIC: * Indirection means that a IndirectContainer (wrapping a ValueHolder) will be put in-between the attribute and the real object. * This allows for an application specific class to be used which wraps the value holder. * The purpose of this is that the domain objects will not require to import the ValueHolderInterface class. * Refer also to transparent indirection for a transparent solution to indirection. */ public void useContainerIndirection(Class containerClass) { ContainerIndirectionPolicy policy = new ContainerIndirectionPolicy(); policy.setContainerClass(containerClass); setIndirectionPolicy(policy); }
/** * Reset the wrapper used to store the value. */ public void reset(Object target) { getMapping().setAttributeValueInObject(target, buildContainer(new ValueHolder())); }