CVS: plexus-container-new/src/java/org/apache/plexus/embed Embedder.java,1.2,1.3
[email protected] Sun, 25 May 2003 11:54:03 -0500
| Newsgroups | gmane.comp.java.plexus.devel |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/plexus/plexus-container-new/src/java/org/apache/plexus/embed
In directory eng.werken.com:/tmp/cvs-serv466
Modified Files:
Embedder.java
Log Message:
o removed an unused import
o reformat
o add a little snippet for cli use
Index: Embedder.java
===================================================================
RCS file: /cvsroot/plexus/plexus-container-new/src/java/org/apache/plexus/embed/Embedder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Embedder.java 25 May 2003 16:38:15 -0000 1.2
+++ Embedder.java 25 May 2003 16:54:00 -0000 1.3
@@ -2,12 +2,11 @@
import org.apache.plexus.DefaultPlexusContainer;
import org.apache.plexus.PlexusContainer;
-import org.apache.avalon.framework.configuration.Configuration;
-import java.io.InputStreamReader;
-import java.io.InputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
/**
* <tt>Embedder</tt> enables a client to embed Plexus into their
@@ -25,8 +24,21 @@
*
* embedder.stop();
* </pre>
+ * <p/>
+ * If you want to use the <tt>Embedder</tt> for CLI applications
+ * then you would use the following:
* <br/>
- *
+ * <pre>
+ * Embedder embedder = new Embedder();
+ * embedder.setConfiguration("/plexus.xml");
+ * embedder.addContextValue("plexus.home", ".");
+ * embedder.run();
+ * </pre>
+ * <p/>
+ * In this case it is assumed that in your plexus configuration that
+ * you have specified a component to load-on-start.
+ * <br/>
+ *
* @author <a href="mailto:[email protected]">Jason van Zyl</a>
* @author <a href="[email protected]">Pete Kazmier</a>
* @version $Id$
@@ -35,7 +47,7 @@
{
/** Configuration resource or file. */
private String configuration;
-
+
/** Plexus Container. */
private PlexusContainer container;
@@ -63,14 +75,14 @@
*/
public PlexusContainer getContainer()
{
- if (!embedderStarted)
+ if ( !embedderStarted )
{
- throw new IllegalStateException("Embedder must be started");
+ throw new IllegalStateException( "Embedder must be started" );
}
-
+
return container;
}
-
+
/**
* Set the configuration for the <tt>PlexusContainer</tt>. This
* configuration can either be a file or a resource in the
@@ -83,12 +95,12 @@
*/
public void setConfiguration( String configuration )
{
- if (embedderStarted || embedderStopped)
+ if ( embedderStarted || embedderStopped )
{
throw new IllegalStateException(
- "Embedder has already been started");
+ "Embedder has already been started" );
}
-
+
this.configuration = configuration;
}
@@ -102,10 +114,10 @@
*/
public void addContextValue( Object key, Object value )
{
- if (embedderStarted || embedderStopped)
+ if ( embedderStarted || embedderStopped )
{
throw new IllegalStateException(
- "Embedder has already been started");
+ "Embedder has already been started" );
}
container.addContextValue( key, value );
@@ -123,14 +135,14 @@
public void start()
throws Exception
{
- if (embedderStarted)
+ if ( embedderStarted )
{
- throw new IllegalStateException("Embedder already started");
+ throw new IllegalStateException( "Embedder already started" );
}
- if (embedderStopped)
+ if ( embedderStopped )
{
- throw new IllegalStateException("Embedder cannot be restarted");
+ throw new IllegalStateException( "Embedder cannot be restarted" );
}
container.setConfigurationResource(
@@ -151,21 +163,21 @@
public void stop()
throws Exception
{
- if (!embedderStarted)
+ if ( !embedderStarted )
{
- throw new IllegalStateException("Embedder not started");
+ throw new IllegalStateException( "Embedder not started" );
}
- if (embedderStopped)
+ if ( embedderStopped )
{
- throw new IllegalStateException("Embedder already stopped");
+ throw new IllegalStateException( "Embedder already stopped" );
}
container.dispose();
embedderStarted = false;
embedderStopped = true;
}
-
+
public void run()
throws Exception
{
@@ -175,8 +187,8 @@
private InputStream findConfigurationInputStream()
{
- InputStream is = getClass().getResourceAsStream(configuration);
-
+ InputStream is = getClass().getResourceAsStream( configuration );
+
if ( is == null )
{
try