From ff8b6709bcf07f12efecc3625f5e1665e7ddf34d Mon Sep 17 00:00:00 2001 From: Peter Donald Date: Sun, 27 Jan 2002 23:39:46 +0000 Subject: [PATCH] Made class package access until such a time when it is needed outside package Added support for reflection picking up typed adders git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270967 13f79535-47bb-0310-9956-ffa450edef68 --- .../configurer/DefaultObjectConfigurer.java | 74 +++++++++++++------ 1 file changed, 52 insertions(+), 22 deletions(-) diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/DefaultObjectConfigurer.java b/proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/DefaultObjectConfigurer.java index 74b7f66e7..a5f0f7376 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/DefaultObjectConfigurer.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/DefaultObjectConfigurer.java @@ -20,6 +20,7 @@ import java.util.Set; 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 @@ -28,7 +29,7 @@ import org.apache.avalon.framework.configuration.ConfigurationException; * @author Adam Murdoch * @version $Revision$ $Date$ */ -public class DefaultObjectConfigurer +class DefaultObjectConfigurer implements ObjectConfigurer { private final static Resources REZ = @@ -154,12 +155,24 @@ public class DefaultObjectConfigurer { 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 @@ public class DefaultObjectConfigurer // 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 @@ public class DefaultObjectConfigurer // 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 @@ public class DefaultObjectConfigurer 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 @@ public class DefaultObjectConfigurer 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 @@ public class DefaultObjectConfigurer /** * 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 @@ public class DefaultObjectConfigurer 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;