FileDocCategorySizeDatePackage
MethodBeanProperty.javaAPI DocJBoss 4.2.13512Fri Jul 13 20:53:46 BST 2007org.jboss.injection.lang.reflect

MethodBeanProperty

public class MethodBeanProperty extends AbstractAccessibleObjectBeanProperty
Morphs a setter method into a bean property.
author
Carlo de Wolf
version
$Revision: $

Fields Summary
private final Logger
log
private String
name
Constructors Summary
public MethodBeanProperty(Method method)

param
method

 // lazily initialized
   
         
     
   
      super(method);
      
      assert method.getReturnType() == Void.TYPE;
      assert method.getParameterTypes().length == 1;
      assert method.getName().startsWith("set");
   
Methods Summary
public java.lang.ClassgetDeclaringClass()

      return getMethod().getDeclaringClass();
   
protected java.lang.reflect.MethodgetMethod()

      return getAccessibleObject();
   
public java.lang.StringgetName()

      if(name == null)
      {
         String name = getMethod().getName().substring(3);
         if (name.length() > 1)
         {
            name = name.substring(0, 1).toLowerCase() + name.substring(1);
         }
         else
         {
            name = name.toLowerCase();
         }
         this.name = name; // atomair, no synch
      }
      return name;
   
public java.lang.ClassgetType()

      return getMethod().getParameterTypes()[0];
   
public voidset(java.lang.Object instance, java.lang.Object value)

      Method method = getMethod();
      Object args[] = { value };
      try
      {
         method.invoke(instance, args);
      }
      catch (IllegalAccessException e)
      {
         log.fatal("illegal access on method " + method, e);
         throw new RuntimeException(e);
      }
      catch (IllegalArgumentException e)
      {
         String msg = "failed to set value " + value + " with setter " + method;
         log.error(msg, e);
         throw new IllegalArgumentException(msg);
      }
      catch (InvocationTargetException e)
      {
         Throwable cause = e.getCause();
         if(cause instanceof Error)
            throw (Error) cause;
         if(cause instanceof RuntimeException)
            throw (RuntimeException) cause;
         throw new RuntimeException(cause);
      }