ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer DefaultObjectConfigurer.java
Date Sun, 27 Jan 2002 23:39:47 GMT
donaldp     02/01/27 15:39:46

  Modified:    proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer
                        DefaultObjectConfigurer.java
  Log:
  Made class package access until such a time when it is needed outside package
  
  Added support for reflection picking up typed adders
  
  Revision  Changes    Path
  1.6       +53 -23    jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/DefaultObjectConfigurer.java
  
  Index: DefaultObjectConfigurer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/DefaultObjectConfigurer.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DefaultObjectConfigurer.java	26 Jan 2002 11:59:31 -0000	1.5
  +++ DefaultObjectConfigurer.java	27 Jan 2002 23:39:46 -0000	1.6
  @@ -20,15 +20,16 @@
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.avalon.framework.configuration.Configuration;
   
   /**
    * An object configurer which uses reflection to determine the properties
    * of a class.
    *
    * @author <a href="mailto:adammurdoch_ml@yahoo.com">Adam Murdoch</a>
  - * @version $Revision: 1.5 $ $Date: 2002/01/26 11:59:31 $
  + * @version $Revision: 1.6 $ $Date: 2002/01/27 23:39:46 $
    */
  -public class DefaultObjectConfigurer
  +class DefaultObjectConfigurer
       implements ObjectConfigurer
   {
       private final static Resources REZ =
  @@ -154,12 +155,24 @@
           {
               final Method method = (Method)iterator.next();
               final String methodName = method.getName();
  -            if( method.getReturnType() != Void.TYPE
  -                || method.getParameterTypes().length != 1 )
  +            if( Void.TYPE != method.getReturnType() ||
  +                1 != method.getParameterTypes().length )
               {
                   continue;
               }
   
  +            final boolean isTypedAdder = methodName.equals( "add" );
  +
  +            final Class paramType = method.getParameterTypes()[ 0 ];
  +            if( isTypedAdder && !paramType.isInterface() )
  +            {
  +                final String message =
  +                    REZ.getString( "typed-adder-non-interface.error",
  +                                   m_class.getName(),
  +                                   paramType.getName() );
  +                throw new ConfigurationException( message );
  +            }
  +
               // TODO - un-hard-code this
               if( methodName.equals( "addContent" ) )
               {
  @@ -169,12 +182,13 @@
               // Extract property name
               final String propName = extractName( 3, methodName );
   
  -            final Class type = method.getParameterTypes()[ 0 ];
  +            final Class type = paramType;
   
               // Add to the adders map
               if( adders.containsKey( propName ) )
               {
  -                final Class currentType = ( (Method)adders.get( propName ) ).getParameterTypes()[
0 ];
  +                final Method candidate = (Method)adders.get( propName );
  +                final Class currentType = candidate.getParameterTypes()[ 0 ];
   
                   // Ditch the string version, if any
                   if( currentType != String.class && type == String.class )
  @@ -183,7 +197,7 @@
                       // the new method
                       continue;
                   }
  -                if( currentType != String.class || type == String.class )
  +                else if( currentType != String.class || type == String.class )
                   {
                       // Both are string, or both are not string
                       final String message =
  @@ -192,6 +206,16 @@
                                          propName );
                       throw new ConfigurationException( message );
                   }
  +                else if( isTypedAdder )
  +                {
  +                    // Both are string, or both are not string
  +                    final String message =
  +                        REZ.getString( "multiple-typed-adder-methods-for-element.error",
  +                                       m_class.getName(),
  +                                       type.getName(),
  +                                       currentType.getName() );
  +                    throw new ConfigurationException( message );
  +                }
   
                   // Else, current type is string, and new type is not, so
                   // continue below, and overwrite the current method
  @@ -312,7 +336,7 @@
           final int size = m_allProps.size();
           for( int i = 0; i < size; i++ )
           {
  -            if( defState.getCreatedObject( i ) != null )
  +            if( null != defState.getCreatedObject( i ) )
               {
                   final String message = REZ.getString( "pending-property-value.error" );
                   throw new ConfigurationException( message );
  @@ -325,32 +349,38 @@
       /**
        * Returns a configurer for an element of this class.
        */
  -    public PropertyConfigurer getProperty( final String name ) throws NoSuchPropertyException
  +    public PropertyConfigurer getProperty( final String name )
  +        throws NoSuchPropertyException
       {
  -        final PropertyConfigurer prop = (PropertyConfigurer)m_props.get( name );
  -        if( prop != null )
  +        final PropertyConfigurer configurer = (PropertyConfigurer)m_props.get( name );
  +        if( null != configurer )
           {
  -            return prop;
  +            return configurer;
  +        }
  +        else
  +        {
  +            // Unknown property
  +            final String message = REZ.getString( "unknown-property.error", m_class.getName(),
name );
  +            throw new NoSuchPropertyException( message );
           }
  -
  -        // Unknown property
  -        final String message = REZ.getString( "unknown-property.error", m_class.getName(),
name );
  -        throw new NoSuchPropertyException( message );
       }
   
       /**
        * Returns a configurer for the content of this class.
        */
  -    public PropertyConfigurer getContentConfigurer() throws NoSuchPropertyException
  +    public PropertyConfigurer getContentConfigurer()
  +        throws NoSuchPropertyException
       {
  -        if( m_contentConfigurer != null )
  +        if( null != m_contentConfigurer )
           {
               return m_contentConfigurer;
           }
  -
  -        // Does not handle content
  -        final String message = REZ.getString( "content-unsupported.error", m_class.getName()
);
  -        throw new NoSuchPropertyException( message );
  +        else
  +        {
  +            // Does not handle content
  +            final String message = REZ.getString( "content-unsupported.error", m_class.getName()
);
  +            throw new NoSuchPropertyException( message );
  +        }
       }
   
       /**
  @@ -399,7 +429,7 @@
               final Method method = methods[ i ];
               final String methodName = method.getName();
               if( Modifier.isStatic( method.getModifiers() ) ||
  -                methodName.length() <= prefixLen ||
  +                methodName.length() < prefixLen ||
                   !methodName.startsWith( prefix ) )
               {
                   continue;
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message