Banq,请教如何动态实现标准java bean?

05-07-28 hgwnet
用common属性包可实现如下动态bean,但是假的bean:

DynaProperty[] px = {

new DynaProperty("firstName", Class.forName("java.lang.String")),

new DynaProperty("lastName", Class.forName("java.lang.String"))

};

DynaClass dynaClass = new BasicDynaClass("employee", null, px);

DynaBean employee = dynaClass.newInstance();

PropertyUtils.setProperty(employee, "firstName", "Fred");

PropertyUtils.setProperty(employee, "lastName", "Flintstone");

System.out.println("firstName:" + PropertyUtils.getProperty(employee, "firstName"));

System.out.println("lastName:" + PropertyUtils.getProperty(employee, "lastName"));

由于特殊需要,须按如下反射方式取得bean属性,但系统抛出NoSuchMethodException:

Method method = employee.getClass().getMethod("getLastName", null);

debug(method.invoke(employee, null));

可否告知有无方法实现一个标准规范的bean,即可按反射方式取得属性。

先多谢了。

banq
2005-07-29 11:10
不是很清楚,标准javabean应该是能编译通过就可以吧?

猜你喜欢