akarasulu 2003/11/15 22:06:51
Modified: repository/api/src/java/org/apache/avalon/repository
Bootstrapper.java
Log:
Filled in method to instantiate using constructor with args.
Revision Changes Path
1.2 +35 -6
avalon-sandbox/repository/api/src/java/org/apache/avalon/repository/Bootstrapper.java
Index: Bootstrapper.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/repository/api/src/java/org/apache/avalon/repository/Bootstrapper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Bootstrapper.java 16 Nov 2003 05:45:05 -0000 1.1
+++ Bootstrapper.java 16 Nov 2003 06:06:51 -0000 1.2
@@ -53,6 +53,7 @@
import java.text.ParseException ;
+import java.lang.reflect.Constructor;
import java.lang.reflect.Method ;
import java.lang.reflect.InvocationTargetException ;
@@ -277,17 +278,45 @@
* @return the newly created instance
* @throws RepositoryException if the instantiation fails
*/
- public Object newInstance( String a_fqcn, String[] a_types, Object[] args )
+ public Object newInstance( String a_fqcn, String[] a_types,
+ Object[] a_args )
throws RepositoryException
{
Class l_clazz = loadClass( a_fqcn ) ;
+ Class[] l_types = new Class[a_types.length] ;
for ( int ii = 0; ii < a_types.length; ii++ )
{
-
+ l_types[ii] = loadClass( a_types[ii] ) ;
}
- throw new UnsupportedOperationException( "STUB" ) ;
+ try
+ {
+ Constructor l_constructor = l_clazz.getConstructor( l_types ) ;
+ return l_constructor.newInstance( a_args ) ;
+ }
+ catch ( InstantiationException e )
+ {
+ throw new RepositoryException(
+ "Failed to instantiate with constructor "
+ + toSignature( getConstructor( a_fqcn ), a_types ), e ) ;
+ }
+ catch ( NoSuchMethodException e )
+ {
+ throw new RepositoryException(
+ "Could not find a constructor with signature "
+ + toSignature( getConstructor( a_fqcn ), a_types ), e ) ;
+ }
+ catch ( InvocationTargetException e )
+ {
+ throw new RepositoryException( "Failed to invoke constructor "
+ + toSignature( getConstructor( a_fqcn ), a_types ), e ) ;
+ }
+ catch ( IllegalAccessException e )
+ {
+ throw new RepositoryException( "Cannot access constructor "
+ + toSignature( getConstructor( a_fqcn ), a_types ), e ) ;
+ }
}
@@ -343,7 +372,7 @@
{
throw new RepositoryException( "Failed to invoke target "
+ toSignature( a_method, a_argTypes ) + " in class "
- + a_obj.getClass() ) ;
+ + a_obj.getClass(), e ) ;
}
catch ( IllegalAccessException e )
{
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]