You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2003/06/24 22:50:19 UTC
cvs commit: avalon-sandbox/merlin/merlin-platform/tutorials/hello/src/java/tutorial HelloComponent.java
mcconnell 2003/06/24 13:50:19
Modified: merlin/assembly/src/java/org/apache/avalon/assembly/appliance/impl
DefaultAppliance.java
merlin/assembly/src/java/org/apache/avalon/assembly/lifestyle/impl
AbstractLifestyleHandler.java
PooledLifestyleHandler.java
SingletonLifestyleHandler.java
merlin/assembly/src/java/org/apache/avalon/assembly/locator/impl
DefaultLocator.java
merlin/assembly-spi/src/java/org/apache/avalon/assembly/lifestyle
LifestyleException.java
merlin/assembly-spi/src/java/org/apache/avalon/assembly/locator
Resolvable.java
merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl
StandardBlock.java
merlin/merlin-platform/tutorials/hello/src/java/tutorial
HelloComponent.java
Log:
Removed some exception that are not really adding value relative to the causal information.
Revision Changes Path
1.17 +7 -16 avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/appliance/impl/DefaultAppliance.java
Index: DefaultAppliance.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/appliance/impl/DefaultAppliance.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- DefaultAppliance.java 24 Jun 2003 16:04:49 -0000 1.16
+++ DefaultAppliance.java 24 Jun 2003 20:50:18 -0000 1.17
@@ -414,10 +414,10 @@
*
* @param source the context within the the resolution is applied
* @return the resolved object
- * @throws LocatorException if an error occurs
+ * @throws Exception if an error occurs
*/
public Object resolve( Object source )
- throws LocatorException
+ throws Exception
{
return resolve( source, null );
}
@@ -428,23 +428,14 @@
* @param source the context within the the resolution is applied
* @param ref the service reference
* @return the resolved object
- * @throws ContextException if an error occurs
+ * @throws Exception if an error occurs
*/
public Object resolve( Object source, String ref )
- throws LocatorException
+ throws Exception
{
if( !m_deployed )
{
- try
- {
- deploy();
- }
- catch( Throwable e )
- {
- final String error =
- "Internal implementation deployment failure in appliance: " + this;
- throw new LocatorException( error, e );
- }
+ deploy();
}
if( ref != null )
@@ -454,7 +445,7 @@
final String error =
"Requested service reference: " + ref
+ " is unknown within appliance: " + this;
- throw new LocatorException( ref, error );
+ throw new ApplianceException( error );
}
}
1.7 +19 -25 avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifestyle/impl/AbstractLifestyleHandler.java
Index: AbstractLifestyleHandler.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifestyle/impl/AbstractLifestyleHandler.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- AbstractLifestyleHandler.java 22 Jun 2003 00:27:30 -0000 1.6
+++ AbstractLifestyleHandler.java 24 Jun 2003 20:50:19 -0000 1.7
@@ -54,6 +54,7 @@
import org.apache.avalon.assembly.lifestyle.LifestyleHandler;
import org.apache.avalon.assembly.lifestyle.LifestyleException;
import org.apache.avalon.assembly.lifestyle.LifestyleRuntimeException;
+import org.apache.avalon.assembly.lifecycle.DeploymentException;
import org.apache.avalon.assembly.lifecycle.DeploymentService;
import org.apache.avalon.assembly.locator.Contextualizable;
import org.apache.avalon.assembly.locator.Locator;
@@ -170,12 +171,11 @@
* @param source the service consumer
* @param ref the reference descriptor
* @return the resolved object
- * @throws ContextException if an error occurs
+ * @throws Exception if an error occurs
* @todo build a proxy that isolates the service described by the
* ref argument
*/
- public Object resolve( Object source, String ref )
- throws LocatorException
+ public Object resolve( Object source, String ref ) throws Exception
{
return resolve( source );
}
@@ -183,9 +183,9 @@
/**
* Activate a service provided by the appliance.
* @param source the consumer
+ * @throws Exception if an error occurs
*/
- public abstract Object resolve( Object source )
- throws LocatorException;
+ public abstract Object resolve( Object source ) throws Exception;
/**
* Release an a service or handler established by the appliance. The
@@ -240,19 +240,9 @@
* appliance assigned to this handler.
* @return Object a new instance of the component class
*/
- protected Object newInstance() throws LifestyleException
+ protected Object newInstance() throws DeploymentException
{
- try
- {
- return m_deployment.deploy( m_appliance, m_classloader );
- }
- catch( Throwable e )
- {
- final String error =
- "Unable to create new instance for appliance: "
- + m_appliance;
- throw new LifestyleException( error, e );
- }
+ return m_deployment.deploy( m_appliance, m_classloader );
}
/**
@@ -260,7 +250,7 @@
* @param object the object to process
* @exception Exception if a stage procesing exception occurs
*/
- protected void processAccessStage( Object object ) throws LifestyleException, ContextException
+ protected void processAccessStage( Object object ) throws Exception
{
StageDescriptor[] phases = getAppliance().getType().getStages();
for( int i = 0; i < phases.length; i++ )
@@ -283,7 +273,8 @@
try
{
processExtension( stage, object, false );
- } catch( Throwable e )
+ }
+ catch( Throwable e )
{
if( getLogger().isWarnEnabled() )
{
@@ -307,8 +298,7 @@
private void processExtension(
StageDescriptor stage,
Object object,
- boolean access )
- throws LifestyleException, ContextException
+ boolean access ) throws Exception
{
Appliance provider = m_appliance.getExtensionProvider( stage );
if( provider == null )
@@ -320,6 +310,7 @@
}
Object handler = provider.resolve( this );
+
if ((handler != null) && (handler instanceof Accessor))
{
Accessor extension = (Accessor) handler;
@@ -329,12 +320,14 @@
if( access )
{
extension.access( object, context );
- } else
+ }
+ else
{
extension.release( object, context );
}
provider.release( extension, this );
- } catch( Throwable e )
+ }
+ catch( Throwable e )
{
final String error =
"Extension provider appliance: " + provider
@@ -351,7 +344,8 @@
{
String classname = m_appliance.getType().getInfo().getClassname();
return m_classloader.loadClass( classname );
- } catch( Throwable e )
+ }
+ catch( Throwable e )
{
final String error =
"Internal error while attempting to load the implementation class for an appliance: "
1.5 +8 -7 avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifestyle/impl/PooledLifestyleHandler.java
Index: PooledLifestyleHandler.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifestyle/impl/PooledLifestyleHandler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- PooledLifestyleHandler.java 22 Jun 2003 00:27:30 -0000 1.4
+++ PooledLifestyleHandler.java 24 Jun 2003 20:50:19 -0000 1.5
@@ -59,7 +59,7 @@
import org.apache.avalon.assembly.appliance.Appliance;
import org.apache.avalon.assembly.locator.Contextualizable;
import org.apache.avalon.assembly.locator.Locator;
-import org.apache.avalon.assembly.locator.LocatorException;
+import org.apache.avalon.assembly.lifecycle.DeploymentException;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.configuration.Configurable;
@@ -177,7 +177,7 @@
* Activate a service provided by the appliance.
* @param appliance the appliance to deploy
*/
- public Object resolve( Object partition ) throws LocatorException
+ public Object resolve( Object partition ) throws Exception
{
return access();
}
@@ -190,7 +190,7 @@
* @return an instance of the type defined by the profile
* @exception Exception if an error occurs while aquiring the object
*/
- private Object access() throws LocatorException
+ private Object access() throws Exception
{
try
{
@@ -212,7 +212,7 @@
{
final String error =
"Pooled object creation error.";
- throw new LocatorException( error, e );
+ throw new LifestyleException( error, e );
}
}
@@ -276,7 +276,7 @@
m_deployment.decommission( m_appliance, object );
}
- public Object newInstance() throws LifestyleException
+ public Object newInstance() throws DeploymentException
{
return super.newInstance();
}
@@ -295,7 +295,8 @@
try
{
((Disposable) m_pool).dispose();
- } catch( Throwable e )
+ }
+ catch( Throwable e )
{
// ignore
}
1.5 +8 -16 avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifestyle/impl/SingletonLifestyleHandler.java
Index: SingletonLifestyleHandler.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/lifestyle/impl/SingletonLifestyleHandler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SingletonLifestyleHandler.java 24 Jun 2003 16:04:49 -0000 1.4
+++ SingletonLifestyleHandler.java 24 Jun 2003 20:50:19 -0000 1.5
@@ -51,7 +51,7 @@
package org.apache.avalon.assembly.lifestyle.impl;
import org.apache.avalon.assembly.locator.LocatorException;
-import org.apache.avalon.assembly.lifestyle.LifestyleException;
+import org.apache.avalon.assembly.lifecycle.DeploymentException;
/**
* The singleton lifestyle handler provides support for object instantiation and
@@ -79,7 +79,7 @@
* Activate a service provided by the appliance.
* @param source the consumer
*/
- public Object resolve( Object source ) throws LocatorException
+ public Object resolve( Object source ) throws Exception
{
return access();
}
@@ -88,7 +88,7 @@
* Activate the implementation.
* @param appliance the appliance to deploy
*/
- private Object access() throws LocatorException
+ private Object access() throws Exception
{
if( getLogger().isDebugEnabled() )
{
@@ -97,17 +97,9 @@
getLogger().debug( debug );
}
- try
- {
- Object object = newInstance();
- super.processAccessStage( object );
- return object;
- }
- catch( Throwable e )
- {
- final String error = "Singleton object access failure in: " + getAppliance();
- throw new LocatorException( error, e );
- }
+ Object object = newInstance();
+ super.processAccessStage( object );
+ return object;
}
/**
@@ -143,7 +135,7 @@
* appliance assigned to this handler.
* @return Object a new instance of the component class
*/
- protected Object newInstance() throws LifestyleException
+ protected Object newInstance() throws DeploymentException
{
if( m_instance == null )
{
1.3 +32 -8 avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/locator/impl/DefaultLocator.java
Index: DefaultLocator.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/locator/impl/DefaultLocator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultLocator.java 8 May 2003 03:02:39 -0000 1.2
+++ DefaultLocator.java 24 Jun 2003 20:50:19 -0000 1.3
@@ -174,7 +174,8 @@
if( data == null )
{
m_data = new Hashtable();
- } else
+ }
+ else
{
m_data = data;
}
@@ -201,7 +202,8 @@
{
Object object = getObject( m_dictionary.translate( key ) );
return object != null;
- } catch( ContextException le )
+ }
+ catch( ContextException le )
{
return false;
}
@@ -269,11 +271,22 @@
if( data instanceof Reclaimable )
{
- Object object = ((Resolvable) data).resolve( this );
+ Object object = null;
+ try
+ {
+ object = ((Resolvable) data).resolve( this );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unable to resolve entry: " + key;
+ throw new LocatorException( key, error, e );
+ }
+
if( object == null )
{
final String error =
- "Unexpected state. Reclaimable source returned a null object reference.";
+ "Reclaimable source returned a null reference for key: " + key;
throw new IllegalStateException( error );
}
m_reclaimers.put( object, data );
@@ -282,14 +295,25 @@
if( data instanceof Resolvable )
{
- Object resolvable = ((Resolvable) data).resolve( this );
- if( resolvable == null )
+ Object object = null;
+ try
+ {
+ object = ((Resolvable) data).resolve( this );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unable to resolve entry: " + key;
+ throw new LocatorException( key, error, e );
+ }
+
+ if( object == null )
{
final String error =
- "Unexpected state. Resolvable source returned a null object reference.";
+ "Resolvable source returned a null reference for key: " + key;
throw new IllegalStateException( error );
}
- return resolvable;
+ return object;
}
return data;
1.2 +3 -3 avalon-sandbox/merlin/assembly-spi/src/java/org/apache/avalon/assembly/lifestyle/LifestyleException.java
Index: LifestyleException.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/assembly-spi/src/java/org/apache/avalon/assembly/lifestyle/LifestyleException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LifestyleException.java 20 Apr 2003 12:13:03 -0000 1.1
+++ LifestyleException.java 24 Jun 2003 20:50:19 -0000 1.2
@@ -50,7 +50,7 @@
package org.apache.avalon.assembly.lifestyle;
-import org.apache.avalon.framework.CascadingException;
+import org.apache.avalon.assembly.lifecycle.DeploymentException;
/**
* Exception to indicate that there was a lifestyle related error.
@@ -59,7 +59,7 @@
* @version $Revision$ $Date$
*/
public class LifestyleException
- extends CascadingException
+ extends DeploymentException
{
/**
1.6 +4 -6 avalon-sandbox/merlin/assembly-spi/src/java/org/apache/avalon/assembly/locator/Resolvable.java
Index: Resolvable.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/assembly-spi/src/java/org/apache/avalon/assembly/locator/Resolvable.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Resolvable.java 12 Jun 2003 18:56:21 -0000 1.5
+++ Resolvable.java 24 Jun 2003 20:50:19 -0000 1.6
@@ -69,10 +69,9 @@
*
* @param source the context within the the resolution is applied
* @return the resolved object
- * @throws ContextException if an error occurs
+ * @throws Exception if an error occurs
*/
- Object resolve( Object source )
- throws LocatorException;
+ Object resolve( Object source ) throws Exception;
/**
* Resolve a object to a value qualified by a supplied service reference.
@@ -80,8 +79,7 @@
* @param source the context within the the resolution is applied
* @param ref the service reference
* @return the resolved object
- * @throws ContextException if an error occurs
+ * @throws Exception if an error occurs
*/
- Object resolve( Object source, String ref )
- throws LocatorException;
+ Object resolve( Object source, String ref ) throws Exception;
}
1.15 +3 -13 avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl/StandardBlock.java
Index: StandardBlock.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl/StandardBlock.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- StandardBlock.java 24 Jun 2003 16:04:49 -0000 1.14
+++ StandardBlock.java 24 Jun 2003 20:50:19 -0000 1.15
@@ -300,8 +300,7 @@
* @return the resolved object
* @throws ContextException if an error occurs
*/
- public Object resolve( Object source, String ref )
- throws LocatorException
+ public Object resolve( Object source, String ref ) throws Exception
{
if( ref == null )
{
@@ -314,16 +313,7 @@
if( !m_deployed )
{
- try
- {
- deploy();
- }
- catch( Throwable e )
- {
- final String error =
- "Internal implementation deployment failure in block: " + this;
- throw new LocatorException( error, e );
- }
+ deploy();
}
//
@@ -354,7 +344,7 @@
{
final String error =
"Unable to resolve object for reference: " + ref;
- throw new LocatorException( ref, error, e );
+ throw new BlockException( error, e );
}
}
1.3 +48 -6 avalon-sandbox/merlin/merlin-platform/tutorials/hello/src/java/tutorial/HelloComponent.java
Index: HelloComponent.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/merlin-platform/tutorials/hello/src/java/tutorial/HelloComponent.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HelloComponent.java 18 Jun 2003 11:19:28 -0000 1.2
+++ HelloComponent.java 24 Jun 2003 20:50:19 -0000 1.3
@@ -1,21 +1,52 @@
package tutorial;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.logger.LogEnabled;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Executable;
import org.apache.avalon.framework.activity.Initializable;
-public class HelloComponent extends AbstractLogEnabled
- implements Initializable, Executable, Disposable
+/**
+ * A sample component. This component implements a number
+ * of lifecycle interface. Each lifecycle interface is a stage
+ * that is processed by a container during the deployment of
+ * the component. The lifecycle stages demonstrated here include
+ * LogEnabled (association of a logging channel), Initializable
+ * (initialization of the component), Executable (component
+ * execution), and Disposable (componet disposal).
+ *
+ * @avalon.meta.version 1.0
+ * @avalon.meta.name hello
+ */
+public class HelloComponent
+ implements LogEnabled, Initializable, Executable, Disposable
{
+
+ /**
+ * Internal reference to the logging channel supplied to us
+ * by the container.
+ */
+ private Logger m_logger;
+
+ /**
+ * Supply of a logging channel by the container.
+ *
+ * @param logger the logging channel for this component
+ */
+ public void enableLogging( final Logger logger )
+ {
+ m_logger = logger;
+ getLogger().info( "logging stage" );
+ }
+
/**
* Initialization of the component by the container.
* @exception Exception if an initialization error occurs
*/
public void initialize() throws Exception
{
- getLogger().info( "initialization stage executed." );
+ getLogger().info( "initialization stage" );
}
/**
@@ -24,7 +55,7 @@
*/
public void execute()
{
- getLogger().info( "execution stage." );
+ getLogger().info( "execution stage" );
}
/**
@@ -33,6 +64,17 @@
*/
public void dispose()
{
- getLogger().info( "disposal stage." );
+ getLogger().info( "disposal stage" );
+ m_logger = null;
}
+
+ /**
+ * Return the logging channel assigned to us by the container.
+ * @return the logging channel
+ */
+ private Logger getLogger()
+ {
+ return m_logger;
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org