KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.instantiation;
2
3 import java.lang.reflect.*;
4 import org.apache.commons.logging.*;
5
6 public class ConstructorInstantiator 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       Constructor constructor = clazz.getDeclaredConstructor( parameterTypes );
14       constructor.setAccessible(true);
15       newInstance = constructor.newInstance( new Object JavaDoc[] { configuration } );
16     } catch (Exception JavaDoc e) {
17       log.error( "couldn't instantiate '" + clazz.getName() + "'", e );
18       throw new RuntimeException JavaDoc( e );
19     }
20     return newInstance;
21   }
22
23   private static final Log log = LogFactory.getLog(ConstructorInstantiator.class);
24 }
25
Popular Tags