[jboss-cvs] jboss-seam/src/main/org/jboss/seam/remoting/wrapper ...

Shane Bryzak Shane_Bryzak at symantec.com
Fri Feb 2 06:53:33 EST 2007


  User: sbryzak2
  Date: 07/02/02 06:53:33

  Modified:    src/main/org/jboss/seam/remoting/wrapper  BeanWrapper.java
  Log:
  JBSEAM-700
  
  Revision  Changes    Path
  1.14      +74 -30    jboss-seam/src/main/org/jboss/seam/remoting/wrapper/BeanWrapper.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: BeanWrapper.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/remoting/wrapper/BeanWrapper.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -b -r1.13 -r1.14
  --- BeanWrapper.java	17 Nov 2006 17:17:42 -0000	1.13
  +++ BeanWrapper.java	2 Feb 2007 11:53:33 -0000	1.14
  @@ -67,8 +67,30 @@
   
         Class cls = value.getClass();
   
  +      // We're going to try a combination of ways to set the property value here
  +      Method method = null;
         Field field = null;
   
  +      // First try to find the best matching method
  +      String setter = "set" + Character.toUpperCase(name.charAt(0)) + name.substring(1);
  +      
  +      ConversionScore score = ConversionScore.nomatch;
  +      for (Method m : cls.getMethods())
  +      {
  +         if (setter.equals(m.getName()) && m.getParameterTypes().length == 1)
  +         {
  +            ConversionScore s = w.conversionScore(m.getParameterTypes()[0]);
  +            if (s.getScore() > score.getScore())
  +            {
  +               method = m;
  +               score = s;
  +            }
  +         }
  +      }    
  +      
  +      // If we can't find a method, look for a matching field name
  +      if (method == null)
  +      {
         while (field == null && !cls.equals(Object.class))
         {
           try
  @@ -84,18 +106,39 @@
         }
   
         if (field == null)
  +         {
           throw new RuntimeException(String.format(
  -          "Error while unmarshalling - field [%s] not found in class [%s]",
  +             "Error while unmarshalling - property [%s] not found in class [%s]",
             name, value.getClass().getName()));
  +         }      
  +      }
   
  +      // Now convert the field value to the correct target type
         Object fieldValue = null;
         try {
  -        fieldValue = w.convert(field.getGenericType());
  +        fieldValue = w.convert(method != null ? method.getGenericParameterTypes()[0] : 
  +           field.getGenericType());
         }
         catch (ConversionException ex) {
           throw new RuntimeException("Could not convert value while unmarshaling", ex);
         }
   
  +      // If we have a setter method, invoke it
  +      if (method != null)
  +      {
  +         try
  +         {
  +            method.invoke(value, fieldValue);
  +         }
  +         catch (Exception e)
  +         {
  +            throw new RuntimeException(String.format(
  +                     "Could not invoke setter method [%s]", method.getName()));
  +         }
  +      }
  +      else
  +      {
  +         // Otherwise try to set the field value directly
         boolean accessible = field.isAccessible();
         try
         {
  @@ -113,6 +156,7 @@
         }
       }
     }
  +  }
   
     public Object convert(Type type)
         throws ConversionException
  
  
  



More information about the jboss-cvs-commits mailing list