From ant-dev-return-23891-qmlist-jakarta-archive-ant-dev=jakarta.apache.org@jakarta.apache.org Sun Jan 27 23:41:28 2002 Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@apache.org Received: (qmail 62084 invoked from network); 27 Jan 2002 23:41:28 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 27 Jan 2002 23:41:28 -0000 Received: (qmail 17193 invoked by uid 97); 27 Jan 2002 23:41:26 -0000 Delivered-To: qmlist-jakarta-archive-ant-dev@jakarta.apache.org Received: (qmail 17123 invoked by uid 97); 27 Jan 2002 23:41:26 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 17110 invoked by uid 97); 27 Jan 2002 23:41:25 -0000 Date: 27 Jan 2002 23:41:18 -0000 Message-ID: <20020127234118.18280.qmail@icarus.apache.org> From: donaldp@apache.org To: jakarta-ant-cvs@apache.org Subject: cvs commit: jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer DefaultConfigurer.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N donaldp 02/01/27 15:41:18 Modified: proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer DefaultConfigurer.java Log: Removed "nasty hack-o-rama" by re-catching and re-throwing ConfigurationExceptions up call stack. Added support for reflection picking up typed adders Added suppot for adders that tak a Configuration object Revision Changes Path 1.20 +85 -33 jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/DefaultConfigurer.java Index: DefaultConfigurer.java =================================================================== RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/DefaultConfigurer.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- DefaultConfigurer.java 22 Jan 2002 11:15:25 -0000 1.19 +++ DefaultConfigurer.java 27 Jan 2002 23:41:18 -0000 1.20 @@ -70,16 +70,7 @@ final Context context ) throws ConfigurationException { - try - { - configureObject( object, configuration, context ); - } - catch( InvocationTargetException ite ) - { - // A configuration exception thrown from a nested object. Unpack - // and re-throw - throw (ConfigurationException)ite.getTargetException(); - } + configureObject( object, configuration, context ); } /** @@ -88,7 +79,7 @@ private void configureObject( final Object object, final Configuration configuration, final Context context ) - throws ConfigurationException, InvocationTargetException + throws ConfigurationException { if( object instanceof Configurable ) { @@ -122,6 +113,11 @@ REZ.getString( "no-such-attribute.error", elemName, name ); throw new ConfigurationException( message, nspe ); } + catch( final ConfigurationException ce ) + { + ce.fillInStackTrace(); + throw ce; + } catch( final CascadingException ce ) { final String message = @@ -146,6 +142,11 @@ REZ.getString( "no-content.error", elemName ); throw new ConfigurationException( message, nspe ); } + catch( final ConfigurationException ce ) + { + ce.fillInStackTrace(); + throw ce; + } catch( final CascadingException ce ) { final String message = @@ -170,6 +171,11 @@ REZ.getString( "no-such-element.error", elemName, name ); throw new ConfigurationException( message, nspe ); } + catch( final ConfigurationException ce ) + { + ce.fillInStackTrace(); + throw ce; + } catch( final CascadingException ce ) { final String message = @@ -230,7 +236,7 @@ private void configureElement( final ConfigurationState state, final Configuration element, final Context context ) - throws CascadingException, InvocationTargetException + throws CascadingException { final String elementName = element.getName(); if( elementName.toLowerCase().endsWith( "-ref" ) ) @@ -251,46 +257,92 @@ private void configureInline( final ConfigurationState state, final Configuration element, final Context context ) - throws CascadingException, InvocationTargetException + throws CascadingException { - final String elementName = element.getName(); + final String name = element.getName(); // Locate the configurer for the child element - final PropertyConfigurer childConfigurer = state.getConfigurer().getProperty( elementName ); + final PropertyConfigurer childConfigurer = state.getConfigurer().getProperty( name ); + + // Create & configure the child element + final Object child = + setupChild( state, element, context, childConfigurer ); + + // Set the child element + childConfigurer.addValue( state, child ); + } - // Create the child element + private Object setupChild( final ConfigurationState state, + final Configuration element, + final Context context, + final PropertyConfigurer childConfigurer ) + throws ConfigurationException + { + final String name = element.getName(); + final Class type = childConfigurer.getType(); Object child = childConfigurer.createValue( state ); - if( child == null ) + + if( null == child && Configuration.class == type ) + { + //special case where you have add(Configuration) + return element; + } + else if( null == child ) { // Create an instance using the default constructor - try + if( type.isInterface() ) { - child = childConfigurer.getType().newInstance(); + child = createdTypedObject( name, type ); + configureObject( child, element, context ); } - catch( final Exception e ) + else { - final String message = - REZ.getString( "create-object.error", - childConfigurer.getType().getName() ); - throw new ConfigurationException( message, e ); + child = createObject( type ); + configureObject( child, element, context ); } } + configureObject( child, element, context ); + return child; + } - // Configure the child element + /** + * Utility method to create an instance of the + * specified type that satisfied supplied interface. + */ + private Object createdTypedObject( final String name, + final Class type ) + throws ConfigurationException + { try { - configureObject( child, element, context ); + return type.newInstance(); } - catch( final ConfigurationException ce ) + catch( final Exception e ) { - // Nasty hack-o-rama, used to get this exception up through - // the stack of doConfigure() calls. This is unpacked by the - // top-most configure() call, and rethrown. - throw new InvocationTargetException( ce ); + final String message = + REZ.getString( "create-object.error", + type.getName() ); + throw new ConfigurationException( message, e ); } + } - // Set the child element - childConfigurer.addValue( state, child ); + /** + * Utility method to instantiate an instance of the specified class. + */ + private Object createObject( final Class type ) + throws ConfigurationException + { + try + { + return type.newInstance(); + } + catch( final Exception e ) + { + final String message = + REZ.getString( "create-object.error", + type.getName() ); + throw new ConfigurationException( message, e ); + } } /** -- To unsubscribe, e-mail: For additional commands, e-mail: