You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xbean-dev@geronimo.apache.org by Dain Sundstrom <da...@iq80.com> on 2008/02/28 20:40:14 UTC
[reflect] Named constructor args
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,
"create");
objectRecipe.setProperty("name", "Joe");
objectRecipe.setProperty("age", "21");
objectRecipe.setProperty("homePage", "http://www.acme.org");
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.
-dain