KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > instantiation > ConfigurationPropertyInstantiator


1 package org.jbpm.instantiation;
2
3 import java.lang.reflect.*;
4 import org.apache.commons.logging.*;
5
6 public class ConfigurationPropertyInstantiator implements Instantiator {
7
8   private static final Class JavaDoc[] parameterTypes = new Class JavaDoc[] {String JavaDoc.class};
9
10   public Object JavaDoc instantiate(Class JavaDoc clazz, String JavaDoc configuration) {
11     Object JavaDoc newInstance = null;
12     try {
13       // create the object
14
newInstance = clazz.newInstance();
15       
16       // set the configuration with the bean-style setter
17
Method setter = clazz.getDeclaredMethod( "setConfiguration", parameterTypes );
18       setter.setAccessible(true);
19       setter.invoke( newInstance, new Object JavaDoc[]{ configuration } );
20       
21     } catch (Exception JavaDoc e) {
22       log.error( "couldn't instantiate '" + clazz.getName() + "'", e );
23       throw new RuntimeException JavaDoc( e );
24     }
25     return newInstance;
26   }
27   
28   private static final Log log = LogFactory.getLog(ConfigurationPropertyInstantiator.class);
29 }
30
Popular Tags