donaldp 01/04/12 04:15:19 Modified: lib avalonapi.jar src/java/org/apache/cornerstone/blocks/datasource DefaultDataSourceSelector.java src/java/org/apache/cornerstone/blocks/masterstore AbstractFileRepository.java RepositoryManager.java src/java/org/apache/cornerstone/blocks/sockets DefaultSocketManager.java src/java/org/apache/cornerstone/demos/xcommander XCommanderServer.java src/java/org/apache/cornerstone/services/sockets SocketManager.java Log: Updated to work with ComponentException rathern than ComponentNot*Exception Revision Changes Path 1.9 +325 -225 jakarta-avalon-cornerstone/lib/avalonapi.jar <<Binary file>> 1.2 +4 -6 jakarta-avalon-cornerstone/src/java/org/apache/cornerstone/blocks/datasource/DefaultDataSourceSelector.java Index: DefaultDataSourceSelector.java =================================================================== RCS file: /home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/cornerstone/blocks/datasource/DefaultDataSourceSelector.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- DefaultDataSourceSelector.java 2001/04/02 00:07:02 1.1 +++ DefaultDataSourceSelector.java 2001/04/12 11:14:56 1.2 @@ -12,8 +12,7 @@ import java.util.Map; import org.apache.avalon.AbstractLoggable; import org.apache.avalon.Component; -import org.apache.avalon.ComponentManagerException; -import org.apache.avalon.ComponentNotFoundException; +import org.apache.avalon.component.ComponentException; import org.apache.avalon.Disposable; import org.apache.avalon.Initializable; import org.apache.avalon.configuration.Configurable; @@ -84,20 +83,19 @@ } public DataSourceComponent selectDataSource( final Object hint ) - throws ComponentManagerException + throws ComponentException { return (DataSourceComponent)select( hint ); } public Component select( final Object hint ) - throws ComponentManagerException + throws ComponentException { final Component component = (Component)m_dataSources.get( hint ); if( null == component ) { - throw new ComponentNotFoundException( "Unable to provide implementation for " - + hint ); + throw new ComponentException( "Unable to provide implementation for " + hint ); } return component; 1.4 +38 -37 jakarta-avalon-cornerstone/src/java/org/apache/cornerstone/blocks/masterstore/AbstractFileRepository.java Index: AbstractFileRepository.java =================================================================== RCS file: /home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/cornerstone/blocks/masterstore/AbstractFileRepository.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- AbstractFileRepository.java 2001/03/13 04:51:56 1.3 +++ AbstractFileRepository.java 2001/04/12 11:15:01 1.4 @@ -21,17 +21,18 @@ import org.apache.avalon.ComponentManager; import org.apache.avalon.ComponentManagerException; import org.apache.avalon.Composer; -import org.apache.avalon.configuration.Configurable; -import org.apache.avalon.configuration.Configuration; -import org.apache.avalon.configuration.ConfigurationException; import org.apache.avalon.Context; import org.apache.avalon.Contextualizable; import org.apache.avalon.Initializable; -import org.apache.phoenix.Block; -import org.apache.phoenix.BlockContext; +import org.apache.avalon.component.ComponentException; +import org.apache.avalon.configuration.Configurable; +import org.apache.avalon.configuration.Configuration; +import org.apache.avalon.configuration.ConfigurationException; +import org.apache.avalon.util.io.ExtensionFileFilter; import org.apache.cornerstone.services.Store; import org.apache.cornerstone.services.store.Repository; -import org.apache.avalon.util.io.ExtensionFileFilter; +import org.apache.phoenix.Block; +import org.apache.phoenix.BlockContext; /** * This an abstract class implementing functionality for creating a file-store. @@ -39,19 +40,19 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a> * @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a> */ -public abstract class AbstractFileRepository - extends AbstractLoggable +public abstract class AbstractFileRepository + extends AbstractLoggable implements Block, Repository, Contextualizable, Composer, Configurable, Initializable { protected static final boolean DEBUG = false; protected static final String HANDLED_URL = "file://"; protected static final int BYTE_MASK = 0x0f; - protected static final char[] HEX_DIGITS = + protected static final char[] HEX_DIGITS = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' }; - + protected String m_path; protected String m_destination; protected String m_extension; @@ -63,15 +64,15 @@ protected BlockContext m_context; protected abstract String getExtensionDecorator(); - + public void contextualize( final Context context ) { final BlockContext blockContext = (BlockContext)context; - m_baseDirectory = blockContext.getBaseDirectory(); + m_baseDirectory = blockContext.getBaseDirectory(); } public void compose( final ComponentManager componentManager ) - throws ComponentManagerException + throws ComponentException { m_componentManager = componentManager; } @@ -86,7 +87,7 @@ } } - public void init() + public void init() throws Exception { getLogger().info( "Init " + getClass().getName() + " Store" ); @@ -94,7 +95,7 @@ m_name = RepositoryManager.getName(); m_extension = "." + m_name + getExtensionDecorator(); m_filter = new ExtensionFileFilter( m_extension ); - + final File directory = new File( m_path ); directory.mkdirs(); @@ -112,11 +113,11 @@ m_path = destination.substring( HANDLED_URL.length() ); File directory = new File( m_baseDirectory, m_path ); - + try { directory = directory.getCanonicalFile(); } catch( final IOException ioe ) { - throw new ConfigurationException( "Unable to form canonical representation of " + + throw new ConfigurationException( "Unable to form canonical representation of " + directory ); } @@ -133,12 +134,12 @@ public Repository getChildRepository( final String childName ) { - AbstractFileRepository child = null; - + AbstractFileRepository child = null; + try { child = createChildRepository(); } catch( final Exception e ) { - throw new RuntimeException( "Cannot create child repository " + + throw new RuntimeException( "Cannot create child repository " + childName + " : " + e ); } @@ -146,34 +147,34 @@ catch( final ComponentManagerException cme ) { throw new RuntimeException( "Cannot compose child " + - "repository " + childName + + "repository " + childName + " : " + cme ); } - try + try { - child.setDestination( m_destination + File.pathSeparatorChar + + child.setDestination( m_destination + File.pathSeparatorChar + childName + File.pathSeparator ); } catch( final ConfigurationException ce ) { throw new RuntimeException( "Cannot set destination for child child " + - "repository " + childName + + "repository " + childName + " : " + ce ); } - - try { child.init(); } + + try { child.init(); } catch( final Exception e ) { throw new RuntimeException( "Cannot initialize child " + - "repository " + childName + + "repository " + childName + " : " + e ); } - if( DEBUG ) + if( DEBUG ) { - getLogger().debug( "Child repository of " + m_name + " created in " + - m_destination + File.pathSeparatorChar + + getLogger().debug( "Child repository of " + m_name + " created in " + + m_destination + File.pathSeparatorChar + childName + File.pathSeparator ); } @@ -208,14 +209,14 @@ final File file = getFile( key ); file.delete(); if( DEBUG ) getLogger().debug( "removed key " + key ); - } + } catch( final Exception e ) { throw new RuntimeException( "Exception caught while removing" + " an object: " + e ); } } - + /** * Indicates if the given key is associated to a contained object. */ @@ -226,7 +227,7 @@ final File file = getFile( key ); if( DEBUG ) getLogger().debug( "checking key " + key ); return file.exists(); - } + } catch( final Exception e ) { throw new RuntimeException( "Exception caught while searching " + @@ -237,7 +238,7 @@ /** * Returns the list of used keys. */ - public Iterator list() + public Iterator list() { final File storeDir = new File( m_path ); final String[] names = storeDir.list( m_filter ); @@ -259,7 +260,7 @@ * it may normally happen). For this reason, it's highly recommended * (even if not mandated) that Strings be used as keys. */ - protected String encode( final String key ) + protected String encode( final String key ) { final byte[] bytes = key.getBytes(); final char[] buffer = new char[ bytes.length << 1 ]; @@ -278,11 +279,11 @@ result.append( m_extension ); return result.toString(); } - + /** * Inverse of encode exept it do not use path. * So decode(encode(s) - m_path) = s. - * In other words it returns a String that can be used as key to retive + * In other words it returns a String that can be used as key to retive * the record contained in the 'filename' file. */ protected String decode( String filename ) 1.4 +43 -45 jakarta-avalon-cornerstone/src/java/org/apache/cornerstone/blocks/masterstore/RepositoryManager.java Index: RepositoryManager.java =================================================================== RCS file: /home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/cornerstone/blocks/masterstore/RepositoryManager.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- RepositoryManager.java 2001/03/13 04:51:56 1.3 +++ RepositoryManager.java 2001/04/12 11:15:02 1.4 @@ -14,26 +14,24 @@ import org.apache.avalon.AbstractLoggable; import org.apache.avalon.Component; import org.apache.avalon.ComponentManager; -import org.apache.avalon.ComponentManagerException; -import org.apache.avalon.ComponentNotAccessibleException; -import org.apache.avalon.ComponentNotFoundException; import org.apache.avalon.Composer; -import org.apache.avalon.configuration.Configurable; -import org.apache.avalon.configuration.Configuration; -import org.apache.avalon.configuration.ConfigurationException; import org.apache.avalon.Context; import org.apache.avalon.Contextualizable; import org.apache.avalon.Initializable; -import org.apache.phoenix.Block; -import org.apache.cornerstone.services.store.Store; +import org.apache.avalon.component.ComponentException; +import org.apache.avalon.configuration.Configurable; +import org.apache.avalon.configuration.Configuration; +import org.apache.avalon.configuration.ConfigurationException; import org.apache.cornerstone.services.store.Repository; +import org.apache.cornerstone.services.store.Store; +import org.apache.phoenix.Block; /** * * @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a> */ -public class RepositoryManager - extends AbstractLoggable +public class RepositoryManager + extends AbstractLoggable implements Block, Store, Contextualizable, Composer, Configurable, org.apache.cornerstone.services.Store { @@ -52,33 +50,33 @@ } public void compose( final ComponentManager componentManager ) - throws ComponentManagerException + throws ComponentException { m_componentManager = componentManager; - } + } public void configure( final Configuration configuration ) throws ConfigurationException { - final Configuration[] registeredClasses = + final Configuration[] registeredClasses = configuration.getChild( "repositories" ).getChildren( "repository" ); - + for( int i = 0; i < registeredClasses.length; i++ ) { registerRepository( registeredClasses[ i ] ); } } - public void registerRepository( final Configuration repConf ) + public void registerRepository( final Configuration repConf ) throws ConfigurationException { final String className = repConf.getAttribute( "class" ); getLogger().info( "Registering Repository " + className ); - final Configuration[] protocols = + final Configuration[] protocols = repConf.getChild( "protocols" ).getChildren( "protocol" ); final Configuration[] types = repConf.getChild( "types" ).getChildren( "type" ); - final Configuration[] modelIterator = + final Configuration[] modelIterator = repConf.getChild( "models" ).getChildren( "model" ); for( int i = 0; i < protocols.length; i++ ) @@ -103,33 +101,33 @@ { } - public Component select( Object hint ) - throws ComponentManagerException + public Component select( Object hint ) + throws ComponentException { Configuration repConf = null; try { repConf = (Configuration) hint; - } + } catch( final ClassCastException cce ) { - throw new ComponentNotAccessibleException( "Hint is of the wrong type. " + - "Must be a Configuration", cce ); + throw new ComponentException( "Hint is of the wrong type. " + + "Must be a Configuration", cce ); } URL destination = null; - try + try { destination = new URL( repConf.getAttribute("destinationURL") ); - } + } catch( final ConfigurationException ce ) { - throw new ComponentNotAccessibleException( "Malformed configuration has no " + - "destinationURL attribute", ce ); - } + throw new ComponentException( "Malformed configuration has no " + + "destinationURL attribute", ce ); + } catch( final MalformedURLException mue ) { - throw new ComponentNotAccessibleException( "destination is malformed. " + - "Must be a valid URL", mue ); + throw new ComponentException( "destination is malformed. " + + "Must be a valid URL", mue ); } try @@ -139,32 +137,32 @@ Repository reply = (Repository)m_repositories.get( repID ); final String model = (String)repConf.getAttribute( "model" ); - if( null != reply ) + if( null != reply ) { if( m_models.get( repID ).equals( model ) ) { return reply; - } + } else { final String message = "There is already another repository with the " + "same destination and type but with different model"; - throw new ComponentNotFoundException( message ); + throw new ComponentException( message ); } - } + } else { final String protocol = destination.getProtocol(); final String repClass = (String)m_classes.get( protocol + type + model ); - getLogger().debug( "Need instance of " + repClass + " to handle: " + + getLogger().debug( "Need instance of " + repClass + " to handle: " + protocol + type + model ); - try + try { reply = (Repository)Class.forName( repClass ).newInstance(); setupLogger( reply, "repository" ); - + if( reply instanceof Contextualizable ) { ((Contextualizable)reply).contextualize( m_context ); @@ -187,26 +185,26 @@ m_repositories.put( repID, reply ); m_models.put( repID, model ); - getLogger().info( "New instance of " + repClass + " created for " + + getLogger().info( "New instance of " + repClass + " created for " + destination ); return reply; - } + } catch( final Exception e ) { final String message = "Cannot find or init repository: " + e.getMessage(); getLogger().warn( message, e ); - - throw new ComponentNotAccessibleException( message, e ); + + throw new ComponentException( message, e ); } } - } - catch( final ConfigurationException ce ) + } + catch( final ConfigurationException ce ) { - throw new ComponentNotAccessibleException( "Malformed configuration", ce ); + throw new ComponentException( "Malformed configuration", ce ); } } - - public static final String getName() + + public static final String getName() { return REPOSITORY_NAME + id++; } 1.3 +44 -45 jakarta-avalon-cornerstone/src/java/org/apache/cornerstone/blocks/sockets/DefaultSocketManager.java Index: DefaultSocketManager.java =================================================================== RCS file: /home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/cornerstone/blocks/sockets/DefaultSocketManager.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- DefaultSocketManager.java 2001/03/28 15:12:15 1.2 +++ DefaultSocketManager.java 2001/04/12 11:15:07 1.3 @@ -11,11 +11,10 @@ import java.util.Iterator; import org.apache.avalon.AbstractLoggable; import org.apache.avalon.Component; -import org.apache.avalon.ComponentNotAccessibleException; -import org.apache.avalon.ComponentNotFoundException; import org.apache.avalon.Context; import org.apache.avalon.Contextualizable; import org.apache.avalon.Initializable; +import org.apache.avalon.component.ComponentException; import org.apache.avalon.configuration.Configurable; import org.apache.avalon.configuration.Configuration; import org.apache.avalon.configuration.ConfigurationException; @@ -26,11 +25,11 @@ /** * Implementation of SocketManager. - * + * * @author <a href="mailto:[EMAIL PROTECTED]">Federico Barbieri</a> * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a> */ -public class DefaultSocketManager +public class DefaultSocketManager extends AbstractLoggable implements SocketManager, Block, Contextualizable, Configurable, Initializable { @@ -56,36 +55,36 @@ { m_configuration = configuration; } - - public void init() - throws Exception + + public void init() + throws Exception { - final Configuration[] serverSockets = + final Configuration[] serverSockets = m_configuration.getChild( "server-sockets" ).getChildren( "factory" ); for( int i = 0; i < serverSockets.length; i++ ) { - final Configuration element = serverSockets[ i ]; + final Configuration element = serverSockets[ i ]; final String name = element.getAttribute( "name" ); final String className = element.getAttribute( "class" ); setupServerSocketFactory( name, className, element ); } - final Configuration[] clientSockets = + final Configuration[] clientSockets = m_configuration.getChild( "client-sockets" ).getChildren( "factory" ); - + for( int i = 0; i < clientSockets.length; i++ ) { final Configuration element = clientSockets[ i ]; final String name = element.getAttribute( "name" ); final String className = element.getAttribute( "class" ); - + setupClientSocketFactory( name, className, element ); } } - protected void setupServerSocketFactory( final String name, + protected void setupServerSocketFactory( final String name, final String className, final Configuration configuration ) throws Exception @@ -94,65 +93,65 @@ if( !(object instanceof ServerSocketFactory) ) { - throw new ComponentNotAccessibleException( "Error creating factory " + name + - " with class " + className + " as " + - "it does not implement the correct " + - "interface (ServerSocketFactory)" ); + throw new ComponentException( "Error creating factory " + name + + " with class " + className + " as " + + "it does not implement the correct " + + "interface (ServerSocketFactory)" ); } m_serverSockets.put( name, object ); } - - protected void setupClientSocketFactory( final String name, + + protected void setupClientSocketFactory( final String name, final String className, final Configuration configuration ) throws Exception { final Object object = createFactory( name, className, configuration ); - + if( !(object instanceof SocketFactory) ) { - throw new ComponentNotAccessibleException( "Error creating factory " + name + - " with class " + className + " as " + - "it does not implement the correct " + - "interface (SocketFactory)" ); + throw new ComponentException( "Error creating factory " + name + + " with class " + className + " as " + + "it does not implement the correct " + + "interface (SocketFactory)" ); } - + m_sockets.put( name, object ); } - - protected Component createFactory( final String name, + + protected Component createFactory( final String name, final String className, final Configuration configuration ) throws Exception { Component factory = null; - + try { - final ClassLoader classLoader = + final ClassLoader classLoader = (ClassLoader)Thread.currentThread().getContextClassLoader(); factory = (Component)classLoader.loadClass( className ).newInstance(); } catch( final Exception e ) { - throw new ComponentNotAccessibleException( "Error creating factory with class " + - className, e ); + throw new ComponentException( "Error creating factory with class " + + className, e ); } - + setupLogger( factory ); - + if( factory instanceof Contextualizable ) { ((Contextualizable)factory).contextualize( m_context ); } - + if( factory instanceof Configurable ) { ((Configurable)factory).configure( configuration ); } - + if( factory instanceof Initializable ) { ((Initializable)factory).init(); @@ -166,10 +165,10 @@ * * @param name the name of server socket factory * @return the ServerSocketFactory - * @exception ComponentNotFoundException if server socket factory is not available + * @exception ComponentException if server socket factory is not available */ public ServerSocketFactory getServerSocketFactory( String name ) - throws ComponentNotFoundException + throws ComponentException { final ServerSocketFactory factory = (ServerSocketFactory)m_serverSockets.get( name ); @@ -179,31 +178,31 @@ } else { - throw new ComponentNotFoundException( "Unable to locate server socket factory " + - "named " + name ); + throw new ComponentException( "Unable to locate server socket factory " + + "named " + name ); } } - + /** * Retrieve a client socket factory by name. * * @param name the name of client socket factory * @return the SocketFactory - * @exception ComponentNotFoundException if socket factory is not available + * @exception ComponentException if socket factory is not available */ public SocketFactory getSocketFactory( final String name ) - throws ComponentNotFoundException + throws ComponentException { final SocketFactory factory = (SocketFactory)m_sockets.get( name ); - + if( null != factory ) { return factory; } else { - throw new ComponentNotFoundException( "Unable to locate client socket factory " + - "named " + name ); + throw new ComponentException( "Unable to locate client socket factory " + + "named " + name ); } } } 1.2 +3 -3 jakarta-avalon-cornerstone/src/java/org/apache/cornerstone/demos/xcommander/XCommanderServer.java Index: XCommanderServer.java =================================================================== RCS file: /home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/cornerstone/demos/xcommander/XCommanderServer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- XCommanderServer.java 2001/03/16 13:16:45 1.1 +++ XCommanderServer.java 2001/04/12 11:15:12 1.2 @@ -19,9 +19,9 @@ import org.apache.avalon.ComponentManager; import org.apache.avalon.ComponentManagerException; import org.apache.avalon.Composer; -import org.apache.avalon.Configurable; -import org.apache.avalon.Configuration; -import org.apache.avalon.ConfigurationException; +import org.apache.avalon.configuration.Configurable; +import org.apache.avalon.configuration.Configuration; +import org.apache.avalon.configuration.ConfigurationException; import org.apache.avalon.Initializable; import org.apache.cornerstone.demos.xcommander.xcommands.Chat; import org.apache.cornerstone.demos.xcommander.xcommands.Echo; 1.3 +3 -3 jakarta-avalon-cornerstone/src/java/org/apache/cornerstone/services/sockets/SocketManager.java Index: SocketManager.java =================================================================== RCS file: /home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/cornerstone/services/sockets/SocketManager.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- SocketManager.java 2001/03/13 04:52:00 1.2 +++ SocketManager.java 2001/04/12 11:15:16 1.3 @@ -7,7 +7,7 @@ */ package org.apache.cornerstone.services.sockets; -import org.apache.avalon.ComponentNotFoundException; +import org.apache.avalon.component.ComponentException; import org.apache.phoenix.Service; /** @@ -26,7 +26,7 @@ * @exception ComponentNotFoundException if server socket factory is not available */ ServerSocketFactory getServerSocketFactory( String name ) - throws ComponentNotFoundException; + throws ComponentException; /** * Retrieve a client socket factory by name. @@ -36,5 +36,5 @@ * @exception ComponentNotFoundException if socket factory is not available */ SocketFactory getSocketFactory( String name ) - throws ComponentNotFoundException; + throws ComponentException; } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]