diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/factorys/ExecManagerFactory.java b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/factorys/ExecManagerFactory.java new file mode 100644 index 000000000..6cac7e1f6 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/factorys/ExecManagerFactory.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) The Apache Software Foundation. All rights reserved. + * + * This software is published under the terms of the Apache Software License + * version 1.1, a copy of which has been included with this distribution in + * the LICENSE.txt file. + */ +package org.apache.myrmidon.framework.factorys; + +import java.io.File; +import org.apache.aut.nativelib.ExecException; +import org.apache.aut.nativelib.impl.DefaultExecManager; +import org.apache.avalon.excalibur.i18n.ResourceManager; +import org.apache.avalon.excalibur.i18n.Resources; +import org.apache.myrmidon.services.ServiceException; +import org.apache.myrmidon.services.ServiceFactory; + +/** + * A Factory responsible for creating the ExecManager service. + * + * @author Peter Donald + * @version $Revision$ $Date$ + */ +public class ExecManagerFactory + implements ServiceFactory +{ + private static final Resources REZ = + ResourceManager.getPackageResources( ExecManagerFactory.class ); + + /** + * Create the ExecManager Service. + */ + public Object createService() + throws ServiceException + { + final File home = getHomeDirectory(); + try + { + return new DefaultExecManager( home ); + } + catch( final ExecException ee ) + { + throw new ServiceException( ee.getMessage(), ee ); + } + } + + /** + * Utility method to retrieve home directory. + */ + private static File getHomeDirectory() + throws ServiceException + { + final String home = System.getProperty( "myrmidon.home" ); + if( null == home ) + { + final String message = REZ.getString( "missing-home-dir.error" ); + throw new ServiceException( message ); + } + + return new File( home ); + } +} diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/factorys/Resources.properties b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/factorys/Resources.properties new file mode 100644 index 000000000..275097c8f --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/factorys/Resources.properties @@ -0,0 +1 @@ +missing-home-dir.error=Cannot locate antRun scripts: Property 'myrmidon.home' not specified \ No newline at end of file diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/services/ServiceException.java b/proposal/myrmidon/src/java/org/apache/myrmidon/services/ServiceException.java new file mode 100644 index 000000000..11c6e0364 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/services/ServiceException.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) The Apache Software Foundation. All rights reserved. + * + * This software is published under the terms of the Apache Software License + * version 1.1, a copy of which has been included with this distribution in + * the LICENSE.txt file. + */ +package org.apache.myrmidon.services; + +import org.apache.avalon.framework.CascadingException; + +/** + * ServiceException thrown when a service can not be created for + * some reason. + * + * @author Peter Donald + */ +public class ServiceException + extends CascadingException +{ + /** + * Basic constructor for exception that does not specify a message + */ + public ServiceException() + { + this( "", null ); + } + + /** + * Basic constructor with a message + * + * @param message the message + */ + public ServiceException( final String message ) + { + this( message, null ); + } + + /** + * Constructor that builds cascade so that other exception information can be retained. + * + * @param message the message + * @param throwable the throwable + */ + public ServiceException( final String message, final Throwable throwable ) + { + super( message, throwable ); + } +} + diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/services/ServiceFactory.java b/proposal/myrmidon/src/java/org/apache/myrmidon/services/ServiceFactory.java new file mode 100644 index 000000000..8fd15ac44 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/services/ServiceFactory.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) The Apache Software Foundation. All rights reserved. + * + * This software is published under the terms of the Apache Software License + * version 1.1, a copy of which has been included with this distribution in + * the LICENSE.txt file. + */ +package org.apache.myrmidon.services; + +/** + * A ServiceFactory is used to create a service for use in the + * Myrmidon runtime. The factory is responsible for creating and + * preparing the service for use. + * + * @author Peter Donald + * @version $Revision$ $Date$ + */ +public interface ServiceFactory +{ + /** + * Create a service that coresponds to this factory. + * This method is usually called after the factory has been + * prepared and configured as appropriate. + */ + Object createService() + throws ServiceException; +} diff --git a/proposal/myrmidon/src/manifest/core-services.xml b/proposal/myrmidon/src/manifest/core-services.xml new file mode 100644 index 000000000..9cc54aefd --- /dev/null +++ b/proposal/myrmidon/src/manifest/core-services.xml @@ -0,0 +1,4 @@ + + + \ No newline at end of file