Class SetPropertyInvocation

  • All Implemented Interfaces:
    Invokable

    public class SetPropertyInvocation
    extends Invocation
    implements Invokable

    A special Invocation implementation for setting properties.

    This Invocation implementation is initialized with a property name and value (the latter one is provided as a Dependency object. In its invoke() method it will set this property on the target object.

    This is more or less a convenience class because similar results could be achieved by using MethodInvocation and specifying the name of the set method corresponding to the property and the property value as parameter dependency. Setting the property is done using the InvocationHelper class. This ensures that required type conversions are done automatically.

    Once initialized, an instance is immutable. So it can easily be shared between multiple components and threads without having to care about synchronization issues.

    Version:
    $Id: SetPropertyInvocation.java 205 2012-01-29 18:29:57Z oheger $
    Author:
    Oliver Heger
    • Constructor Detail

      • SetPropertyInvocation

        public SetPropertyInvocation​(String propName,
                                     Dependency propValue)
        Creates a new instance of SetPropertyInvocation and initializes it.
        Parameters:
        propName - the name of the property to set (must not be null)
        propValue - a dependency that defines the property's value (must not be null)
        Throws:
        IllegalArgumentException - if the property name or its value is undefined
    • Method Detail

      • getPropertyName

        public String getPropertyName()
        Returns the name of the property that will be set.
        Returns:
        the name of the property
      • invoke

        public Object invoke​(DependencyProvider depProvider,
                             Object target)
        Performs the invocation and sets the property on the specified target object.
        Specified by:
        invoke in interface Invokable
        Parameters:
        depProvider - the dependency provider (must not be null)
        target - the target instance (must not be null)
        Returns:
        the result of the invocation, which is always null in this case
        Throws:
        InjectionException - if an error occurs
        IllegalArgumentException - if one of the parameters is null
      • invocationInfoToString

        protected void invocationInfoToString​(StringBuilder buf)
        Outputs further information about this invocation to the specified buffer. This implementation will print the name of the affected property.
        Overrides:
        invocationInfoToString in class Invocation
        Parameters:
        buf - the target buffer