donaldp 01/02/23 20:01:47
Added: src/java/org/apache/avalon AbstractConfiguration.java
AbstractLoggable.java CascadingError.java
CascadingException.java
CascadingRuntimeException.java
CascadingThrowable.java Component.java
ComponentManager.java
ComponentManagerException.java
ComponentNotAccessibleException.java
ComponentNotFoundException.java
ComponentSelector.java Composer.java
Configurable.java Configuration.java
ConfigurationBuilder.java
ConfigurationException.java Context.java
Contextualizable.java DefaultComponentManager.java
DefaultComponentSelector.java
DefaultConfiguration.java
DefaultConfigurationBuilder.java
DefaultContext.java DefaultPipeline.java
Disposable.java Initializable.java Loggable.java
Modifiable.java Parameters.java Pipeline.java
Poolable.java ProcessorPipeline.java
ProcessorStage.java Recomposer.java
Reconfigurable.java Recontextualizable.java
Recyclable.java Resolvable.java Resumable.java
SAXConfigurationHandler.java SingleThreaded.java
Stage.java Startable.java Stoppable.java
Suspendable.java ThreadSafe.java
Log:
Rechecked in avalon
Revision Changes Path
1.1
jakarta-avalon/src/java/org/apache/avalon/AbstractConfiguration.java
Index: AbstractConfiguration.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;
import java.util.Iterator;
/**
* This is an abstract <code>Configuration</code> implementation that deals
* with methods that can be abstracted away from underlying implementations.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
* @version CVS $Revision: 1.1 $ $Date: 2001/02/24 04:01:45 $
* @deprecated This has been deprecated in favour of configuration interface
in org.apache.avalon.configuration interface
*/
public abstract class AbstractConfiguration
implements Configuration
{
private static int PREFIX = 2;
/**
* Returns the value of the configuration element as an <code>int</code>.
*/
public int getValueAsInt()
throws ConfigurationException
{
final String value = getValue();
try
{
if( value.startsWith("0x") )
{
return Integer.parseInt(
value.substring(AbstractConfiguration.PREFIX), 16 );
}
else if( value.startsWith("0o") )
{
return Integer.parseInt(
value.substring(AbstractConfiguration.PREFIX), 8 );
}
else if( value.startsWith("0b") )
{
return Integer.parseInt(
value.substring(AbstractConfiguration.PREFIX), 2 );
}
else
{
return Integer.parseInt( value );
}
}
catch( final Exception nfe )
{
throw
new ConfigurationException( "Cannot parse the value of the
configuration " +
"element \"" + getName() + "\" as
an integer" );
}
}
/**
* Returns the value of the configuration element as an <code>int</code>.
*/
public int getValueAsInt( final int defaultValue )
{
try
{
return getValueAsInt();
}
catch( final ConfigurationException ce )
{
return defaultValue;
}
}
/**
* Returns the value of the configuration element as a <code>long</code>.
*/
public long getValueAsLong()
throws ConfigurationException
{
final String value = getValue();
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 Integer.parseInt(value);
}
catch( final Exception nfe )
{
throw new ConfigurationException( "Cannot parse the value of the
" +
"configuration element \"" +
getName() +
"\" as a long" );
}
}
/**
* Returns the value of the configuration element as a <code>long</code>.
*/
public long getValueAsLong( final long defaultValue )
{
try
{
return getValueAsLong();
}
catch( final ConfigurationException ce )
{
return defaultValue;
}
}
/**
* Returns the value of the configuration element as a <code>float</code>.
*/
public float getValueAsFloat()
throws ConfigurationException
{
final String value = getValue();
try
{
return Float.parseFloat( value );
}
catch( final Exception nfe )
{
throw new ConfigurationException( "Cannot parse the value of the
" +
"configuration element \"" +
getName() +
"\" as a float" );
}
}
/**
* Returns the value of the configuration element as a <code>float</code>.
*/
public float getValueAsFloat( final float defaultValue )
{
try
{
return getValueAsFloat();
}
catch( final ConfigurationException ce )
{
return(defaultValue);
}
}
/**
* Returns the value of the configuration element as a
<code>boolean</code>.
*/
public boolean getValueAsBoolean()
throws ConfigurationException
{
final String value = getValue();
if( value.equals("true") ) return true;
else if( value.equals("false") ) return false;
else
{
throw new ConfigurationException( "Cannot parse the value of the
" +
"configuration element \"" +
getName() + "\" as a boolean" );
}
}
/**
* Returns the value of the configuration element as a
<code>boolean</code>.
*/
public boolean getValueAsBoolean( final boolean defaultValue )
{
try
{
return getValueAsBoolean();
}
catch( final ConfigurationException ce )
{
return defaultValue;
}
}
/**
* Returns the value of the configuration element as a
<code>String</code>.
*/
public String getValue( final String defaultValue )
{
try
{
return getValue();
}
catch( final ConfigurationException ce )
{
return defaultValue;
}
}
/**
* Returns the value of the attribute specified by its name as an
* <code>int</code>.
*/
public int getAttributeAsInt( final String name )
throws ConfigurationException
{
final String value = getAttribute( name );
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 Exception nfe )
{
throw new ConfigurationException( "Cannot parse the value of the
attribute \"" +
name + "\" of the configuration
element \"" +
getName() + "\" as an integer"
);
}
}
/**
* Returns the value of the attribute specified by its name as an
* <code>int</code>.
*/
public int getAttributeAsInt( final String name, final int defaultValue )
{
try
{
return getAttributeAsInt( name );
}
catch( final ConfigurationException ce )
{
return defaultValue;
}
}
/**
* Returns the value of the attribute specified by its name as a
* <code>long</code>.
*/
public long getAttributeAsLong( final String name )
throws ConfigurationException
{
final String value = getAttribute( name );
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 Integer.parseInt( value );
}
}
catch( final Exception nfe )
{
throw new ConfigurationException( "Cannot parse the value of the
attribute \"" +
name + "\" of the configuration
element \"" +
getName() + "\" as a long" );
}
}
/**
* Returns the value of the attribute specified by its name as a
* <code>long</code>.
*/
public long getAttributeAsLong( final String name, final long
defaultValue )
{
try
{
return getAttributeAsLong( name );
}
catch( final ConfigurationException ce )
{
return defaultValue;
}
}
/**
* Returns the value of the attribute specified by its name as a
* <code>float</code>.
*/
public float getAttributeAsFloat( final String name )
throws ConfigurationException
{
final String value = getAttribute( name );
try
{
return Float.parseFloat( value );
}
catch( final Exception e )
{
throw new ConfigurationException( "Cannot parse the value of the
attribute \"" +
name + "\" of the configuration
element \"" +
getName() + "\" as a float" );
}
}
/**
* Returns the value of the attribute specified by its name as a
* <code>float</code>.
*/
public float getAttributeAsFloat( final String name, final float
defaultValue )
{
try
{
return getAttributeAsFloat( name );
}
catch( final ConfigurationException ce )
{
return defaultValue;
}
}
/**
* Returns the value of the attribute specified by its name as a
* <code>boolean</code>.
*/
public boolean getAttributeAsBoolean( final String name )
throws ConfigurationException
{
final String value = getAttribute( name );
if( value.equals("true") ) return true;
else if( value.equals("false") ) return false;
else
{
throw new ConfigurationException( "Cannot parse the value of the
attribute \"" +
name + "\" of the configuration
element \"" +
getName() + "\" as a boolean" );
}
}
/**
* Returns the value of the attribute specified by its name as a
* <code>boolean</code>.
*/
public boolean getAttributeAsBoolean( final String name, final boolean
defaultValue )
{
try
{
return getAttributeAsBoolean( name );
}
catch( final ConfigurationException ce )
{
return defaultValue;
}
}
/**
* Returns the value of the attribute specified by its name as a
* <code>String</code>.
*/
public String getAttribute( final String name, final String defaultValue )
{
try
{
return getAttribute( name );
}
catch( final ConfigurationException ce )
{
return defaultValue;
}
}
/**
* Return the first <code>Configuration</code> object child of this
* associated with the given name.
*/
public Configuration getChild( final String name )
{
final Iterator iterator = getChildren( name );
if( iterator.hasNext() )
{
return (Configuration)iterator.next();
}
else
{
return new DefaultConfiguration( name, "-" );
}
}
}
1.1
jakarta-avalon/src/java/org/apache/avalon/AbstractLoggable.java
Index: AbstractLoggable.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;
import org.apache.log.Logger;
/**
* Helper class to inherit from.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
*/
public abstract class AbstractLoggable
implements Component, Loggable
{
protected Logger m_logger;
public void setLogger( final Logger logger )
{
m_logger = logger;
}
protected final Logger getLogger()
{
return m_logger;
}
protected void setupLogger( final Component component )
{
setupLogger( component, (String)null );
}
protected void setupLogger( final Component component, final String
subCategory )
{
if( component instanceof Loggable )
{
Logger logger = m_logger;
if( null != subCategory )
{
logger = m_logger.getChildLogger( subCategory );
}
((Loggable)component).setLogger( logger );
}
}
protected void setupLogger( final Component component, final Logger
logger )
{
if( component instanceof Loggable )
{
((Loggable)component).setLogger( logger );
}
}
}
1.1
jakarta-avalon/src/java/org/apache/avalon/CascadingError.java
Index: CascadingError.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;
/**
* Class from which all exceptions should inherit.
* Allows recording of nested exceptions.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
*/
public abstract class CascadingError
extends Error
implements CascadingThrowable
{
private final Throwable m_throwable;
/**
* Construct a new <code>CascadingError</code> instance.
*
* @param message The detail message for this exception.
* @param throwable the root cause of the exception
*/
public CascadingError( final String message, final Throwable throwable )
{
super( message );
m_throwable = throwable;
}
/**
* Retrieve root cause of the exception.
*
* @return the root cause
*/
public final Throwable getCause()
{
return m_throwable;
}
}
1.1
jakarta-avalon/src/java/org/apache/avalon/CascadingException.java
Index: CascadingException.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;
/**
* Class from which all exceptions should inherit.
* Allows recording of nested exceptions.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
*/
public class CascadingException
extends Exception
implements CascadingThrowable
{
private final Throwable m_throwable;
/**
* Construct a new <code>CascadingException</code> instance.
*
* @param message The detail message for this exception.
*/
public CascadingException( final String message )
{
this( message, null );
}
/**
* Construct a new <code>CascadingException</code> instance.
*
* @param message The detail message for this exception.
* @param throwable the root cause of the exception
*/
public CascadingException( final String message, final Throwable
throwable )
{
super( message );
m_throwable = throwable;
}
/**
* Retrieve root cause of the exception.
*
* @return the root cause
*/
public final Throwable getCause()
{
return m_throwable;
}
}
1.1
jakarta-avalon/src/java/org/apache/avalon/CascadingRuntimeException.java
Index: CascadingRuntimeException.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;
/**
* Class from which all exceptions should inherit.
* Allows recording of nested exceptions.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
*/
public abstract class CascadingRuntimeException
extends RuntimeException
implements CascadingThrowable
{
private final Throwable m_throwable;
/**
* Construct a new <code>CascadingRuntimeException</code> instance.
*
* @param message The detail message for this exception.
* @param throwable the root cause of the exception
*/
public CascadingRuntimeException( final String message, final Throwable
throwable )
{
super( message );
m_throwable = throwable;
}
/**
* Retrieve root cause of the exception.
*
* @return the root cause
*/
public final Throwable getCause()
{
return m_throwable;
}
}
1.1
jakarta-avalon/src/java/org/apache/avalon/CascadingThrowable.java
Index: CascadingThrowable.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;
/**
* Interface which all cascadign throwables should implement.
* Allows recording of nested exceptions.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
*/
public interface CascadingThrowable
{
Throwable getCause();
}
1.1 jakarta-avalon/src/java/org/apache/avalon/Component.java
Index: Component.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;
/**
* This interface identifies classes that can be used as
<code>Components</code>
* by a <code>Composer</code>.
* <br />
*
* The contract surrounding the <code>Component</code> is that it is
* used, but not a user. When a class implements this interface, it
* is stating that other entities may use that class. As part of the
* contract with the system, a <code>Component</code> must always
* declare an empty constructor.
* <br />
*
* A <code>Component</code> is the basic building block of the Avalon.
* When a class implements this interface, it allows itself to be
* managed by a <code>ComponentManager</code> and used by an outside
* element called a <code>Composer</code>. The <code>Composer</code>
* must know what type of <code>Component</code> it is accessing, so
* it will re-cast the <code>Component</code> into the type it needs.
* <br />
*
* In order for a <code>Component</code> to be useful you must either
* extend this interface, or implement this interface in conjunction
* with one that actually has methods. The new interface is the contract
* with the <code>Composer</code> that this is a particular type of
* component, and as such it can perform those functions on that type
* of component.
* <br />
*
* For example, we want a component that performs a logging function
* so we extend the <code>Component</code> to be a
<code>LoggingComponent</code>.
*
* <pre>
* interface LoggingComponent extends Component {
* log(String message);
* }
* </pre>
*
* Now all <code>Composer</code>s that want to use this type of component,
* will re-cast the <code>Component</code> into a
<code>LoggingComponent</code>
* and the <code>Composer</code> will be able to use the <code>log</code>
* method.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
* @author <a href="mailto:[EMAIL PROTECTED]>Berin Loritsch</a>
*/
public interface Component
{
}
1.1
jakarta-avalon/src/java/org/apache/avalon/ComponentManager.java
Index: ComponentManager.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;
/**
* A <code>ComponentManager</code> selects <code>Component</code>s based on a
* role. The contract is that all the <code>Component</code>s implement the
* differing roles and there is one <code>Component</code> per role. If you
* need to select on of many <code>Component</code>s that implement the same
* role, then you need to use a <code>ComponentSelector</code>. Roles are the
* full interface name.
*
* A role is better understood by the analogy of a play. There are many
* different roles in a script. Any actor or actress can play any given part
* and you get the same results (phrases said, movements made, etc.). The
exact
* nuances of the performance is different.
*
* Below is a list of things that might be considered the different roles:
*
* <ul>
* <li> InputAdaptor and OutputAdaptor</li>
* <li> Store and Spool</li>
* </ul>
*
* The <code>ComponentManager</code> does not specify the methodology of
* getting the <code>Component</code>, merely the interface used to get it.
* Therefore the <code>ComponentManager</code> can be implemented with a
* factory pattern, an object pool, or a simple Hashtable.
*
* @see org.apache.avalon.Component
* @see org.apache.avalon.Composer
* @see org.apache.avalon.ComponentSelector
*
* @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
* @author <a href="mailto:[EMAIL PROTECTED]>Berin Loritsch</a>
*/
public interface ComponentManager
{
/**
* Get the <code>Component</code> associated with the given role. For
* instance, If the <code>ComponentManager</code> had a
* <code>LoggerComponent</code> stored and referenced by role, I would use
* the following call:
* <pre>
* try {
* LoggerComponent log;
* log = (LoggerComponent)
manager.lookup("org.apache.avalon.blocks.Logger");
* } catch (...) {
* ...
* }
* </pre>
*
* @param name The role name of the <code>Component</code> to retrieve.
*
* @exception ComponentNotFoundException If the given role is not
associated
* with a <code>Component</code>.
* @exception ComponentNotAccessibleException If a <code>Component</code>
* instance cannot be created.
*/
Component lookup( String role )
throws ComponentManagerException, ComponentNotFoundException,
ComponentNotAccessibleException;
/**
* Return the <code>Component</code> when you are finished with it. This
* allows the <code>ComponentManager</code> to handle the End-Of-Life
Lifecycle
* events associated with the Component. Please note, that no Exceptions
* should be thrown at this point. This is to allow easy use of the
* ComponentManager system without having to trap Exceptions on a release.
*
* @param component The Component we are releasing.
*/
void release(Component component);
}
1.1
jakarta-avalon/src/java/org/apache/avalon/ComponentManagerException.java
Index: ComponentManagerException.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;
/**
* This base class of exceptions thrown by ComponentManager.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
*/
public class ComponentManagerException
extends CascadingException
{
/**
* Construct a new <code>ComponentManagerException</code> instance.
*/
public ComponentManagerException( final String message, final Throwable
throwable )
{
super( message, throwable );
}
}
1.1
jakarta-avalon/src/java/org/apache/avalon/ComponentNotAccessibleException.java
Index: ComponentNotAccessibleException.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;
/**
* This exception is thrown by the <code>ComponentManager</code> when a
* <code>Component</code> cannot be accessed.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
*/
public class ComponentNotAccessibleException
extends ComponentManagerException
{
/**
* Construct a new <code>ComponentNotAccessibleException</code> instance.
*/
public ComponentNotAccessibleException( final String message )
{
this( message, null );
}
/**
* Construct a new <code>ComponentNotAccessibleException</code> instance.
*/
public ComponentNotAccessibleException( final String message, final
Throwable throwable )
{
super( message, throwable );
}
}
1.1
jakarta-avalon/src/java/org/apache/avalon/ComponentNotFoundException.java
Index: ComponentNotFoundException.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;
/**
* This exception is thrown by the <code>ComponentManager</code> when a
* <code>Component</code> cannot be found.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
*/
public final class ComponentNotFoundException
extends ComponentManagerException
{
/**
* Constructs the ComponentNotFoundException with an initial
* message.
*/
public ComponentNotFoundException( final String message )
{
this( message, null );
}
/**
* Constructs the ComponentNotFoundException with an initial
* message.
*/
public ComponentNotFoundException( final String message, final Throwable
throwable )
{
super( message, throwable );
}
}
1.1
jakarta-avalon/src/java/org/apache/avalon/ComponentSelector.java
Index: ComponentSelector.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;
/**
* A <code>ComponentSelector</code> selects <code>Component</code>s based on a
* hint. The contract is that all the <code>Component</code>s implement the
* same role.
*
* A role is better understood by the analogy of a play. There are many
* different roles in a script. Any actor or actress can play any given part
* and you get the same results (phrases said, movements made, etc.). The
exact
* nuances of the performance is different.
*
* Below is a list of things that might be considered the same role:
*
* <ul>
* <li> XMLInputAdaptor and PropertyInputAdaptor</li>
* <li> FileGenerator and SQLGenerator</li>
* </ul>
*
* The <code>ComponentSelector</code> does not specify the methodology of
* getting the <code>Component</code>, merely the interface used to get it.
* Therefore the <code>ComponentSelector</code> can be implemented with a
* factory pattern, an object pool, or a simple Hashtable.
*
* @see org.apache.avalon.Component
* @see org.apache.avalon.Composer
* @see org.apache.avalon.ComponentManager
*
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
*/
public interface ComponentSelector
extends Component
{
/**
* Select the <code>Component</code> associated with the given hint.
* For instance, If the <code>ComponentSelector</code> has a
* <code>Generator</code> stored and referenced by a URL, I would use the
* following call:
*
* <pre>
* try {
* Generator input;
* input = (Generator) selector.select(new URL("foo://demo/url"));
* } catch (...) {
* ...
* }
* </pre>
*
* @param name A hint to retrieve the correct <code>Component</code>.
*
* @exception ComponentNotFoundException If the given role is not
associated
* with a <code>Component</code>.
* @exception ComponentNotAccessibleException If a <code>Component</code>
* instance cannot be created.
*/
Component select( Object hint )
throws ComponentManagerException, ComponentNotFoundException,
ComponentNotAccessibleException;
/**
* Return the <code>Component</code> when you are finished with it. This
* allows the <code>ComponentManager</code> to handle the End-Of-Life
Lifecycle
* events associated with the Component. Please note, that no Exceptions
* should be thrown at this point. This is to allow easy use of the
* ComponentManager system without having to trap Exceptions on a release.
*
* @param component The Component we are releasing.
*/
void release(Component component);
}
1.1 jakarta-avalon/src/java/org/apache/avalon/Composer.java
Index: Composer.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;
/**
* A composer is a class that need to connect to software components using
* a "role" abstraction, thus not depending on particular implementations
* but on behavioral interfaces.
* <br />
*
* The contract surrounding a <code>Composer</code> is that it is a user.
* The <code>Composer</code> is able to use <code>Components</code> managed
* by the <code>ComponentManager</code> it was initialized with. As part
* of the contract with the system, the instantiating entity must call
* the <code>setComponenetManager</code> method before the
* <code>Composer</code> can be considered valid. The
* <code>setComponentManager</code> method must be called after the
constructor
* and before any user methods.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
*/
public interface Composer
{
/**
* Pass the <code>ComponentManager</code> to the <code>composer</code>.
* The <code>Composer</code> implementation should use the specified
* <code>ComponentManager</code> to acquire the components it needs for
* execution.
*
* @param manager The <code>ComponentManager</code> which this
* <code>Composer</code> uses.
*/
void compose( ComponentManager componentManager )
throws ComponentManagerException;
}
1.1
jakarta-avalon/src/java/org/apache/avalon/Configurable.java
Index: Configurable.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;
/**
* This interface should be implemented by classes that need to be
* configured with custom parameters before initialization.
* <br />
*
* The contract surrounding a <code>Configurable</code> is that the
* instantiating entity must call the <code>configure</code>
* method before it is valid. The <code>configure</code> method
* must be called after the constructor, and before any other method.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @deprecated This has been deprecated in favour of configuration interface
in org.apache.avalon.configuration interface
*/
public interface Configurable
{
/**
* Pass the <code>Configuration</code> to the <code>Configurable</code>
* class. This method must always be called after the constructor
* and before any other method.
*
* @param configuration the class configurations.
*/
void configure( Configuration configuration )
throws ConfigurationException;
}
1.1
jakarta-avalon/src/java/org/apache/avalon/Configuration.java
Index: Configuration.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;
import java.util.Iterator;
/**
* <code>Configuration</code> is a interface encapsulating a configuration
node
* used to retrieve configuration values. This is a "read only" interface
* preventing applications from modifying their own configurations.
* <br />
*
* The contract surrounding the <code>Configuration</code> is that once
* it is created, information never changes. The <code>Configuration</code>
* is built by the <code>SAXConfigurationBuilder</code> and the
* <code>ConfigurationImpl</code> helper classes.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @deprecated This has been deprecated in favour of configuration interface
in org.apache.avalon.configuration interface
*/
public interface Configuration
{
/**
* Return the name of the node.
*
* @post getName() != null
*
* @return name of the <code>Configuration</code> node.
*/
String getName();
/**
* Return a string describing location of Configuration.
* Location can be different for different mediums (ie "file:line" for
normal XML files or
* "table:primary-key" for DB based configurations);
*
* @return a string describing location of Configuration
*/
String getLocation();
/**
* Return a new <code>Configuration</code> instance encapsulating the
* specified child node.
*
* @pre child != null
* @post getConfiguration() != null
*
* @param child The name of the child node.
* @return Configuration
*/
Configuration getChild( String child );
/**
* Return an <code>Iterator</code> of <code>Configuration<code>
* elements containing all node children with the specified name.
*
* @pre name != null
* @post getConfigurations() != null
*
* @param name The name of the children to get.
* @return The child nodes with name
*/
Iterator getChildren( String name );
/**
* Return the value of specified attribute.
*
* @pre paramName != null
* @post getAttribute != null
*
* @param paramName The name of the parameter you ask the value of.
* @return String value of attribute.
* @exception ConfigurationException If no attribute with that name
exists.
*/
String getAttribute( String paramName ) throws ConfigurationException;
/**
* Return the <code>int</code> value of the specified attribute contained
* in this node.
*
* @pre paramName != null
* @post getAttributeAsInt() != null
*
* @param paramName The name of the parameter you ask the value of.
* @return int value of attribute
* @exception ConfigurationException If no parameter with that name
exists.
* or if conversion to <code>int</code>
fails.
*/
int getAttributeAsInt( String paramName ) throws ConfigurationException;
/**
* Returns the value of the attribute specified by its name as a
* <code>long</code>.
*
* @pre paramName != null
* @post getAttributeAsLong() != null
*
* @param paramName The name of the parameter you ask the value of.
* @return long value of attribute
* @exception ConfigurationException If no parameter with that name
exists.
* or if conversion to
<code>long</code> fails.
*/
long getAttributeAsLong( String name ) throws ConfigurationException;
/**
* Return the <code>float</code> value of the specified parameter
contained
* in this node.
*
* @pre paramName != null
* @post getAttributeAsFloat() != null
*
* @param paramName The name of the parameter you ask the value of.
* @return float value of attribute
* @exception ConfigurationException If no parameter with that name
exists.
* or if conversion to
<code>float</code> fails.
*/
float getAttributeAsFloat( String paramName ) throws
ConfigurationException;
/**
* Return the <code>boolean</code> value of the specified parameter
contained
* in this node.<br>
*
* @pre paramName != null
* @post getAttributeAsBoolean() != null
*
* @param paramName The name of the parameter you ask the value of.
* @return boolean value of attribute
* @exception ConfigurationException If no parameter with that name
exists.
* or if conversion to
<code>boolean</code> fails.
*/
boolean getAttributeAsBoolean( String paramName ) throws
ConfigurationException;
/**
* Return the <code>String</code> value of the node.
*
* @post getValue() != null
*
* @return the value of the node.
*/
String getValue() throws ConfigurationException;
/**
* Return the <code>int</code> value of the node.
*
* @post getValueAsInt() != null
*
* @returns the value of the node.
*
* @exception ConfigurationException If conversion to <code>int</code>
fails.
*/
int getValueAsInt() throws ConfigurationException;
/**
* Return the <code>float</code> value of the node.
*
* @post getValueAsFloat() != null
*
* @return the value of the node.
* @exception ConfigurationException If conversion to <code>float</code>
fails.
*/
float getValueAsFloat() throws ConfigurationException;
/**
* Return the <code>boolean</code> value of the node.
*
* @post getValueAsBoolean() != null
*
* @return the value of the node.
* @exception ConfigurationException If conversion to
<code>boolean</code> fails.
*/
boolean getValueAsBoolean() throws ConfigurationException;
/**
* Return the <code>long</code> value of the node.<br>
*
* @post getValueAsLong() != null
*
* @return the value of the node.
* @exception ConfigurationException If conversion to <code>long</code>
fails.
*/
long getValueAsLong() throws ConfigurationException;
/**
* Returns the value of the configuration element as a
<code>String</code>.
* If the configuration value is not set, the default value will be
* used.
*
* @pre defaultValue != null
* @post getValue(defaultValue) != null
*
* @param defaultValue The default value desired.
* @return String value of the <code>Configuration</code>, or default
* if none specified.
*/
String getValue( String defaultValue );
/**
* Returns the value of the configuration element as an <code>int</code>.
* If the configuration value is not set, the default value will be
* used.
*
* @pre defaultValue != null
* @post getValueAsInt(defaultValue) != null
*
* @param defaultValue The default value desired.
* @return int value of the <code>Configuration</code>, or default
* if none specified.
*/
int getValueAsInt( int defaultValue );
/**
* Returns the value of the configuration element as a <code>long</code>.
* If the configuration value is not set, the default value will be
* used.
*
* @pre defaultValue != null
* @post getValueAsLong(defaultValue) != null
*
* @param defaultValue The default value desired.
* @return long value of the <code>Configuration</code>, or default
* if none specified.
*/
long getValueAsLong( long defaultValue );
/**
* Returns the value of the configuration element as a <code>float</code>.
* If the configuration value is not set, the default value will be
* used.
*
* @pre defaultValue != null
* @post getValueAsFloat(defaultValue) != null
*
* @param defaultValue The default value desired.
* @return float value of the <code>Configuration</code>, or default
* if none specified.
*/
float getValueAsFloat( float defaultValue );
/**
* Returns the value of the configuration element as a
<code>boolean</code>.
* If the configuration value is not set, the default value will be
* used.
*
* @pre defaultValue != null
* @post getValueAsBoolean(defaultValue) != null
*
* @param defaultValue The default value desired.
* @return boolean value of the <code>Configuration</code>, or default
* if none specified.
*/
boolean getValueAsBoolean( boolean defaultValue );
/**
* Returns the value of the attribute specified by its name as a
* <code>String</code>, or the default value if no attribute by
* that name exists or is empty.
*
* @pre name != null
* @pre defaultValue != null
* @post getAttribute(name, defaultValue) != null
*
* @param name The name of the attribute you ask the value of.
* @param defaultValue The default value desired.
* @return String value of attribute. It will return the default
* value if the named attribute does not exist, or if
* the value is not set.
*/
String getAttribute( String name, String defaultValue );
/**
* Returns the value of the attribute specified by its name as a
* <code>int</code>, or the default value if no attribute by
* that name exists or is empty.
*
* @pre name != null
* @pre defaultValue != null
* @post getAttributeAsInt(name, defaultValue) != null
*
* @param name The name of the attribute you ask the value of.
* @param defaultValue The default value desired.
* @return int value of attribute. It will return the default
* value if the named attribute does not exist, or if
* the value is not set.
*/
int getAttributeAsInt( String name, int defaultValue );
/**
* Returns the value of the attribute specified by its name as a
* <code>long</code>, or the default value if no attribute by
* that name exists or is empty.
*
* @pre name != null
* @pre defaultValue != null
* @post getAttributeAsLong(name, defaultValue) != null
*
* @param name The name of the attribute you ask the value of.
* @param defaultValue The default value desired.
* @return long value of attribute. It will return the default
* value if the named attribute does not exist, or if
* the value is not set.
*/
long getAttributeAsLong( String name, long defaultValue );
/**
* Returns the value of the attribute specified by its name as a
* <code>float</code>, or the default value if no attribute by
* that name exists or is empty.
*
* @pre name != null
* @pre defaultValue != null
* @post getAttributeAsFloat(name, defaultValue) != null
*
* @param name The name of the attribute you ask the value of.
* @param defaultValue The default value desired.
* @return float value of attribute. It will return the default
* value if the named attribute does not exist, or if
* the value is not set.
*/
float getAttributeAsFloat( String name, float defaultValue );
/**
* Returns the value of the attribute specified by its name as a
* <code>boolean</code>, or the default value if no attribute by
* that name exists or is empty.
*
* @pre name != null
* @pre defaultValue != null
* @post getAttributeAsBoolean(name, defaultValue) != null
*
* @param name The name of the attribute you ask the value of.
* @param defaultValue The default value desired.
* @return boolean value of attribute. It will return the default
* value if the named attribute does not exist, or if
* the value is not set.
*/
boolean getAttributeAsBoolean( String name, boolean defaultValue );
}
1.1
jakarta-avalon/src/java/org/apache/avalon/ConfigurationBuilder.java
Index: ConfigurationBuilder.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;
import java.io.IOException;
import org.xml.sax.SAXException;
/**
* The interface implemented to build configurations.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @deprecated This has been deprecated in favour of configuration interface
in org.apache.avalon.configuration interface
*/
public interface ConfigurationBuilder
{
Configuration build( String resource )
throws SAXException, IOException, ConfigurationException;
}
1.1
jakarta-avalon/src/java/org/apache/avalon/ConfigurationException.java
Index: ConfigurationException.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;
/**
* Thrown when a <code>Configurable</code> component cannot be configured
* properly, or if a value cannot be retrieved properly.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
* @deprecated This has been deprecated in favour of configuration interface
in org.apache.avalon.configuration interface
*/
public final class ConfigurationException
extends CascadingException
{
/**
* Construct a new <code>ConfigurationException</code> instance.
*
* @param message The detail message for this exception.
*/
public ConfigurationException( final String message )
{
this( message, null );
}
/**
* Construct a new <code>ConfigurationException</code> instance.
*
* @param message The detail message for this exception.
* @param throwable the root cause of the exception
*/
public ConfigurationException( final String message, final Throwable
throwable )
{
super( message, throwable );
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/Context.java
Index: Context.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]">Federico Barbieri</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
*/
public interface Context
{
Object get( Object key );
}
1.1
jakarta-avalon/src/java/org/apache/avalon/Contextualizable.java
Index: Contextualizable.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;
/**
* This inteface should be implemented by classes that need
* a Context to work. Context contains runtime generated object
* provided by the parent to this class.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
*/
public interface Contextualizable
{
/**
* Pass the Context to the contextualizable class. This method
* is always called after the constructor and, if present,
* after configure but before any other method.
*
*/
void contextualize( Context context );
}
1.1
jakarta-avalon/src/java/org/apache/avalon/DefaultComponentManager.java
Index: DefaultComponentManager.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;
import java.util.HashMap;
import java.util.Iterator;
/**
* This class is a static implementation of a ComponentManager. Allow
ineritance
* and extention so you can generate a tree of ComponentManager each defining
* Component scope.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
*/
public class DefaultComponentManager
implements ComponentManager
{
protected final HashMap m_components = new HashMap();
protected final ComponentManager m_parent;
public DefaultComponentManager()
{
this( null );
}
public DefaultComponentManager( final ComponentManager parent )
{
m_parent = parent;
}
public Component lookup( final String role )
throws ComponentManagerException
{
final Component component = (Component)m_components.get( role );
if( null != component )
{
return component;
}
else if( null != m_parent )
{
return m_parent.lookup( role );
}
else
{
throw new ComponentNotFoundException("Unable to provide
implementation for " + role);
}
}
public void put( final String name, final Component component )
{
m_components.put( name, component );
}
public void release( final Component component )
{
// if the ComponentManager handled pooling, it would be
// returned to the pool here.
}
public String toString()
{
final StringBuffer buffer = new StringBuffer();
final Iterator components = m_components.keySet().iterator();
buffer.append( "Components:" );
while( components.hasNext() )
{
buffer.append( "[" );
buffer.append( components.next() );
buffer.append( "]" );
}
return buffer.toString();
}
}
1.1
jakarta-avalon/src/java/org/apache/avalon/DefaultComponentSelector.java
Index: DefaultComponentSelector.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;
import java.util.HashMap;
/**
* This is the default implementation of the ComponentSelector
*/
public class DefaultComponentSelector implements ComponentSelector {
protected final HashMap components = new HashMap();
public DefaultComponentSelector() {
// do nothing
}
/**
* Select the desired component. It does not cascade, neither
* should it.
*/
public Component select(Object hint)
throws ComponentNotFoundException,
ComponentNotAccessibleException {
final Component component = (Component) components.get(hint);
if ( component != null ) {
return component;
} else {
throw new ComponentNotFoundException("Unable to provide
implementation for " + hint.toString());
}
}
public void release( final Component component )
{
// if the ComponentManager handled pooling, it would be
// returned to the pool here.
}
/**
* Populate the ComponentSelector.
*/
public void put(final Object hint, final Component component) {
this.components.put(hint, component);
}
}
1.1
jakarta-avalon/src/java/org/apache/avalon/DefaultConfiguration.java
Index: DefaultConfiguration.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;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
/**
* This is the default <code>Configuration</code> implementation.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @deprecated This has been deprecated in favour of configuration interface
in org.apache.avalon.configuration interface
*/
public class DefaultConfiguration
extends AbstractConfiguration
{
protected final static Iterator EMPTY_ITERATOR = (new
ArrayList(1)).iterator();
protected final String m_name;
protected final String m_location;
protected HashMap m_attributes;
protected ArrayList m_children;
protected String m_value;
/**
* Create a new <code>DefaultConfiguration</code> instance.
*/
public DefaultConfiguration( final String name, final String location )
{
m_name = name;
m_location = location;
}
/**
* Returns the name of this configuration element.
*/
public String getName()
{
return m_name;
}
/**
* Returns a description of location of element.
*/
public String getLocation()
{
return m_location;
}
/**
* Returns the value of the configuration element as a
<code>String</code>.
*
* @exception ConfigurationException If the value is not present.
*/
public String getValue() throws ConfigurationException
{
if( null != m_value ) return m_value;
else
{
throw new ConfigurationException( "No value is associated with
the "+
"configuration element \"" +
getName() + "\"" );
}
}
/**
* Returns the value of the attribute specified by its name as a
* <code>String</code>.
*
* @exception ConfigurationException If the attribute is not present.
*/
public String getAttribute( final String name )
throws ConfigurationException
{
final String value =
(null != m_attributes) ? (String)m_attributes.get( name ) : null;
if( null != value ) return value;
else
{
throw new ConfigurationException( "No attribute named \"" + name
+ "\" is " +
"associated with the
configuration element \"" +
getName() + "\"" );
}
}
/**
* Return the first <code>Configuration</code> object child of this
* associated with the given name. If none exists a new one of that name
is created.
*
* @param name The name of the required child <code>Configuration</code>.
*/
public Configuration getChild( final String name )
{
if( null == m_children )
{
return new DefaultConfiguration( name, "-" );
}
else
{
final int size = m_children.size();
for( int i = 0; i < size; i++ )
{
final Configuration configuration =
(Configuration)m_children.get( i );
if( name.equals( configuration.getName() ) )
{
return configuration;
}
}
return new DefaultConfiguration( name, "-" );
}
}
/**
* Return an <code>Enumeration</code> of <code>Configuration</code>
objects
* children of this associated with the given name.
* <br>
* The returned <code>Enumeration</code> may be empty.
*
* @param name The name of the required children
<code>Configuration</code>.
*/
public Iterator getChildren( final String name )
{
if( null == m_children ) return EMPTY_ITERATOR;
else
{
final ArrayList children = new ArrayList();
final int size = m_children.size();
for( int i = 0; i < size; i++ )
{
final Configuration configuration =
(Configuration)m_children.get( i );
if( name.equals( configuration.getName() ) )
{
children.add( configuration );
}
}
return children.iterator();
}
}
/**
* Append data to the value of this configuration element.
*/
public void appendValueData( final String value )
{
if( null == m_value )
{
m_value = value;
}
else
{
m_value = m_value + value;
}
}
/**
* Add an attribute to this configuration element, returning its old
* value or <b>null</b>.
*/
public String addAttribute( final String name, String value )
{
if( null == m_attributes ) m_attributes = new HashMap();
return (String) m_attributes.put( name, value );
}
/**
* Add a child <code>Configuration</code> to this configuration element.
*/
public void addChild( final Configuration configuration )
{
if( null == m_children )
{
m_children = new ArrayList();
}
m_children.add( configuration );
}
/**
* Return count of children.
*/
public int getChildCount()
{
if( null == m_children )
{
return 0;
}
return m_children.size();
}
}
1.1
jakarta-avalon/src/java/org/apache/avalon/DefaultConfigurationBuilder.java
Index: DefaultConfigurationBuilder.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;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
/**
* A SAXConfigurationBuilder builds configurations via SAX2 compliant parser.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @deprecated This has been deprecated in favour of configuration interface
in org.apache.avalon.configuration interface
*/
public class DefaultConfigurationBuilder
implements ConfigurationBuilder
{
protected final static String DEFAULT_PARSER =
"org.apache.xerces.parsers.SAXParser";
protected final static String PARSER =
System.getProperty("org.xml.sax.parser", DEFAULT_PARSER );
protected SAXConfigurationHandler m_handler;
protected XMLReader m_parser;
public DefaultConfigurationBuilder()
{
this( PARSER );
}
public DefaultConfigurationBuilder( final String parserClass )
{
//yaya the bugs with some compilers and final variables ..
m_handler = getHandler();
try
{
m_parser = XMLReaderFactory.createXMLReader( parserClass );
//m_parser.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
m_parser.setContentHandler( m_handler );
m_parser.setErrorHandler( m_handler );
}
catch( final SAXException se )
{
throw new Error( "Unable to setup SAX parser" + se );
}
}
protected SAXConfigurationHandler getHandler()
{
return new SAXConfigurationHandler();
}
public Configuration build( final String resource )
throws SAXException, IOException, ConfigurationException
{
final InputStream input = new FileInputStream( resource );
try { return build( input ); }
finally
{
try { input.close(); }
catch( final IOException ioe ) {}
}
}
public Configuration build( final InputStream inputStream )
throws SAXException, IOException, ConfigurationException
{
final InputSource inputSource = new InputSource( inputStream );
return build( inputSource );
}
public Configuration build( final InputSource input )
throws SAXException, IOException, ConfigurationException
{
m_handler.clear();
m_parser.parse( input );
return m_handler.getConfiguration();
}
}
1.1
jakarta-avalon/src/java/org/apache/avalon/DefaultContext.java
Index: DefaultContext.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;
import java.util.Hashtable;
import java.util.Map;
/**
* Default implementation of Context.
* This implementation is a static hierarchial store.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
*/
public class DefaultContext
implements Context
{
protected final Map m_contextData;
protected final Context m_parent;
public DefaultContext( final Map contextData, final Context parent )
{
m_parent = parent;
m_contextData = contextData;
}
public DefaultContext( final Map contextData )
{
this( contextData, null );
}
public DefaultContext( final Context parent )
{
this( new Hashtable(), parent );
}
public DefaultContext()
{
this( (Context)null );
}
public Object get( final Object key )
{
final Object data = m_contextData.get( key );
if( null == m_parent || null != data )
{
return data;
}
return m_parent.get( key );
}
public void put( final Object key, final Object value )
{
m_contextData.put( key, value );
}
}
1.1
jakarta-avalon/src/java/org/apache/avalon/DefaultPipeline.java
Index: DefaultPipeline.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;
import java.util.ArrayList;
import java.util.NoSuchElementException;
/**
* This is basic array based pipeline.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
*/
public class DefaultPipeline
implements Pipeline
{
protected final ArrayList m_stages = new ArrayList();
/**
* Retrieve size of pipeline (number of stages).
*
* @return the size of pipeline
*/
public int getSize()
{
return m_stages.size();
}
/**
* Retrieve a particular stage of pipeline
*
* @param index the index of stage
* @return the stage
* @exception NoSuchElementException if index >= getSize() or index < 0
*/
public Stage getStage( final int index )
throws NoSuchElementException
{
return (Stage)m_stages.get( index );
}
public void addStage( final Stage stage )
{
m_stages.add( stage );
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/Disposable.java
Index: Disposable.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;
/**
* This interface should be implemented by those classes that
* need to provide a service that requires some resources to be
* initialized before being able to operate and properly destroyed
* before termination and unloading.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
*/
public interface Disposable
{
/**
* Destroys the service. This method is guaranteed to be called always
* after the stop() method if this class implements
<code>Stoppable</code>.
*/
void dispose()
throws Exception;
}
1.1
jakarta-avalon/src/java/org/apache/avalon/Initializable.java
Index: Initializable.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;
/**
* This interface should be implemented by those classes that
* need to provide a service that requires some resources to be
* initialized before being able to operate.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
*/
public interface Initializable
{
/**
* Initialize the service. This method is guaranteed to be called always
* after methods in <code>Configurable</code> and <code>Component</code>,
* if the class implements those interfaces and before the run() method
* if the class implements <code>Runnable</code>.
*/
void init()
throws Exception;
}
1.1 jakarta-avalon/src/java/org/apache/avalon/Loggable.java
Index: Loggable.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;
import org.apache.log.Logger;
/**
* Interface through which to provide Loggers.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
*/
public interface Loggable
{
void setLogger( Logger logger );
}
1.1 jakarta-avalon/src/java/org/apache/avalon/Modifiable.java
Index: Modifiable.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;
/**
* This interface is implemented by those classes that change
* their behavior/results over time (non-ergodic).
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
*/
public interface Modifiable
{
/**
* Queries the class to estimate its ergodic period termination.
* <br>
* This method is called to ensure the validity of a cached product. It
* is the class responsibility to provide the fastest possible
* implementation of this method or, whether this is not possible and the
* costs of the change evaluation is comparable to the production costs,
* to return <b>true</b> directly with no further delay, thus reducing
* the evaluation overhead to a minimum.
*
* @return <b>true</b> if the class ergodic period is over and the class
* would behave differently if processed again, <b>false</b> if
the
* resource is still ergodic so that it doesn't require
* reprocessing.
*/
boolean modifiedSince( long date );
}
1.1 jakarta-avalon/src/java/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;
import java.util.Iterator;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import org.apache.avalon.Configuration;
import org.apache.avalon.ConfigurationException;
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
*/
public final 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.
*/
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 Iterator parameters = configuration.getChildren("parameter");
final Parameters param = new Parameters();
while( parameters.hasNext() )
{
try {
final Configuration child =(Configuration) parameters.next();
final String name = child.getAttribute("name");
final String value = child.getAttribute("value");
param.setParameter( name, value );
} catch (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 (Exception e) {
throw new ConfigurationException("Cannot process
Configurable", e);
}
}
return param;
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/Pipeline.java
Index: Pipeline.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;
import java.util.NoSuchElementException;
/**
* This represents a pipeline made up of stages.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
*/
public interface Pipeline
extends Stage
{
/**
* Retrieve size of pipeline (number of stages).
*
* @return the size of pipeline
*/
int getSize();
/**
* Retrieve a particular stage of pipeline
*
* @param index the index of stage
* @return the stage
* @exception NoSuchElementException if index >= getSize() or index < 0
*/
Stage getStage( int index )
throws NoSuchElementException;
}
1.1 jakarta-avalon/src/java/org/apache/avalon/Poolable.java
Index: Poolable.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;
/**
* Poolable marker interface.
*
* Components implement this interface if it is reasonable to
* Pool the object. Components that don't implement this interface
* will be created anew via a factory.
*
* NB: It was a deliberat e choice not to extend Component. This will have to
* be reassed once we see it in action.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
*/
public interface Poolable
{
}
1.1
jakarta-avalon/src/java/org/apache/avalon/ProcessorPipeline.java
Index: ProcessorPipeline.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;
import java.util.Iterator;
/**
* This represents a pipeline made up of stages.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
*/
public class ProcessorPipeline
extends DefaultPipeline
implements ProcessorStage
{
public void process( final Object object )
{
final Iterator stages = m_stages.iterator();
while( stages.hasNext() )
{
((ProcessorStage)stages.next()).process( object );
}
}
public Stage getStage( final int index )
{
return (Stage)m_stages.get( index );
}
public int getSize()
{
return m_stages.size();
}
}
1.1
jakarta-avalon/src/java/org/apache/avalon/ProcessorStage.java
Index: ProcessorStage.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;
/**
* This represents a stage in a pipeline.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a>
*/
public interface ProcessorStage
extends Stage
{
void process( Object object );
}
1.1 jakarta-avalon/src/java/org/apache/avalon/Recomposer.java
Index: Recomposer.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;
/**
* Extends composer to allow recomposing.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
*/
public interface Recomposer
extends Composer
{
void recompose( ComponentManager componentManager )
throws ComponentNotAccessibleException, ComponentNotFoundException;
}
1.1
jakarta-avalon/src/java/org/apache/avalon/Reconfigurable.java
Index: Reconfigurable.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;
/**
* Extends Configurable to allow reconfiguration runtime.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @author <a href="http://java.apache.org/">Java Apache Project</a>
*/
public interface Reconfigurable
extends Configurable
{
void reconfigure( Configuration configuration ) throws
ConfigurationException;
}
1.1
jakarta-avalon/src/java/org/apache/avalon/Recontextualizable.java
Index: Recontextualizable.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;
/**
* Extends composer to allow recontextualizing.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
*/
public interface Recontextualizable
extends Composer
{
void recontextualizable( Context context ) ;
}
1.1 jakarta-avalon/src/java/org/apache/avalon/Recyclable.java
Index: Recyclable.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;
/**
* This interface standardizes the behaviour of a recyclable object.
* A recyclable object is defined as an object that can be used to
* encapsulate another object without being altered by its content.
* Therefore, a recyclable object may be recycled and reused many times.
*
* This is helpful in cases where recyclable objects are continously
* created and destroied, causing a much greater amount of garbage to
* be collected by the JVM garbage collector. By making it recyclable,
* it is possible to reduce the GC execution time thus incrementing the
* overall performance of a process and decrementing the chance of
* memory overflow.
*
* Every implementation must provide their own method to allow this
* recyclable object to be reused by setting its content.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
*/
public interface Recyclable
extends Poolable
{
/**
* This method should be implemented to remove all costly resources
* in object. These resources can be object references, database
connections,
* threads etc. What is categorised as "costly" resources is determined on
* a case by case analysis.
*/
void recycle();
}
1.1 jakarta-avalon/src/java/org/apache/avalon/Resolvable.java
Index: Resolvable.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;
/**
* This interface is used to indicate objects that need to be
* resolved in some particular context.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
*/
public interface Resolvable
{
/**
* Resolve a object to a value.
*
* @param context the contextwith respect which to resolve
* @return the resolved object
*/
Object resolve( Context context );
}
1.1 jakarta-avalon/src/java/org/apache/avalon/Resumable.java
Index: Resumable.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;
/**
* This is used to restart execturion after temporarily halt.
* The halt may have been for some re- configuring|composing|contextualizing
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
*/
public interface Resumable
{
/**
* Resumes the component.
*/
void resume();
}
1.1
jakarta-avalon/src/java/org/apache/avalon/SAXConfigurationHandler.java
Index: SAXConfigurationHandler.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;
import java.io.IOException;
import java.util.ArrayList;
import org.xml.sax.Attributes;
import org.xml.sax.ErrorHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
/**
* A SAXConfigurationHandler helps build Configurations out of sax events.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @deprecated This has been deprecated in favour of configuration interface
in org.apache.avalon.configuration interface
*/
public class SAXConfigurationHandler
extends DefaultHandler
implements ErrorHandler
{
protected final ArrayList m_elements = new
ArrayList();
protected Configuration m_configuration;
protected Locator m_locator;
public Configuration getConfiguration()
{
return m_configuration;
}
public void clear()
{
m_elements.clear();
m_locator = null;
}
public void setDocumentLocator( final Locator locator )
{
m_locator = locator;
}
public void characters( final char[] ch, int start, int end )
throws SAXException
{
final String value = (new String( ch, start, end )).trim();
if( value.equals( "" ) ) return;
final DefaultConfiguration configuration =
(DefaultConfiguration)m_elements.get( m_elements.size() - 1 );
if( 0 != configuration.getChildCount() )
{
throw new SAXException( "Not allowed to define mixed content in
the " +
"element " + configuration.getName() + "
at " +
configuration.getLocation() );
}
configuration.appendValueData( value );
}
public void endElement( final String namespaceURI,
final String localName,
final String rawName )
{
final int location = m_elements.size() - 1;
final Object object = m_elements.remove( location );
if( 0 == location )
{
m_configuration = (Configuration)object;
}
}
protected DefaultConfiguration createConfiguration( final String
localName,
final String location
)
{
return new DefaultConfiguration( localName, location );
}
public void startElement( final String namespaceURI,
final String localName,
final String rawName,
final Attributes attributes )
throws SAXException
{
final DefaultConfiguration configuration =
createConfiguration( localName, getLocationString() );
final int size = m_elements.size() - 1;
if( size > -1 )
{
final DefaultConfiguration parent =
(DefaultConfiguration)m_elements.get( size );
if( null != parent.getValue( null ) )
{
throw new SAXException( "Not allowed to define mixed content
in the " +
"element " + parent.getName() + " at
" +
parent.getLocation() );
}
parent.addChild( configuration );
}
m_elements.add( configuration );
final int attributesSize = attributes.getLength();
for( int i = 0; i < attributesSize; i++ )
{
final String name = attributes.getQName( i );
final String value = attributes.getValue( i );
configuration.addAttribute( name, value );
}
}
/**
* This just throws an exception on a parse error.
*/
public void error( final SAXParseException exception )
throws SAXException
{
throw exception;
}
/**
* This just throws an exception on a parse error.
*/
public void warning( final SAXParseException exception )
throws SAXException
{
throw exception;
}
/**
* This just throws an exception on a parse error.
*/
public void fatalError( final SAXParseException exception )
throws SAXException
{
throw exception;
}
protected String getLocationString()
{
if( null == m_locator ) return "Unknown";
else
{
return
m_locator.getSystemId() + ":" +
m_locator.getLineNumber() + ":" +
m_locator.getColumnNumber();
}
}
}
1.1
jakarta-avalon/src/java/org/apache/avalon/SingleThreaded.java
Index: SingleThreaded.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;
/**
* A interface to mark a component as not ThreadSafe.
*
* NB: It was a deliberat e choice not to extend Component. This will have to
* be reassed once we see it in action.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
*/
public interface SingleThreaded
{
}
1.1 jakarta-avalon/src/java/org/apache/avalon/Stage.java
Index: Stage.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;
/**
* This represents a stage in a pipeline.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a>
*/
public interface Stage
extends Component
{
}
1.1 jakarta-avalon/src/java/org/apache/avalon/Startable.java
Index: Startable.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;
/**
* This interface is the dual interface of Stoppable.
*
* It provides a method through which components can be "started"
* without requiring a thread. Useful for reactive or passive objects.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
*/
public interface Startable
{
/**
* Starts the component.
*/
void start()
throws Exception;
}
1.1 jakarta-avalon/src/java/org/apache/avalon/Stoppable.java
Index: Stoppable.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;
/**
* This interface is the dual interface of the <code>java.lang.Runnable</code>
* interface and provides a hook to safely stop the thread of execution.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
*/
public interface Stoppable
{
/**
* Stops the current thread of execution.
*/
void stop()
throws Exception;
}
1.1
jakarta-avalon/src/java/org/apache/avalon/Suspendable.java
Index: Suspendable.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;
/**
* This is used to temporarily halt execution of a component.
* The execution may be halted so that you can reconfigure/
* recompose/recontextualize component
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
*/
public interface Suspendable
{
/**
* Suspends the component.
*/
void suspend();
}
1.1 jakarta-avalon/src/java/org/apache/avalon/ThreadSafe.java
Index: ThreadSafe.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;
/**
* A interface to mark a component as ThreadSafe or reentrant.
*
* NB: It was a deliberat e choice not to extend Component. This will have to
* be reassed once we see it in action.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
*/
public interface ThreadSafe
{
}