diff --git a/proposal/myrmidon/src/java/org/apache/antlib/core/Resources.properties b/proposal/myrmidon/src/java/org/apache/antlib/core/Resources.properties index 94fa15265..a374dcc5b 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/core/Resources.properties +++ b/proposal/myrmidon/src/java/org/apache/antlib/core/Resources.properties @@ -9,6 +9,7 @@ loadprop.file.notice=Loading proeprties from {0}. loadprop.missing-file.notice=Unable to find property file: {0}. loadprop.bad-resolve.error=Unable to resolve and set property named "{0}" to value "{1}". +convert.bad-boolean.error=Error converting object ({0}) to Boolean. convert.bad-byte.error=Error converting object ({0}) to Byte. convert.bad-class.error=Error converting object ({0}) to Class. convert.bad-double.error=Error converting object ({0}) to Double. diff --git a/proposal/myrmidon/src/java/org/apache/antlib/core/StringToBooleanConverter.java b/proposal/myrmidon/src/java/org/apache/antlib/core/StringToBooleanConverter.java new file mode 100644 index 000000000..0467648b6 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/antlib/core/StringToBooleanConverter.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) The Apache Software Foundation. All rights reserved. + * + * This software is published under the terms of the Apache Software License + * version 1.1, a copy of which has been included with this distribution in + * the LICENSE.txt file. + */ +package org.apache.antlib.core; + +import org.apache.avalon.excalibur.i18n.ResourceManager; +import org.apache.avalon.excalibur.i18n.Resources; +import org.apache.avalon.framework.context.Context; +import org.apache.myrmidon.converter.AbstractConverter; +import org.apache.myrmidon.converter.ConverterException; + +/** + * String to boolean converter + * + * @author Peter Donald + */ +public class StringToBooleanConverter + extends AbstractConverter +{ + private static final Resources REZ = + ResourceManager.getPackageResources( StringToBooleanConverter.class ); + + public StringToBooleanConverter() + { + super( String.class, Boolean.class ); + } + + public Object convert( final Object object, final Context context ) + throws ConverterException + { + final String string = (String)object; + if( string.equals( "true" ) ) + { + return Boolean.TRUE; + } + else if( string.equals( "false" ) ) + { + return Boolean.FALSE; + } + else + { + final String message = REZ.getString( "convert.bad-boolean.error", object ); + throw new ConverterException( message ); + } + } +} + diff --git a/proposal/myrmidon/src/manifest/core-ant-descriptor.xml b/proposal/myrmidon/src/manifest/core-ant-descriptor.xml index 6b70650f8..4f282cdcd 100644 --- a/proposal/myrmidon/src/manifest/core-ant-descriptor.xml +++ b/proposal/myrmidon/src/manifest/core-ant-descriptor.xml @@ -18,6 +18,9 @@ +