Package org.strecks.injection.internal

Source Code of org.strecks.injection.internal.InjectionSetter

/*
* Copyright 2005-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package org.strecks.injection.internal;

import java.lang.reflect.Method;

import org.strecks.exceptions.ApplicationRuntimeException;
import org.strecks.util.Assert;
import org.strecks.util.PropertyValueSetter;

/**
* This class has the responsibility of performing the actual binding on the target property using
* the Object returned from the invocation of <code>InjectionHandler.getValue(actionContext)</code>
* @author Phil Zoio
*/
public class InjectionSetter
{

  private String propertyName;

  private String methodName;

  private Method setterMethod;

  private Class type;

  public InjectionSetter(Class hostClass, String methodName, String propertyName, Class type)
  {

    super();

    Assert.notNull(hostClass);
    Assert.notNull(methodName);
    Assert.notNull(propertyName);
    Assert.notNull(type);

    this.methodName = methodName;
    this.propertyName = propertyName;
    this.type = type;

    // create setter method
    try
    {
      setterMethod = hostClass.getMethod(methodName, new Class[]
      {
        type
      });
    }
    catch (Exception e)
    {
      // quite a few exceptions we can have here
      throw new ApplicationRuntimeException("Application error: could not get method " + methodName
          + " from host class " + hostClass.getName());
    }

  }

  public void setInput(Object targetBean, Object converted)
  {
    PropertyValueSetter.setPropertyValue(targetBean, setterMethod, type, converted);
  }

  public String getMethodName()
  {
    return methodName;
  }

  public String getPropertyName()
  {
    return propertyName;
  }

  public Class getType()
  {
    return type;
  }

}
TOP

Related Classes of org.strecks.injection.internal.InjectionSetter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.