geronimo-xbean-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dain Sundstrom <>
Subject [reflect] Named constructor args
Date Thu, 28 Feb 2008 19:40:14 GMT
I have finally finished adding support for named constructor (and  
static factory) args to xbean-reflect.  When enabled the ObjectRecipe  
code while select the constructor with the longest parameter list that  
can be supplied with the available properties in the recipe.  For  
example, if you have the following recipe and target class:

     ObjectRecipe objectRecipe = new ObjectRecipe(PersonFactory.class,  
     objectRecipe.setProperty("name", "Joe");
     objectRecipe.setProperty("age", "21");
     objectRecipe.setProperty("homePage", "");

     public class Person {
         public Person() { ... }
         public Person(String name, int age, URL homePage) { ... }
         public void setName(String name) { ... }
         public void setAge(int age) { ... }
         public void setHomePage(URL homePage) { ... }

With this feature enabled, ObjectRecipe will call the 3 arg  
constructor, and without named parameters enabled, it will call the  
default constructor and the three setters.  To enable this feature  
simply call objectRecipe.allow(Option.NAMED_PARAMETERS);

As for the implementation, we load the parameter names by first  
checking for a java.beans.ConstructorProperties or a  
org.apache.xbean.recipe.ParameterNames annotation.  If one of the  
annotations was not present, we use ASM to extract the parameter names  
from the debug symbol table in the byte code.


View raw message