You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by do...@apache.org on 2001/04/16 10:23:23 UTC
cvs commit: jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/blocks DefaultBlockDeployer.java
donaldp 01/04/16 01:23:23
Modified: src/java/org/apache/phoenix/engine DefaultSarDeployer.java
src/java/org/apache/phoenix/engine/blocks
DefaultBlockDeployer.java
Log:
Altered Deployers to directly extend AbstractDeployer rather than subclasses. The sub-classes did not offer significant extra functionality.
Revision Changes Path
1.9 +54 -26 jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/DefaultSarDeployer.java
Index: DefaultSarDeployer.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/DefaultSarDeployer.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- DefaultSarDeployer.java 2001/04/15 13:29:17 1.8
+++ DefaultSarDeployer.java 2001/04/16 08:23:23 1.9
@@ -22,12 +22,15 @@
import org.apache.avalon.ComponentManager;
import org.apache.avalon.ComponentManagerException;
import org.apache.avalon.Composer;
+import org.apache.avalon.Composer;
import org.apache.avalon.DefaultComponentManager;
import org.apache.avalon.DefaultContext;
import org.apache.avalon.atlantis.Application;
import org.apache.avalon.atlantis.Kernel;
-import org.apache.avalon.camelot.AbstractCamelotDeployer;
+import org.apache.avalon.camelot.AbstractDeployer;
import org.apache.avalon.camelot.CamelotUtil;
+import org.apache.avalon.camelot.Container;
+import org.apache.avalon.camelot.Info;
import org.apache.avalon.camelot.ContainerException;
import org.apache.avalon.camelot.DefaultRegistry;
import org.apache.avalon.camelot.Deployer;
@@ -53,20 +56,34 @@
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public class DefaultSarDeployer
- extends AbstractCamelotDeployer
+ extends AbstractDeployer
+ implements Composer
{
protected File m_deployDirectory;
+ protected Container m_container;
/**
* Default constructor.
*/
public DefaultSarDeployer()
{
- m_deployToContainer = true;
m_autoUndeploy = true;
m_type = "Sar";
}
+ /**
+ * Retrieve relevent services needed to deploy.
+ *
+ * @param componentManager the ComponentManager
+ * @exception ComponentManagerException if an error occurs
+ */
+ public void compose( final ComponentManager componentManager )
+ throws ComponentManagerException
+ {
+ m_container = (Container)componentManager.
+ lookup( "org.apache.avalon.camelot.Container" );
+ }
+
protected void deployFromFile( final String name, final File file )
throws DeploymentException
{
@@ -181,14 +198,6 @@
context.put( SarContextResources.APP_NAME, name );
entry.setContext( context );
- //setup the ServerApplications component manager
- final DefaultComponentManager componentManager = new DefaultComponentManager();
- componentManager.put( "org.apache.avalon.camelot.Registry",
- new DefaultRegistry( BlockInfo.class ) );
- componentManager.put( "org.apache.avalon.camelot.Registry/Locator",
- new DefaultRegistry( Locator.class ) );
- entry.setComponentManager( componentManager );
-
//setup the ServerApplications configuration manager
final File file = new File( directory, "conf" + File.separator + "server.xml" );
final Configuration configuration = getConfigurationFor( file );
@@ -219,7 +228,12 @@
}
//rework next bit so it grabs deployments from archive
- final Deployer deployer = getBlockDeployer( entry );
+
+ //Registry that stores locators and infos for blocks
+ final Registry registry = new DefaultRegistry( Info.class );
+
+ final Deployer deployer = getBlockDeployer( entry, registry );
+
final File blocksDirectory = new File( directory, "blocks" );
CamelotUtil.deployFromDirectory( deployer, blocksDirectory, ".bar" );
@@ -230,7 +244,7 @@
{
final Configuration configuration = getConfigurationFor( file );
final Configuration[] blocks = configuration.getChildren( "block" );
- handleBlocks( application, entry, blocks );
+ handleBlocks( application, entry, blocks, registry );
}
catch( final ComponentManagerException cme )
{
@@ -242,6 +256,21 @@
}
}
+ protected void addEntry( final String name, final ServerApplicationEntry entry )
+ throws DeploymentException
+ {
+ try
+ {
+ m_container.add( name, entry );
+ }
+ catch( final ContainerException ce )
+ {
+ throw new DeploymentException( "Error adding component to container", ce );
+ }
+
+ getLogger().debug( "Adding " + m_type + "Entry " + name + " as " + entry );
+ }
+
protected Configuration getConfigurationFor( final File file )
throws DeploymentException
{
@@ -256,7 +285,7 @@
}
}
- protected Deployer getBlockDeployer( final ServerApplicationEntry entry )
+ protected Deployer getBlockDeployer( final ServerApplicationEntry entry, final Registry registry )
throws DeploymentException
{
final Deployer deployer = new DefaultBlockDeployer();
@@ -264,7 +293,13 @@
if( deployer instanceof Composer )
{
- try { ((Composer)deployer).compose( entry.getComponentManager() ); }
+ final DefaultComponentManager componentManager = new DefaultComponentManager();
+ componentManager.put( "org.apache.avalon.camelot.Registry", registry );
+
+ try
+ {
+ ((Composer)deployer).compose( componentManager );
+ }
catch( final Exception e )
{
throw new DeploymentException( "Error composing block deployer", e );
@@ -276,17 +311,10 @@
protected void handleBlocks( final Application application,
final ServerApplicationEntry saEntry,
- final Configuration[] blocks )
+ final Configuration[] blocks,
+ final Registry registry )
throws ComponentManagerException, ConfigurationException, DeploymentException
{
- final ComponentManager componentManager = saEntry.getComponentManager();
-
- final Registry infoRegistry =
- (Registry)componentManager.lookup( "org.apache.avalon.camelot.Registry" );
-
- final Registry locatorRegistry = (Registry)componentManager.
- lookup( "org.apache.avalon.camelot.Registry/Locator" );
-
for( int i = 0; i < blocks.length; i++ )
{
final Configuration block = blocks[ i ];
@@ -295,7 +323,7 @@
BlockInfo info = null;
- try { info = (BlockInfo)infoRegistry.getInfo( className, BlockInfo.class ); }
+ try { info = (BlockInfo)registry.getInfo( className, BlockInfo.class ); }
catch( final RegistryException re )
{
throw new DeploymentException( "Failed to aquire BlockInfo for " + className,
@@ -303,7 +331,7 @@
}
Locator locator = null;
- try { locator = (Locator)locatorRegistry.getInfo( className, Locator.class ); }
+ try { locator = (Locator)registry.getInfo( className + "/Locator", Locator.class ); }
catch( final RegistryException re )
{
throw new DeploymentException( "Failed to aquire Locator for " + className,
1.3 +81 -17 jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/blocks/DefaultBlockDeployer.java
Index: DefaultBlockDeployer.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/blocks/DefaultBlockDeployer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultBlockDeployer.java 2001/04/02 09:10:57 1.2
+++ DefaultBlockDeployer.java 2001/04/16 08:23:23 1.3
@@ -8,31 +8,40 @@
package org.apache.phoenix.engine.blocks;
import java.io.IOException;
+import java.io.File;
import java.io.InputStream;
import java.net.URL;
+import java.net.MalformedURLException;
import java.util.Iterator;
import java.util.Map;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import java.util.zip.ZipFile;
-import org.apache.avalon.camelot.AbstractZipDeployer;
+import org.apache.avalon.camelot.AbstractDeployer;
import org.apache.avalon.camelot.DeployerUtil;
import org.apache.avalon.camelot.DeploymentException;
+import org.apache.avalon.camelot.DefaultLocator;
import org.apache.avalon.camelot.Registry;
import org.apache.avalon.camelot.RegistryException;
import org.apache.avalon.util.io.IOUtil;
import org.apache.phoenix.metainfo.BlockInfo;
import org.apache.phoenix.metainfo.BlockInfoBuilder;
+import org.apache.avalon.ComponentManager;
+import org.apache.avalon.ComponentManagerException;
+import org.apache.avalon.Composer;
/**
* This class deploys a .bar file into a registry.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
-public class DefaultBlockDeployer
- extends AbstractZipDeployer
+public final class DefaultBlockDeployer
+ extends AbstractDeployer
+ implements Composer
{
- protected BlockInfoBuilder m_builder;
+ private Registry m_registry;
+ private BlockInfoBuilder m_builder;
+
/**
* Default constructor.
@@ -40,29 +49,55 @@
public DefaultBlockDeployer()
{
m_builder = new BlockInfoBuilder();
-
- //Indicate that this deployer should deploy to respective types
- m_deployToLocatorRegistry = true;
- m_deployToInfoRegistry = true;
-
m_autoUndeploy = true;
m_type = "Block";
}
+ /**
+ * Retrieve relevent services needed to deploy.
+ *
+ * @param componentManager the ComponentManager
+ * @exception ComponentManagerException if an error occurs
+ */
+ public void compose( final ComponentManager componentManager )
+ throws ComponentManagerException
+ {
+ m_registry = (Registry)componentManager.
+ lookup( "org.apache.avalon.camelot.Registry" );
+ }
+
/**
- * Load resources from jar required to deploy file.
+ * Deploy a file.
+ * Eventually this should be cached for performance reasons.
*
- * @param zipFile the zipFile
- * @param location the location deploying to
- * @param url the URL
+ * @param location the location
+ * @param file the file
* @exception DeploymentException if an error occurs
*/
- protected void loadResources( final ZipFile zipFile, final String location, final URL url )
+ protected void deployFromFile( final String location, final File file )
throws DeploymentException
{
- handleBlocks( zipFile, DeployerUtil.loadManifest( zipFile ), url );
- }
-
+ final ZipFile zipFile = DeployerUtil.getZipFileFor( file );
+
+ URL url = null;
+
+ try
+ {
+ try { url = file.toURL(); }
+ catch( final MalformedURLException mue )
+ {
+ throw new DeploymentException( "Unable to form url", mue );
+ }
+
+ handleBlocks( zipFile, DeployerUtil.loadManifest( zipFile ), url );
+ }
+ finally
+ {
+ try { zipFile.close(); }
+ catch( final IOException ioe ) {}
+ }
+ }
+
/**
* Create and register Infos for all blocks stored in deployment.
*
@@ -137,5 +172,34 @@
{
IOUtil.shutdownStream( inputStream );
}
+ }
+
+
+ protected void addLocator( final String name, final String classname, final URL url )
+ throws DeploymentException
+ {
+ final DefaultLocator locator = new DefaultLocator( classname, url );
+
+ try { m_registry.register( name + "/Locator", locator ); }
+ catch( final RegistryException re )
+ {
+ throw new DeploymentException( "Error registering " + name + " due to " + re,
+ re );
+ }
+
+ getLogger().debug( "Registered Locator for " + m_type + " " + name + " as " + classname );
+ }
+
+ protected void addInfo( final String name, final BlockInfo info )
+ throws DeploymentException
+ {
+ try { m_registry.register( name, info ); }
+ catch( final RegistryException re )
+ {
+ throw new DeploymentException( "Error registering " + name + " due to " + re,
+ re );
+ }
+
+ getLogger().debug( "Registered Info " + m_type + " " + name );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org