donaldp 01/03/14 21:52:00 Modified: src/compat/org/apache/avalon Configuration.java Added: src/compat/org/apache/avalon Parameters.java src/java/org/apache/avalon/configuration Parameters.java Removed: src/java/org/apache/avalon Parameters.java Log: Moved Parameters to configuration sub-directory as it depends on Configurtion* classes. Deprecated old version and pointed it to new version. Revision Changes Path 1.2 +20 -10 jakarta-avalon/src/compat/org/apache/avalon/Configuration.java Index: Configuration.java =================================================================== RCS file: /home/cvs/jakarta-avalon/src/compat/org/apache/avalon/Configuration.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Configuration.java 2001/03/15 05:09:17 1.1 +++ Configuration.java 2001/03/15 05:52:00 1.2 @@ -81,7 +81,8 @@ * @return String value of attribute. * @exception ConfigurationException If no attribute with that name exists. */ - String getAttribute( String paramName ) throws ConfigurationException; + String getAttribute( String paramName ) + throws ConfigurationException; /** * Return the <code>int</code> value of the specified attribute contained @@ -95,7 +96,8 @@ * @exception ConfigurationException If no parameter with that name exists. * or if conversion to <code>int</code> fails. */ - int getAttributeAsInt( String paramName ) throws ConfigurationException; + int getAttributeAsInt( String paramName ) + throws ConfigurationException; /** * Returns the value of the attribute specified by its name as a @@ -109,7 +111,8 @@ * @exception ConfigurationException If no parameter with that name exists. * or if conversion to <code>long</code> fails. */ - long getAttributeAsLong( String name ) throws ConfigurationException; + long getAttributeAsLong( String name ) + throws ConfigurationException; /** * Return the <code>float</code> value of the specified parameter contained @@ -123,7 +126,8 @@ * @exception ConfigurationException If no parameter with that name exists. * or if conversion to <code>float</code> fails. */ - float getAttributeAsFloat( String paramName ) throws ConfigurationException; + float getAttributeAsFloat( String paramName ) + throws ConfigurationException; /** * Return the <code>boolean</code> value of the specified parameter contained @@ -137,7 +141,8 @@ * @exception ConfigurationException If no parameter with that name exists. * or if conversion to <code>boolean</code> fails. */ - boolean getAttributeAsBoolean( String paramName ) throws ConfigurationException; + boolean getAttributeAsBoolean( String paramName ) + throws ConfigurationException; /** * Return the <code>String</code> value of the node. @@ -146,7 +151,8 @@ * * @return the value of the node. */ - String getValue() throws ConfigurationException; + String getValue() + throws ConfigurationException; /** * Return the <code>int</code> value of the node. @@ -157,7 +163,8 @@ * * @exception ConfigurationException If conversion to <code>int</code> fails. */ - int getValueAsInt() throws ConfigurationException; + int getValueAsInt() + throws ConfigurationException; /** * Return the <code>float</code> value of the node. @@ -167,7 +174,8 @@ * @return the value of the node. * @exception ConfigurationException If conversion to <code>float</code> fails. */ - float getValueAsFloat() throws ConfigurationException; + float getValueAsFloat() + throws ConfigurationException; /** * Return the <code>boolean</code> value of the node. @@ -177,7 +185,8 @@ * @return the value of the node. * @exception ConfigurationException If conversion to <code>boolean</code> fails. */ - boolean getValueAsBoolean() throws ConfigurationException; + boolean getValueAsBoolean() + throws ConfigurationException; /** * Return the <code>long</code> value of the node.<br> @@ -187,7 +196,8 @@ * @return the value of the node. * @exception ConfigurationException If conversion to <code>long</code> fails. */ - long getValueAsLong() throws ConfigurationException; + long getValueAsLong() + throws ConfigurationException; /** * Returns the value of the configuration element as a <code>String</code>. 1.1 jakarta-avalon/src/compat/org/apache/avalon/Parameters.java Index: Parameters.java =================================================================== /* * 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 file. */ package org.apache.avalon; /** * * @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a> * @deprecated Use org.apache.avalon.configuration.Parameters instead */ public final class Parameters extends org.apache.avalon.configuration.Parameters { } 1.1 jakarta-avalon/src/java/org/apache/avalon/configuration/Parameters.java Index: Parameters.java =================================================================== /* * 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 file. */ package org.apache.avalon.configuration; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.List; /** * * @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a> */ public class Parameters { protected HashMap m_parameters; /** * Create a new <code>Parameters</code> instance. */ public Parameters() { m_parameters = new HashMap(); } /** * Set the <code>String</code> value of a specified parameter. * <p /> * If the specified value is <b>null</b> the parameter is removed. * * @return The previous value of the parameter or <b>null</b>. */ public String setParameter( final String name, final String value ) { if( null == name ) { return null; } if( null == value ) { return (String)m_parameters.remove( name ); } return (String)m_parameters.put( name, value ); } /** * Return an <code>Enumeration</code> view of all parameter names. */ public Iterator getParameterNames() { return m_parameters.keySet().iterator(); } /** * Check if the specified parameter can be retrieved. */ public boolean isParameter( final String name ) { return m_parameters.containsKey( name ); } /** * Retrieve the <code>String</code> value of the specified parameter. * <p /> * If the specified parameter cannot be found, <b>null</b> is returned. */ protected String getParameter( final String name ) { if( null == name ) { return null; } return (String)m_parameters.get( name ); } /** * Retrieve the <code>String</code> value of the specified parameter. * <p /> * If the specified parameter cannot be found, <code>defaultValue</code> * is returned. */ public String getParameter( final String name, final String defaultValue ) { final String value = getParameter( name ); if( null == value ) { return defaultValue; } else { return value; } } /** * Retrieve the <code>int</code> value of the specified parameter. * <p /> * If the specified parameter cannot be found, <code>defaultValue</code> * is returned. */ public int getParameterAsInteger( final String name, final int defaultValue ) { final String value = getParameter( name ); if( null == value ) { return defaultValue; } try { if( value.startsWith("0x") ) { return Integer.parseInt( value.substring(2), 16 ); } else if( value.startsWith("0o") ) { return Integer.parseInt( value.substring(2), 8 ); } else if( value.startsWith("0b") ) { return Integer.parseInt( value.substring(2), 2 ); } else { return Integer.parseInt( value ); } } catch( final NumberFormatException nfe ) { return defaultValue; } } /** * Retrieve the <code>long</code> value of the specified parameter. * <p /> * If the specified parameter cannot be found, <code>defaultValue</code> * is returned. */ public long getParameterAsLong( final String name, final long defaultValue ) { final String value = getParameter( name ); if( null == value ) { return defaultValue; } try { if( value.startsWith("0x") ) { return Long.parseLong( value.substring(2), 16 ); } else if( value.startsWith("0o") ) { return Long.parseLong( value.substring(2), 8 ); } else if( value.startsWith("0b") ) { return Long.parseLong( value.substring(2), 2 ); } else { return Long.parseLong(value); } } catch( final NumberFormatException nfe ) { return defaultValue; } } /** * Retrieve the <code>float</code> value of the specified parameter. * <p /> * If the specified parameter cannot be found, <code>defaultValue</code> * is returned. */ public float getParameterAsFloat( final String name, final float defaultValue ) { final String value = getParameter( name ); if( null == value ) { return defaultValue; } try { return Float.parseFloat(value); } catch( final NumberFormatException nfe ) { return defaultValue; } } /** * Retrieve the <code>boolean</code> value of the specified parameter. * <p /> * If the specified parameter cannot be found, <code>defaultValue</code> * is returned. */ public boolean getParameterAsBoolean( final String name, final boolean defaultValue ) { final String value = getParameter( name ); if( null == value ) { return defaultValue; } if( value.equalsIgnoreCase("true") ) { return true; } if( value.equalsIgnoreCase("false") ) { return(false); } return defaultValue; } /** * Merge parameters from another <code>Parameters</code> instance * into this. * * @return This <code>Parameters</code> instance. */ public Parameters merge( final Parameters other ) { final Iterator names = other.getParameterNames(); while( names.hasNext() ) { final String name = (String) names.next(); final String value = other.getParameter( name ); setParameter( name, value ); } return this; } /** * Create a <code>Parameters</code> object from a <code>Configuration</code> * object. * @deprecated Will be removed when old config removed */ public static Parameters fromConfiguration( final org.apache.avalon.Configuration configuration ) throws org.apache.avalon.ConfigurationException { if( null == configuration ) { throw new org.apache.avalon. ConfigurationException( "You cannot convert to parameters with " + "a null Configuration"); } final Iterator parameters = configuration.getChildren("parameter"); final Parameters param = new Parameters(); while( parameters.hasNext() ) { try { final org.apache.avalon.Configuration child = (org.apache.avalon.Configuration)parameters.next(); final String name = child.getAttribute( "name" ); final String value = child.getAttribute( "value" ); param.setParameter( name, value ); } catch( final ClassCastException cce ) { // ignore this. Temporary work around until the Iterator // is guaranteed to return Configuration values. Unfortunately // there are problems with empty strings getting in there. } catch( final Exception e ) { throw new org.apache.avalon. ConfigurationException( "Cannot process Configurable", e ); } } return param; } /** * Create a <code>Parameters</code> object from a <code>Configuration</code> * object. */ public static Parameters fromConfiguration( final Configuration configuration ) throws ConfigurationException { if( null == configuration ) { throw new ConfigurationException( "You cannot convert to parameters with " + "a null Configuration" ); } final Configuration[] parameters = configuration.getChildren( "parameter" ); final Parameters param = new Parameters(); for (int i = 0; i < parameters.length; i++ ) { try { final String name = parameters[ i ].getAttribute( "name" ); final String value = parameters[ i ].getAttribute( "value" ); param.setParameter( name, value ); } catch( final Exception e ) { throw new ConfigurationException( "Cannot process Configurable", e ); } } return param; } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]