ITeye博客

在jbpm3中使用Ioc

hongsoft · 2005-02-21 15:48 · Markdown

在jbpm3中,采用反射实现了从配置文件中构造一个新的对象的功能,
使用方法如下:
   String configuration =
      "<s>hello</s>" +
      "<stringConstructor>" +
      "  i want yoghurt" +
      "</stringConstructor>" +
      "<structuredElement>" +
      " <surfboard length=\"270\" />" +
      " <mast length=\"475\" />" +
      " <boom length=\"160\" />" +
      " <sail size=\"5.7\" />" +
      "</structuredElement>" +
      "<memberWithoutSetter>hello</memberWithoutSetter>";
   
    Mix mix = (Mix) beanInstantiator.instantiate(Mix.class, configuration);
   
    assertEquals( "hello", mix.s );
它的实现方法很简单,就是使用java.lang.reflect.*包,构造对象,然后根据解析的文件
为对象的属性赋值

其实,我们把它的实现稍做扩展,就可以实现我们自己的ioc:
Mix mix=(Mix)MyIoc.getbean("theMix");
和
Mix mix = (Mix) beanInstantiator.instantiate(Mix.class, configuration);
比较,显得更简单一些,呵呵.

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。