@@ -10,19 +10,21 @@ package org.apache.myrmidon.libs.runtime;
import java.io.File;
import java.io.File;
import java.net.MalformedURLException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URL;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.myrmidon.api.AbstractTask;
import org.apache.myrmidon.api.AbstractTask;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.aspects.AspectHandler;
import org.apache.myrmidon.components.aspect.AspectManager;
import org.apache.myrmidon.components.aspect.AspectManager;
import org.apache.myrmidon.components.type.TypeFactory;
import org.apache.myrmidon.components.type.TypeException;
import org.apache.myrmidon.components.type.TypeException;
import org.apache.myrmidon.components.type.TypeFactory;
import org.apache.myrmidon.components.type.TypeManager;
import org.apache.myrmidon.components.type.TypeManager;
import org.apache.myrmidon.aspects.AspectHandler;
import org.apache.myrmidon.framework.AbstractContainerTask;
import org.apache.myrmidon.framework.AbstractContainerTask;
/**
/**
@@ -32,26 +34,30 @@ import org.apache.myrmidon.framework.AbstractContainerTask;
*/
*/
public class Facility
public class Facility
extends AbstractContainerTask
extends AbstractContainerTask
implements Composable, Configurable
implements Composable, Configurable
{
{
private static final Resources REZ =
ResourceManager.getPackageResources( Facility.class );
private String m_namespace;
private String m_namespace;
private AspectHandler m_aspectHandler;
private AspectHandler m_aspectHandler;
private AspectManager m_aspectManager;
private AspectManager m_aspectManager;
private TypeFactory m_factory;
private TypeFactory m_factory;
public void compose( final ComponentManager componentManager )
public void compose( final ComponentManager componentManager )
throws ComponentException
throws ComponentException
{
{
super.compose( componentManager );
super.compose( componentManager );
m_aspectManager = (AspectManager)componentManager.lookup( AspectManager.ROLE );
m_aspectManager = (AspectManager)componentManager.lookup( AspectManager.ROLE );
final TypeManager typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE );
final TypeManager typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE );
try { m_factory = typeManager.getFactory( AspectHandler.ROLE ); }
try { m_factory = typeManager.getFactory( AspectHandler.ROLE ); }
catch( final TypeException te )
catch( final TypeException te )
{
{
throw new ComponentException( "Unable to retrieve factory from TypeManager", te );
final String message = REZ.getString( "facility.no-factory.error" );
throw new ComponentException( message, te );
}
}
}
}
@@ -68,7 +74,7 @@ public class Facility
final Configuration[] children = configuration.getChildren();
final Configuration[] children = configuration.getChildren();
if( 1 == children.length )
if( 1 == children.length )
{
{
try
try
{
{
@@ -76,16 +82,17 @@ public class Facility
}
}
catch( final Exception e )
catch( final Exception e )
{
{
throw new ConfigurationException( "Failed to create aspect handler of type '" +
children[ 0 ].getName() + "'", e );
final String message =
REZ.getString( "facility.no-create.error", children[ 0 ].getName() );
throw new ConfigurationException( message, e );
}
}
configure( m_aspectHandler, children[ 0 ] );
configure( m_aspectHandler, children[ 0 ] );
}
}
else
else
{
{
throw new ConfigurationException( "Expected one sub-element to " +
"configure facility" );
final String message = REZ.getString( "facility.multi-element.error" );
throw new ConfigurationException( message );
}
}
}
}
@@ -99,7 +106,8 @@ public class Facility
{
{
if( null == m_namespace )
if( null == m_namespace )
{
{
throw new TaskException( "Must specify namespace parameter" );
final String message = REZ.getString( "facility.no-namespace.error" );
throw new TaskException( message );
}
}
m_aspectManager.addAspectHandler( m_namespace, m_aspectHandler );
m_aspectManager.addAspectHandler( m_namespace, m_aspectHandler );