Update of /cvsroot/plexus/plexus-container-new/src/java/org/apache/plexus
In directory eng.werken.com:/tmp/cvs-serv7788/src/java/org/apache/plexus
Modified Files:
DefaultPlexusContainer.java PlexusContainer.java
PlexusTestCase.java
Added Files:
PlexusContainerHost.java
Removed Files:
PlexusHost.java
Log Message:
o Clarifying name of the container host.
o Using the context as the source of values for the configuration resource
interpolation. As a result I cleaned up anything to do with configuration
variables as this is redundant given the existence of the context.
o Created a simple adapter so that a context can be used as a Map in the
InterpolationFilterReader.
o Added test cases for the ContextMapAdapter and the InterpolationFilterReader
using the adapter.
--- NEW FILE: PlexusContainerHost.java ---
package org.apache.plexus;
/* ----------------------------------------------------------------------------
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Plexus", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [email protected].
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ----------------------------------------------------------------------------
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ----------------------------------------------------------------------------
*/
import com.werken.classworlds.ClassWorld;
import java.io.File;
import java.io.FileReader;
/**
* A <code>ContainerHost</code>.
*
* @author <a href="mailto:[email protected]">Jason van Zyl</a>
* @author <a href="mailto:[email protected]">bob mcwhirter</a>
*
* @version $Id: PlexusContainerHost.java,v 1.1 2003/04/27 16:27:39 jvanzyl Exp $
*/
public class PlexusContainerHost
implements Runnable
{
private boolean shouldStop;
private boolean isStopped;
// ----------------------------------------------------------------------
// Constructors
// ----------------------------------------------------------------------
/**
* Constuctor.
*/
public PlexusContainerHost()
{
}
// ----------------------------------------------------------------------
// Implementation
// ----------------------------------------------------------------------
public void start( ClassWorld classWorld, String configurationResource )
throws Exception
{
PlexusContainer container = new DefaultPlexusContainer();
container.setClassWorld( classWorld );
container.setConfigurationResource( new FileReader( configurationResource ) );
container.addContextValue( "plexus.home",
new File( System.getProperty( "plexus.home" ) ) );
container.addContextValue( "plexus.work",
new File( System.getProperty( "plexus.home" ) + "/work" ) );
container.addContextValue( "plexus.logs",
new File( System.getProperty( "plexus.home" ) + "/logs" ) );
// Move this to the logging subsystem. And there might be a logging directory
// so we need better analsys as the container might be embedded.
File plexusLogs = new File( System.getProperty( "plexus.home" ) + "/logs" );
if ( plexusLogs.exists() == false )
{
plexusLogs.mkdirs();
}
container.initialize();
container.start();
Thread thread = new Thread( this );
thread.setDaemon( false );
Runtime.getRuntime().addShutdownHook( new Thread( new Runnable()
{
public void run()
{
try
{
shutdown();
}
catch ( Exception e )
{
// do nothing.
}
}
} ) );
thread.start();
}
/**
* Asynchronous hosting service loop.
*/
public void run()
{
synchronized ( this )
{
while ( !shouldStop )
{
try
{
wait();
}
catch ( InterruptedException e )
{
break;
}
}
}
synchronized ( this )
{
isStopped = true;
notifyAll();
}
}
// ----------------------------------------------------------------------
// Startup
// ----------------------------------------------------------------------
/**
* Shutdown this container.
*
* @throws java.lang.Exception If an error occurs while shutting down the container.
*/
public void shutdown()
throws Exception
{
synchronized ( this )
{
shouldStop = true;
notifyAll();
}
synchronized ( this )
{
while ( !isStopped )
{
try
{
wait();
}
catch ( InterruptedException e )
{
break;
}
}
}
}
/**
* Main entry-point.
*
* @param args Command-line arguments.
*/
public static void main( String[] args, ClassWorld classWorld )
{
if ( args.length != 1 )
{
System.err.println( "usage: plexus <plexus.conf>" );
System.exit( 1 );
}
try
{
PlexusContainerHost host = new PlexusContainerHost();
host.start( classWorld, args[0] );
}
catch ( Exception e )
{
e.printStackTrace();
System.exit( 2 );
}
}
}
Index: DefaultPlexusContainer.java
===================================================================
RCS file: /cvsroot/plexus/plexus-container-new/src/java/org/apache/plexus/DefaultPlexusContainer.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- DefaultPlexusContainer.java 25 Apr 2003 19:24:42 -0000 1.9
+++ DefaultPlexusContainer.java 27 Apr 2003 16:27:39 -0000 1.10
@@ -72,19 +72,13 @@
import org.apache.plexus.logging.log4j.Log4JLoggerManager;
import org.apache.plexus.service.repository.DefaultServiceRepository;
import org.apache.plexus.service.repository.ServiceRepository;
+import org.apache.plexus.util.ContextMapAdapter;
import org.apache.plexus.util.InterpolationFilterReader;
import org.xml.sax.InputSource;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
/** The main Plexus container component.
*
@@ -121,12 +115,6 @@
private Configuration configuration;
/**
- * These are values that are interpolated into the configuration stream
- * during container initialization.
- */
- private Map configurationVariables;
-
- /**
* The configuration reader which is ultimately used to read the
* configuration file.
*/
@@ -179,53 +167,6 @@
// --[ Configuration ]--
- /** @see PlexusContainer#setConfigurationResource(String) */
- public void setConfigurationResource( String configuration )
- throws ConfigurationResourceException
- {
- setConfigurationResource( new File( configuration ) );
- }
-
- /** @see PlexusContainer#setConfigurationResource(File) */
- public void setConfigurationResource( File configuration )
- throws ConfigurationResourceException
- {
- try
- {
- setConfigurationResource( new FileReader( configuration ) );
- }
- catch ( FileNotFoundException e )
- {
- throw new ConfigurationResourceException( e.getMessage() );
- }
- }
-
- /** @see PlexusContainer#setConfigurationResource(URL) */
- public void setConfigurationResource( URL configuration )
- throws ConfigurationResourceException
- {
- try
- {
- setConfigurationResource( configuration.openStream() );
- }
- catch ( IOException e )
- {
- throw new ConfigurationResourceException( e.getMessage() );
- }
- }
-
- /** @see PlexusContainer#setConfigurationResource(InputStream) */
- public void setConfigurationResource( InputStream configuration )
- throws ConfigurationResourceException
- {
- if ( configuration == null )
- {
- throw new ConfigurationResourceException( "The specified InputStream is null." );
- }
-
- setConfigurationReader( new InputStreamReader( configuration ) );
- }
-
/** @see PlexusContainer#setConfigurationResource(Reader) */
public void setConfigurationResource( Reader configuration )
throws ConfigurationResourceException
@@ -233,20 +174,6 @@
setConfigurationReader( configuration );
}
- /**
- * Sets the configurationVariables.
- * @param configurationVariables The configurationVariables to set
- */
- public void setConfigurationVariables( Map configurationVariables )
- {
- this.configurationVariables = configurationVariables;
- }
-
- public void addConfigurationVariable( String key, String value )
- {
- getConfigurationVariables().put( key, value );
- }
-
// --[ ResourceManager ]--
/**
@@ -319,12 +246,12 @@
throws Exception
{
initializeClassLoader();
+ initializeContext();
initializeDefaultConfiguration();
initializeConfiguration();
initializeLogging();
initializeResourceManager();
initializeServiceRepository();
- initializeContext();
initializeLifecycleHandler();
}
@@ -342,6 +269,16 @@
// Internal initialization methods
// ----------------------------------------------------------------------
+ /** Initialize the context.
+ *
+ */
+ protected void initializeContext()
+ {
+ // The resource manager is plexus specific and really shouldn't go into the context.
+ //addContextValue( PlexusConstants.RESOURCE_MANAGER_KEY, getResourceManager() );
+ addContextValue( PlexusConstants.COMMON_CLASSLOADER, getClassLoader() );
+ }
+
/** Initialize the configuration.
*
* @throws Exception
@@ -371,7 +308,8 @@
throws Exception
{
InterpolationFilterReader interpolationFilterReader =
- new InterpolationFilterReader( getConfigurationReader(), getConfigurationVariables() );
+ new InterpolationFilterReader( getConfigurationReader(),
+ new ContextMapAdapter( getContext() ) );
setConfiguration( builder.build( new InputSource( interpolationFilterReader ) ) );
}
@@ -448,15 +386,6 @@
getServiceRepository().initialize();
}
- /** Initialize the context.
- *
- */
- protected void initializeContext()
- {
- addContextValue( PlexusConstants.RESOURCE_MANAGER_KEY, getResourceManager() );
- addContextValue( PlexusConstants.COMMON_CLASSLOADER, getClassLoader() );
- }
-
/** Initialize the lifecycle handler.
*
*/
@@ -544,20 +473,6 @@
void setConfiguration( Configuration configuration )
{
this.configuration = configuration;
- }
-
- /**
- *
- * @return
- */
- Map getConfigurationVariables()
- {
- if ( configurationVariables == null )
- {
- configurationVariables = new HashMap();
- }
-
- return configurationVariables;
}
void setConfigurationReader( Reader configurationReader )
Index: PlexusContainer.java
===================================================================
RCS file: /cvsroot/plexus/plexus-container-new/src/java/org/apache/plexus/PlexusContainer.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- PlexusContainer.java 23 Apr 2003 03:57:12 -0000 1.4
+++ PlexusContainer.java 27 Apr 2003 16:27:39 -0000 1.5
@@ -12,11 +12,7 @@
import org.apache.plexus.lifecycle.LifecycleHandler;
import org.apache.plexus.service.repository.ServiceRepository;
-import java.io.File;
-import java.io.InputStream;
import java.io.Reader;
-import java.net.URL;
-import java.util.Map;
public interface PlexusContainer
{
@@ -24,12 +20,6 @@
void addContextValue( Object key, Object value );
/** */
- void setConfigurationVariables( Map variables );
-
- /** */
- void addConfigurationVariable( String key, String value );
-
- /** */
LifecycleHandler getLifecycleHandler();
/** */
@@ -40,38 +30,6 @@
/** */
void setClassLoader( ClassLoader classLoader );
-
- /**
- *
- * @param configuration
- * @throws ConfigurationResourceException
- */
- void setConfigurationResource( String configuration )
- throws ConfigurationResourceException;
-
- /**
- *
- * @param configuration
- * @throws ConfigurationResourceException
- */
- void setConfigurationResource( File configuration )
- throws ConfigurationResourceException;
-
- /**
- *
- * @param configuration
- * @throws ConfigurationResourceException
- */
- void setConfigurationResource( InputStream configuration )
- throws ConfigurationResourceException;
-
- /**
- *
- * @param configuration
- * @throws ConfigurationResourceException
- */
- void setConfigurationResource( URL configuration )
- throws ConfigurationResourceException;
/**
*
Index: PlexusTestCase.java
===================================================================
RCS file: /cvsroot/plexus/plexus-container-new/src/java/org/apache/plexus/PlexusTestCase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- PlexusTestCase.java 23 Apr 2003 03:57:12 -0000 1.2
+++ PlexusTestCase.java 27 Apr 2003 16:27:39 -0000 1.3
@@ -61,6 +61,7 @@
import java.io.File;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.net.URL;
public class PlexusTestCase
@@ -115,8 +116,8 @@
}
container = new DefaultPlexusContainer();
- container.addConfigurationVariable( "basedir", System.getProperty( "basedir" ) );
- container.setConfigurationResource( configuration );
+ container.addContextValue( "basedir", System.getProperty( "basedir" ) );
+ container.setConfigurationResource( new InputStreamReader( configuration ) );
container.initialize();
container.start();
}
--- PlexusHost.java DELETED ---
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.