avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/transport/publishing AbstractPublisher.java
Date Mon, 23 Dec 2002 17:52:40 GMT
bloritsch    2002/12/23 09:52:40

  Modified:    src/java/org/apache/avalon/cornerstone/blocks/datasource
                        DefaultDataSourceSelector.java
               src/java/org/apache/avalon/cornerstone/blocks/event
                        DefaultEventManager.java
               src/java/org/apache/avalon/cornerstone/blocks/masterstore
                        AbstractFileRepository.java
               src/java/org/apache/avalon/cornerstone/blocks/sockets
                        SSLFactoryBuilder.java
               src/java/org/apache/avalon/cornerstone/blocks/transport/publishing
                        AbstractPublisher.java
  Log:
  Divorce ourselves from useing *phoenix.BlockContext--without sacrificing functionality
  
  Revision  Changes    Path
  1.26      +185 -185  jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/datasource/DefaultDataSourceSelector.java
  
  Index: DefaultDataSourceSelector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/datasource/DefaultDataSourceSelector.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- DefaultDataSourceSelector.java	2 Oct 2002 01:52:15 -0000	1.25
  +++ DefaultDataSourceSelector.java	23 Dec 2002 17:52:40 -0000	1.26
  @@ -1,185 +1,185 @@
  -/*
  - * 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.avalon.cornerstone.blocks.datasource;
  -
  -import java.util.HashMap;
  -import java.util.Iterator;
  -import java.util.Map;
  -import org.apache.avalon.cornerstone.services.datasource.DataSourceSelector;
  -import org.apache.avalon.excalibur.datasource.DataSourceComponent;
  -import org.apache.avalon.framework.activity.Disposable;
  -import org.apache.avalon.framework.activity.Initializable;
  -import org.apache.avalon.framework.component.Component;
  -import org.apache.avalon.framework.component.ComponentException;
  -import org.apache.avalon.framework.configuration.Configurable;
  -import org.apache.avalon.framework.configuration.Configuration;
  -import org.apache.avalon.framework.context.Context;
  -import org.apache.avalon.framework.context.ContextException;
  -import org.apache.avalon.framework.context.Contextualizable;
  -import org.apache.avalon.framework.logger.AbstractLogEnabled;
  -import org.apache.avalon.framework.logger.LogEnabled;
  -import org.apache.avalon.phoenix.BlockContext;
  -
  -/**
  - * The Default implementation for DataSourceSelector.
  - * The Configuration is like this:
  - *
  - * <pre>
  - * &lt;myBlock&gt;
  - *   &lt;data-source name="<i>default</i>"
  - *     class="<i>org.apache.avalon.excalibur.datasource.JdbcDataSource</i>"&gt;
  - *     &lt;!-- configuration for JdbcDataSource --&gt;
  - *     &lt;pool-controller min="<i>5</i>" max="<i>10</i>" connection-class="<i>my.overrided.ConnectionClass</i>"&gt;
  - *       &lt;keep-alive&gt;select 1&lt;/keep-alive&gt;
  - *     &lt;/pool-controller&gt;
  - *     &lt;driver&gt;<i>com.database.jdbc.JdbcDriver</i>&lt;/driver&gt;
  - *     &lt;dburl&gt;<i>jdbc:driver://host/mydb</i>&lt;/dburl&gt;
  - *     &lt;user&gt;<i>username</i>&lt;/user&gt;
  - *     &lt;password&gt;<i>password</i>&lt;/password&gt;
  - *   &lt;/data-source&gt;
  - * &lt;/myBlock&gt;
  - * </pre>
  - *
  - * @phoenix:block
  - * @phoenix:service name="org.apache.avalon.cornerstone.services.datasource.DataSourceSelector"
  - *
  - * @author <a href="mailto:colus@apache.org">Eung-ju Park</a>
  - */
  -public class DefaultDataSourceSelector
  -    extends AbstractLogEnabled
  -    implements DataSourceSelector, Contextualizable, Configurable, Initializable, Disposable
  -{
  -    private Configuration m_configuration;
  -    private Map m_dataSources;
  -    private BlockContext m_context;
  -
  -    public void contextualize( final Context context )
  -        throws ContextException
  -    {
  -        m_context = (BlockContext)context;
  -    }
  -
  -    /**
  -     * @phoenix:configuration-schema type="relax-ng"
  -     */
  -    public void configure( final Configuration configuration )
  -    {
  -        m_configuration = configuration;
  -    }
  -
  -    public void initialize()
  -        throws Exception
  -    {
  -        m_dataSources = new HashMap();
  -
  -        Configuration[] dataSourceConfs = getDataSourceConfig();
  -
  -        for( int i = 0; i < dataSourceConfs.length; i++ )
  -        {
  -            final Configuration dataSourceConf = dataSourceConfs[ i ];
  -
  -            final String name = dataSourceConf.getAttribute( "name" );
  -            final String clazz = dataSourceConf.getAttribute( "class" );
  -            final String driver = dataSourceConf.getChild( "driver", true ).getValue( "" );
  -
  -            final ClassLoader classLoader =
  -                Thread.currentThread().getContextClassLoader();
  -
  -            DataSourceComponent component = null;
  -            if( null == classLoader )
  -            {
  -                if( !"".equals( driver ) )
  -                {
  -                    Class.forName( driver, true, Thread.currentThread().getContextClassLoader() );
  -                }
  -
  -                component = (DataSourceComponent)Class.forName( clazz ).newInstance();
  -            }
  -            else
  -            {
  -                if( !"".equals( driver ) )
  -                {
  -                    classLoader.loadClass( driver );
  -                }
  -
  -                component = (DataSourceComponent)classLoader.loadClass( clazz ).newInstance();
  -            }
  -
  -            if( component instanceof LogEnabled )
  -            {
  -                setupLogger( component, name );
  -            }
  -            component.configure( dataSourceConf );
  -            m_dataSources.put( name, component );
  -
  -            if( getLogger().isInfoEnabled() )
  -            {
  -                getLogger().info( "DataSource " + name + " ready" );
  -            }
  -        }
  -    }
  -
  -    private Configuration[] getDataSourceConfig()
  -    {
  -        final Configuration head =
  -            m_configuration.getChild( "data-sources" );
  -        if( 0 != head.getChildren().length )
  -        {
  -            final String message =
  -                "WARNING: Child node <data-sources/> in " +
  -                "configuration of component named " + m_context.getName() +
  -                " has been deprecated. Please put <data-source/> elements" +
  -                " in root configuration element";
  -            getLogger().warn( message );
  -            System.out.println( message );
  -            return head.getChildren( "data-source" );
  -        }
  -        else
  -        {
  -            return m_configuration.getChildren( "data-source" );
  -        }
  -    }
  -
  -    public void dispose()
  -    {
  -        final Iterator keys = m_dataSources.keySet().iterator();
  -        while( keys.hasNext() )
  -        {
  -            final DataSourceComponent dsc =
  -                (DataSourceComponent)m_dataSources.get( keys.next() );
  -            if( dsc instanceof Disposable )
  -            {
  -                ((Disposable)dsc).dispose();
  -            }
  -        }
  -    }
  -
  -    public boolean hasComponent( final Object hint )
  -    {
  -        return m_dataSources.containsKey( hint );
  -    }
  -
  -    public Component select( final Object hint )
  -        throws ComponentException
  -    {
  -        final Component component = (Component)m_dataSources.get( hint );
  -
  -        if( null == component )
  -        {
  -            throw new ComponentException( "Unable to provide DataSourceComponent for " + hint );
  -        }
  -
  -        return component;
  -    }
  -
  -    public void release( final Component component )
  -    {
  -        //do nothing
  -    }
  -
  -}
  +/*
  + * 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.avalon.cornerstone.blocks.datasource;
  +
  +import java.util.HashMap;
  +import java.util.Iterator;
  +import java.util.Map;
  +import org.apache.avalon.cornerstone.services.datasource.DataSourceSelector;
  +import org.apache.avalon.excalibur.datasource.DataSourceComponent;
  +import org.apache.avalon.framework.activity.Disposable;
  +import org.apache.avalon.framework.activity.Initializable;
  +import org.apache.avalon.framework.component.Component;
  +import org.apache.avalon.framework.component.ComponentException;
  +import org.apache.avalon.framework.configuration.Configurable;
  +import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.context.Context;
  +import org.apache.avalon.framework.context.ContextException;
  +import org.apache.avalon.framework.context.Contextualizable;
  +import org.apache.avalon.framework.logger.AbstractLogEnabled;
  +import org.apache.avalon.framework.logger.LogEnabled;
  +
  +/**
  + * The Default implementation for DataSourceSelector.
  + * The Configuration is like this:
  + *
  + * <pre>
  + * &lt;myBlock&gt;
  + *   &lt;data-source name="<i>default</i>"
  + *     class="<i>org.apache.avalon.excalibur.datasource.JdbcDataSource</i>"&gt;
  + *     &lt;!-- configuration for JdbcDataSource --&gt;
  + *     &lt;pool-controller min="<i>5</i>" max="<i>10</i>" connection-class="<i>my.overrided.ConnectionClass</i>"&gt;
  + *       &lt;keep-alive&gt;select 1&lt;/keep-alive&gt;
  + *     &lt;/pool-controller&gt;
  + *     &lt;driver&gt;<i>com.database.jdbc.JdbcDriver</i>&lt;/driver&gt;
  + *     &lt;dburl&gt;<i>jdbc:driver://host/mydb</i>&lt;/dburl&gt;
  + *     &lt;user&gt;<i>username</i>&lt;/user&gt;
  + *     &lt;password&gt;<i>password</i>&lt;/password&gt;
  + *   &lt;/data-source&gt;
  + * &lt;/myBlock&gt;
  + * </pre>
  + *
  + * @phoenix:block
  + * @phoenix:service name="org.apache.avalon.cornerstone.services.datasource.DataSourceSelector"
  + *
  + * @author <a href="mailto:colus@apache.org">Eung-ju Park</a>
  + */
  +public class DefaultDataSourceSelector
  +    extends AbstractLogEnabled
  +    implements DataSourceSelector, Contextualizable, Configurable, Initializable, Disposable
  +{
  +    private Configuration m_configuration;
  +    private Map m_dataSources;
  +    private String m_blockName;
  +
  +    public void contextualize( final Context context )
  +        throws ContextException
  +    {
  +        m_blockName = (String) context.get("block.name");
  +    }
  +
  +    /**
  +     * @phoenix:configuration-schema type="relax-ng"
  +     */
  +    public void configure( final Configuration configuration )
  +    {
  +        m_configuration = configuration;
  +    }
  +
  +    public void initialize()
  +        throws Exception
  +    {
  +        m_dataSources = new HashMap();
  +
  +        Configuration[] dataSourceConfs = getDataSourceConfig();
  +
  +        for( int i = 0; i < dataSourceConfs.length; i++ )
  +        {
  +            final Configuration dataSourceConf = dataSourceConfs[ i ];
  +
  +            final String name = dataSourceConf.getAttribute( "name" );
  +            final String clazz = dataSourceConf.getAttribute( "class" );
  +            final String driver = dataSourceConf.getChild( "driver", true ).getValue( "" );
  +
  +            final ClassLoader classLoader =
  +                Thread.currentThread().getContextClassLoader();
  +
  +            DataSourceComponent component = null;
  +            if( null == classLoader )
  +            {
  +                if( !"".equals( driver ) )
  +                {
  +                    Class.forName( driver, true, Thread.currentThread().getContextClassLoader() );
  +                }
  +
  +                component = (DataSourceComponent)Class.forName( clazz ).newInstance();
  +            }
  +            else
  +            {
  +                if( !"".equals( driver ) )
  +                {
  +                    classLoader.loadClass( driver );
  +                }
  +
  +                component = (DataSourceComponent)classLoader.loadClass( clazz ).newInstance();
  +            }
  +
  +            if( component instanceof LogEnabled )
  +            {
  +                setupLogger( component, name );
  +            }
  +            component.configure( dataSourceConf );
  +            m_dataSources.put( name, component );
  +
  +            if( getLogger().isInfoEnabled() )
  +            {
  +                getLogger().info( "DataSource " + name + " ready" );
  +            }
  +        }
  +    }
  +
  +    private Configuration[] getDataSourceConfig()
  +    {
  +        final Configuration head =
  +            m_configuration.getChild( "data-sources" );
  +        if( 0 != head.getChildren().length )
  +        {
  +
  +            final String message =
  +                "WARNING: Child node <data-sources/> in " +
  +                "configuration of component named " + m_blockName +
  +                " has been deprecated. Please put <data-source/> elements" +
  +                " in root configuration element";
  +            getLogger().warn( message );
  +            System.out.println( message );
  +            return head.getChildren( "data-source" );
  +        }
  +        else
  +        {
  +            return m_configuration.getChildren( "data-source" );
  +        }
  +    }
  +
  +    public void dispose()
  +    {
  +        final Iterator keys = m_dataSources.keySet().iterator();
  +        while( keys.hasNext() )
  +        {
  +            final DataSourceComponent dsc =
  +                (DataSourceComponent)m_dataSources.get( keys.next() );
  +            if( dsc instanceof Disposable )
  +            {
  +                ((Disposable)dsc).dispose();
  +            }
  +        }
  +    }
  +
  +    public boolean hasComponent( final Object hint )
  +    {
  +        return m_dataSources.containsKey( hint );
  +    }
  +
  +    public Component select( final Object hint )
  +        throws ComponentException
  +    {
  +        final Component component = (Component)m_dataSources.get( hint );
  +
  +        if( null == component )
  +        {
  +            throw new ComponentException( "Unable to provide DataSourceComponent for " + hint );
  +        }
  +
  +        return component;
  +    }
  +
  +    public void release( final Component component )
  +    {
  +        //do nothing
  +    }
  +
  +}
  
  
  
  1.2       +10 -12    jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/event/DefaultEventManager.java
  
  Index: DefaultEventManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/event/DefaultEventManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultEventManager.java	29 Nov 2002 21:30:06 -0000	1.1
  +++ DefaultEventManager.java	23 Dec 2002 17:52:40 -0000	1.2
  @@ -23,8 +23,6 @@
   import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.activity.Disposable;
   
  -import org.apache.avalon.phoenix.BlockContext;
  -
   import org.apache.avalon.cornerstone.services.event.Event;
   import org.apache.avalon.cornerstone.services.event.Filter;
   import org.apache.avalon.cornerstone.services.event.EventManager;
  @@ -49,18 +47,18 @@
       private Publisher m_publisher = new DefaultPublisher();
       private Register m_register = new DefaultRegister();
       private Hashtable m_subscribers = new Hashtable();
  -    
  +
       public Publisher getPublisher(){
           return m_publisher;
       }
       public Register getRegister(){
           return m_register;
       }
  -    
  +
       public void contextualize( final Context context )
       {
       }
  -    
  +
       public void configure( final Configuration configuration )
           throws ConfigurationException
       {
  @@ -76,7 +74,7 @@
   
       public void initialize()
           throws Exception
  -    {            
  +    {
           m_eventClass = Class.forName( m_rootEventType );
           getLogger().info("Initialising eventClass " + m_eventClass);
       }
  @@ -84,10 +82,10 @@
       public void dispose()
       {
       }
  -    
  +
       class DefaultPublisher implements Publisher
       {
  -        public void publish( final Event event ) 
  +        public void publish( final Event event )
           {
               getLogger().info("Publishing event " + event.getClass());
               System.out.println("Publishing event " + event.getClass());
  @@ -102,7 +100,7 @@
               }
           }
       }
  -    
  +
       class DefaultRegister implements Register
       {
           public void subscribe( final Subscriber subscriber )
  @@ -110,7 +108,7 @@
           {
               if ( !m_eventClass.isAssignableFrom( subscriber.getEventType() ) )
                   throw new InvalidEventTypeException();
  -            
  +
               getLogger().info( "Subscribing event " + subscriber.getEventType().getName() );
               // Add to list but prevent duplicate subscriptions
               if ( !m_subscribers.containsKey( subscriber.getUID() ) ){
  @@ -122,7 +120,7 @@
               }
           }
           public void unsubscribe( Subscriber subscriber )
  -            throws InvalidEventTypeException 
  +            throws InvalidEventTypeException
           {
               if ( !m_eventClass.isAssignableFrom( subscriber.getEventType() ) )
                   throw new InvalidEventTypeException();
  @@ -137,5 +135,5 @@
               }
           }
       }
  -    
  +
   }
  
  
  
  1.10      +319 -321  jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/masterstore/AbstractFileRepository.java
  
  Index: AbstractFileRepository.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/masterstore/AbstractFileRepository.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- AbstractFileRepository.java	2 Oct 2002 01:52:16 -0000	1.9
  +++ AbstractFileRepository.java	23 Dec 2002 17:52:40 -0000	1.10
  @@ -1,321 +1,319 @@
  -/*
  - * 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.avalon.cornerstone.blocks.masterstore;
  -
  -import java.io.File;
  -import java.io.FileInputStream;
  -import java.io.FileOutputStream;
  -import java.io.FilenameFilter;
  -import java.io.IOException;
  -import java.io.InputStream;
  -import java.io.OutputStream;
  -import java.util.ArrayList;
  -import java.util.Iterator;
  -import org.apache.avalon.cornerstone.services.store.Repository;
  -import org.apache.avalon.excalibur.io.ExtensionFileFilter;
  -import org.apache.avalon.framework.activity.Initializable;
  -import org.apache.avalon.framework.configuration.Configurable;
  -import org.apache.avalon.framework.configuration.Configuration;
  -import org.apache.avalon.framework.configuration.ConfigurationException;
  -import org.apache.avalon.framework.context.Context;
  -import org.apache.avalon.framework.context.Contextualizable;
  -import org.apache.avalon.framework.logger.AbstractLogEnabled;
  -import org.apache.avalon.framework.service.ServiceException;
  -import org.apache.avalon.framework.service.ServiceManager;
  -import org.apache.avalon.framework.service.Serviceable;
  -import org.apache.avalon.phoenix.BlockContext;
  -
  -/**
  - * This an abstract class implementing functionality for creating a file-store.
  - *
  - * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @author <a href="mailto:fede@apache.org">Federico Barbieri</a>
  - */
  -public abstract class AbstractFileRepository
  -    extends AbstractLogEnabled
  -    implements Repository, Contextualizable, Serviceable, 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 = new char[]
  -    {
  -        '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;
  -    protected String m_name;
  -    protected FilenameFilter m_filter;
  -    protected File m_baseDirectory;
  -
  -    protected ServiceManager m_serviceManager;
  -    protected BlockContext m_context;
  -
  -    protected abstract String getExtensionDecorator();
  -
  -    public void contextualize( final Context context )
  -    {
  -        final BlockContext blockContext = (BlockContext) context;
  -        m_baseDirectory = blockContext.getBaseDirectory();
  -    }
  -
  -    public void service( final ServiceManager serviceManager )
  -        throws ServiceException
  -    {
  -        m_serviceManager = serviceManager;
  -    }
  -
  -    public void configure( final Configuration configuration )
  -        throws ConfigurationException
  -    {
  -        if( null == m_destination )
  -        {
  -            final String destination = configuration.getAttribute( "destinationURL" );
  -            setDestination( destination );
  -        }
  -    }
  -
  -    public void initialize()
  -        throws Exception
  -    {
  -        getLogger().info( "Init " + getClass().getName() + " Store" );
  -
  -        m_name = RepositoryManager.getName();
  -        m_extension = "." + m_name + getExtensionDecorator();
  -        m_filter = new ExtensionFileFilter( m_extension );
  -
  -        final File directory = new File( m_path );
  -        directory.mkdirs();
  -
  -        getLogger().info( getClass().getName() + " opened in " + m_path );
  -    }
  -
  -    protected void setDestination( final String destination )
  -        throws ConfigurationException
  -    {
  -        if( !destination.startsWith( HANDLED_URL ) )
  -        {
  -            throw new ConfigurationException( "cannot handle destination " + destination );
  -        }
  -
  -        m_path = destination.substring( HANDLED_URL.length() );
  -
  -        File directory;
  -
  -        // Check for absolute path
  -        if( m_path.startsWith( "/" ) )
  -        {
  -            directory = new File( m_path );
  -        }
  -        else
  -        {
  -            directory = new File( m_baseDirectory, m_path );
  -        }
  -
  -        try
  -        {
  -            directory = directory.getCanonicalFile();
  -        }
  -        catch( final IOException ioe )
  -        {
  -            throw new ConfigurationException( "Unable to form canonical representation of " +
  -                                              directory );
  -        }
  -
  -        m_path = directory.toString();
  -
  -        m_destination = destination;
  -    }
  -
  -    protected AbstractFileRepository createChildRepository()
  -        throws Exception
  -    {
  -        return (AbstractFileRepository) getClass().newInstance();
  -    }
  -
  -    public Repository getChildRepository( final String childName )
  -    {
  -        AbstractFileRepository child = null;
  -
  -        try
  -        {
  -            child = createChildRepository();
  -        }
  -        catch( final Exception e )
  -        {
  -            throw new RuntimeException( "Cannot create child repository " +
  -                                        childName + " : " + e );
  -        }
  -
  -        try
  -        {
  -            child.service( m_serviceManager );
  -        }
  -        catch( final ServiceException cme )
  -        {
  -            throw new RuntimeException( "Cannot service child " +
  -                                        "repository " + childName +
  -                                        " : " + cme );
  -        }
  -
  -        try
  -        {
  -            child.setDestination( m_destination + File.pathSeparatorChar +
  -                                  childName + File.pathSeparator );
  -        }
  -        catch( final ConfigurationException ce )
  -        {
  -            throw new RuntimeException( "Cannot set destination for child child " +
  -                                        "repository " + childName +
  -                                        " : " + ce );
  -        }
  -
  -        try
  -        {
  -            child.initialize();
  -        }
  -        catch( final Exception e )
  -        {
  -            throw new RuntimeException( "Cannot initialize child " +
  -                                        "repository " + childName +
  -                                        " : " + e );
  -        }
  -
  -        if( DEBUG )
  -        {
  -            getLogger().debug( "Child repository of " + m_name + " created in " +
  -                               m_destination + File.pathSeparatorChar +
  -                               childName + File.pathSeparator );
  -        }
  -
  -        return child;
  -    }
  -
  -    protected File getFile( final String key )
  -        throws IOException
  -    {
  -        return new File( encode( key ) );
  -    }
  -
  -    protected InputStream getInputStream( final String key )
  -        throws IOException
  -    {
  -        return new FileInputStream( getFile( key ) );
  -    }
  -
  -    protected OutputStream getOutputStream( final String key )
  -        throws IOException
  -    {
  -        return new FileOutputStream( getFile( key ) );
  -    }
  -
  -    /**
  -     * Remove the object associated to the given key.
  -     */
  -    public synchronized void remove( final String key )
  -    {
  -        try
  -        {
  -            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.
  -     */
  -    public synchronized boolean containsKey( final String key )
  -    {
  -        try
  -        {
  -            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 " +
  -                                        "an object: " + e );
  -        }
  -    }
  -
  -    /**
  -     * Returns the list of used keys.
  -     */
  -    public Iterator list()
  -    {
  -        final File storeDir = new File( m_path );
  -        final String[] names = storeDir.list( m_filter );
  -        final ArrayList list = new ArrayList();
  -
  -        for( int i = 0; i < names.length; i++ )
  -        {
  -            list.add( decode( names[ i ] ) );
  -        }
  -
  -        return list.iterator();
  -    }
  -
  -    /**
  -     * Returns a String that uniquely identifies the object.
  -     * <b>Note:</b> since this method uses the Object.toString()
  -     * method, it's up to the caller to make sure that this method
  -     * doesn't change between different JVM executions (like
  -     * 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 )
  -    {
  -        final byte[] bytes = key.getBytes();
  -        final char[] buffer = new char[ bytes.length << 1 ];
  -
  -        for( int i = 0, j = 0; i < bytes.length; i++ )
  -        {
  -            final int k = bytes[ i ];
  -            buffer[ j++ ] = HEX_DIGITS[ ( k >>> 4 ) & BYTE_MASK ];
  -            buffer[ j++ ] = HEX_DIGITS[ k & BYTE_MASK ];
  -        }
  -
  -        StringBuffer result = new StringBuffer();
  -        result.append( m_path );
  -        result.append( File.separator );
  -        result.append( buffer );
  -        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
  -     * the record contained in the 'filename' file.
  -     */
  -    protected String decode( String filename )
  -    {
  -        filename = filename.substring( 0, filename.length() - m_extension.length() );
  -        final int size = filename.length();
  -        final byte[] bytes = new byte[ size >>> 1 ];
  -
  -        for( int i = 0, j = 0; i < size; j++ )
  -        {
  -            bytes[ j ] = Byte.parseByte( filename.substring( i, i + 2 ), 16 );
  -            i += 2;
  -        }
  -
  -        return new String( bytes );
  -    }
  -}
  +/*
  + * 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.avalon.cornerstone.blocks.masterstore;
  +
  +import java.io.File;
  +import java.io.FileInputStream;
  +import java.io.FileOutputStream;
  +import java.io.FilenameFilter;
  +import java.io.IOException;
  +import java.io.InputStream;
  +import java.io.OutputStream;
  +import java.util.ArrayList;
  +import java.util.Iterator;
  +import org.apache.avalon.cornerstone.services.store.Repository;
  +import org.apache.avalon.excalibur.io.ExtensionFileFilter;
  +import org.apache.avalon.framework.activity.Initializable;
  +import org.apache.avalon.framework.configuration.Configurable;
  +import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.avalon.framework.context.Context;
  +import org.apache.avalon.framework.context.Contextualizable;
  +import org.apache.avalon.framework.logger.AbstractLogEnabled;
  +import org.apache.avalon.framework.service.ServiceException;
  +import org.apache.avalon.framework.service.ServiceManager;
  +import org.apache.avalon.framework.service.Serviceable;
  +import org.apache.avalon.framework.context.ContextException;
  +
  +/**
  + * This an abstract class implementing functionality for creating a file-store.
  + *
  + * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  + * @author <a href="mailto:fede@apache.org">Federico Barbieri</a>
  + */
  +public abstract class AbstractFileRepository
  +    extends AbstractLogEnabled
  +    implements Repository, Contextualizable, Serviceable, 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 = new char[]
  +    {
  +        '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;
  +    protected String m_name;
  +    protected FilenameFilter m_filter;
  +    protected File m_baseDirectory;
  +
  +    protected ServiceManager m_serviceManager;
  +
  +    protected abstract String getExtensionDecorator();
  +
  +    public void contextualize( final Context context ) throws ContextException
  +    {
  +        m_baseDirectory = (File) context.get("app.home");
  +    }
  +
  +    public void service( final ServiceManager serviceManager )
  +        throws ServiceException
  +    {
  +        m_serviceManager = serviceManager;
  +    }
  +
  +    public void configure( final Configuration configuration )
  +        throws ConfigurationException
  +    {
  +        if( null == m_destination )
  +        {
  +            final String destination = configuration.getAttribute( "destinationURL" );
  +            setDestination( destination );
  +        }
  +    }
  +
  +    public void initialize()
  +        throws Exception
  +    {
  +        getLogger().info( "Init " + getClass().getName() + " Store" );
  +
  +        m_name = RepositoryManager.getName();
  +        m_extension = "." + m_name + getExtensionDecorator();
  +        m_filter = new ExtensionFileFilter( m_extension );
  +
  +        final File directory = new File( m_path );
  +        directory.mkdirs();
  +
  +        getLogger().info( getClass().getName() + " opened in " + m_path );
  +    }
  +
  +    protected void setDestination( final String destination )
  +        throws ConfigurationException
  +    {
  +        if( !destination.startsWith( HANDLED_URL ) )
  +        {
  +            throw new ConfigurationException( "cannot handle destination " + destination );
  +        }
  +
  +        m_path = destination.substring( HANDLED_URL.length() );
  +
  +        File directory;
  +
  +        // Check for absolute path
  +        if( m_path.startsWith( "/" ) )
  +        {
  +            directory = new File( m_path );
  +        }
  +        else
  +        {
  +            directory = new File( m_baseDirectory, m_path );
  +        }
  +
  +        try
  +        {
  +            directory = directory.getCanonicalFile();
  +        }
  +        catch( final IOException ioe )
  +        {
  +            throw new ConfigurationException( "Unable to form canonical representation of " +
  +                                              directory );
  +        }
  +
  +        m_path = directory.toString();
  +
  +        m_destination = destination;
  +    }
  +
  +    protected AbstractFileRepository createChildRepository()
  +        throws Exception
  +    {
  +        return (AbstractFileRepository) getClass().newInstance();
  +    }
  +
  +    public Repository getChildRepository( final String childName )
  +    {
  +        AbstractFileRepository child = null;
  +
  +        try
  +        {
  +            child = createChildRepository();
  +        }
  +        catch( final Exception e )
  +        {
  +            throw new RuntimeException( "Cannot create child repository " +
  +                                        childName + " : " + e );
  +        }
  +
  +        try
  +        {
  +            child.service( m_serviceManager );
  +        }
  +        catch( final ServiceException cme )
  +        {
  +            throw new RuntimeException( "Cannot service child " +
  +                                        "repository " + childName +
  +                                        " : " + cme );
  +        }
  +
  +        try
  +        {
  +            child.setDestination( m_destination + File.pathSeparatorChar +
  +                                  childName + File.pathSeparator );
  +        }
  +        catch( final ConfigurationException ce )
  +        {
  +            throw new RuntimeException( "Cannot set destination for child child " +
  +                                        "repository " + childName +
  +                                        " : " + ce );
  +        }
  +
  +        try
  +        {
  +            child.initialize();
  +        }
  +        catch( final Exception e )
  +        {
  +            throw new RuntimeException( "Cannot initialize child " +
  +                                        "repository " + childName +
  +                                        " : " + e );
  +        }
  +
  +        if( DEBUG )
  +        {
  +            getLogger().debug( "Child repository of " + m_name + " created in " +
  +                               m_destination + File.pathSeparatorChar +
  +                               childName + File.pathSeparator );
  +        }
  +
  +        return child;
  +    }
  +
  +    protected File getFile( final String key )
  +        throws IOException
  +    {
  +        return new File( encode( key ) );
  +    }
  +
  +    protected InputStream getInputStream( final String key )
  +        throws IOException
  +    {
  +        return new FileInputStream( getFile( key ) );
  +    }
  +
  +    protected OutputStream getOutputStream( final String key )
  +        throws IOException
  +    {
  +        return new FileOutputStream( getFile( key ) );
  +    }
  +
  +    /**
  +     * Remove the object associated to the given key.
  +     */
  +    public synchronized void remove( final String key )
  +    {
  +        try
  +        {
  +            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.
  +     */
  +    public synchronized boolean containsKey( final String key )
  +    {
  +        try
  +        {
  +            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 " +
  +                                        "an object: " + e );
  +        }
  +    }
  +
  +    /**
  +     * Returns the list of used keys.
  +     */
  +    public Iterator list()
  +    {
  +        final File storeDir = new File( m_path );
  +        final String[] names = storeDir.list( m_filter );
  +        final ArrayList list = new ArrayList();
  +
  +        for( int i = 0; i < names.length; i++ )
  +        {
  +            list.add( decode( names[ i ] ) );
  +        }
  +
  +        return list.iterator();
  +    }
  +
  +    /**
  +     * Returns a String that uniquely identifies the object.
  +     * <b>Note:</b> since this method uses the Object.toString()
  +     * method, it's up to the caller to make sure that this method
  +     * doesn't change between different JVM executions (like
  +     * 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 )
  +    {
  +        final byte[] bytes = key.getBytes();
  +        final char[] buffer = new char[ bytes.length << 1 ];
  +
  +        for( int i = 0, j = 0; i < bytes.length; i++ )
  +        {
  +            final int k = bytes[ i ];
  +            buffer[ j++ ] = HEX_DIGITS[ ( k >>> 4 ) & BYTE_MASK ];
  +            buffer[ j++ ] = HEX_DIGITS[ k & BYTE_MASK ];
  +        }
  +
  +        StringBuffer result = new StringBuffer();
  +        result.append( m_path );
  +        result.append( File.separator );
  +        result.append( buffer );
  +        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
  +     * the record contained in the 'filename' file.
  +     */
  +    protected String decode( String filename )
  +    {
  +        filename = filename.substring( 0, filename.length() - m_extension.length() );
  +        final int size = filename.length();
  +        final byte[] bytes = new byte[ size >>> 1 ];
  +
  +        for( int i = 0, j = 0; i < size; j++ )
  +        {
  +            bytes[ j ] = Byte.parseByte( filename.substring( i, i + 2 ), 16 );
  +            i += 2;
  +        }
  +
  +        return new String( bytes );
  +    }
  +}
  
  
  
  1.3       +258 -259  jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/sockets/SSLFactoryBuilder.java
  
  Index: SSLFactoryBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/sockets/SSLFactoryBuilder.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SSLFactoryBuilder.java	8 Oct 2002 21:43:32 -0000	1.2
  +++ SSLFactoryBuilder.java	23 Dec 2002 17:52:40 -0000	1.3
  @@ -1,259 +1,258 @@
  -/*
  - * 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.avalon.cornerstone.blocks.sockets;
  -
  -import com.sun.net.ssl.KeyManagerFactory;
  -import com.sun.net.ssl.SSLContext;
  -import com.sun.net.ssl.TrustManagerFactory;
  -import java.io.File;
  -import java.io.FileInputStream;
  -import java.io.IOException;
  -import java.io.InputStream;
  -import java.security.GeneralSecurityException;
  -import java.security.KeyStore;
  -import java.util.Arrays;
  -import javax.net.ssl.SSLServerSocketFactory;
  -import javax.net.ssl.SSLSocketFactory;
  -import org.apache.avalon.framework.activity.Disposable;
  -import org.apache.avalon.framework.activity.Initializable;
  -import org.apache.avalon.framework.configuration.Configurable;
  -import org.apache.avalon.framework.configuration.Configuration;
  -import org.apache.avalon.framework.configuration.ConfigurationException;
  -import org.apache.avalon.framework.context.Context;
  -import org.apache.avalon.framework.context.Contextualizable;
  -import org.apache.avalon.framework.logger.AbstractLogEnabled;
  -import org.apache.avalon.phoenix.BlockContext;
  -
  -/**
  - * Builds SSLContexts with desired properties. Hides all the gory
  - * details of SSLContext productions behind nice Avalon
  - * interfaces. Married to Sun JCA implementation.
  - * <p>
  - * Configuration looks like:
  - * <pre>
  - * &lt;ssl-factory&gt;
  - *    &lt;keystore&gt;
  - *      &lt;file&gt;conf/keystore&lt;/file&gt; &lt;!-- keystore file location --&gt;
  - *      &lt;password&gt;&lt;/password&gt; &lt;!-- Key Store file password, only used to check keystore integrity --&gt;
  - *      &lt;key-password&gt;&lt;/key-password&gt; &lt;!-- Only required when you need to decrypt a private key --&gt;
  - *     &lt;type&gt;JKS&lt;/type&gt; &lt;!-- Key Store file format, defaults to JKS --&gt;
  - *     &lt;algorithm&gt;SunX509&lt;/algorithm&gt; &lt;!-- Cryptography provider ID, defaults to SunX509 --&gt;
  - *   &lt;/keystore&gt;
  - *   &lt;!-- SSL protocol to use, defaults to TLS, another possible value is SSL --&gt;
  - *   &lt;protocol&gt;TLS&lt;/protocol&gt;
  - * &lt;/ssl-factory&gt;
  - * </pre>
  - * </p>
  - * <p>
  - * Notes on keystore files. Absolute paths are supported. Relative
  - * paths are interpreted relative to .sar base directory. Defaults to
  - * conf/keystore. Since keystore usually contains sensitive keys it
  - * maybe beneficial to <b>not</b> include the keystores into the .sar
  - * files.
  - * </p>
  - * @author <a href="mailto:greg-avalon-apps at nest.cx">Greg Steuck</a>
  - */
  -public class SSLFactoryBuilder extends AbstractLogEnabled
  -    implements Configurable, Contextualizable, Disposable, Initializable
  -{
  -    private File m_baseDirectory;
  -    private File m_keystoreFile;
  -
  -    private String m_keystorePassword;
  -    private String m_keyPassword;
  -    private String m_protocol;
  -    private String m_provider;
  -    private String m_keystoreFormat;
  -
  -    private SSLContext m_ctx;
  -
  -    static
  -    {
  -        // Registers Sun's providers
  -        java.security.Security.addProvider( new sun.security.provider.Sun() );
  -        java.security.Security.addProvider( new com.sun.net.ssl.internal.ssl.Provider() );
  -    }
  -
  -    /**
  -     * Requires a BlockContext. We'll see how we end up expressing
  -     * these dependencies.
  -     */
  -    public void contextualize( final Context context )
  -    {
  -        final BlockContext blockContext = (BlockContext) context;
  -        m_baseDirectory = blockContext.getBaseDirectory();
  -    }
  -
  -    public void configure( final Configuration configuration )
  -        throws ConfigurationException
  -    {
  -        final Configuration storeConfig = configuration.getChild( "keystore" );
  -        final String fileName = storeConfig.getChild( "file" ).getValue( "conf/keystore" );
  -        final File configuredFile = new File( fileName );
  -        if ( ! configuredFile.isAbsolute() )
  -        {
  -            m_keystoreFile = new File ( m_baseDirectory, fileName );
  -        }
  -        else
  -        {
  -            m_keystoreFile = configuredFile;
  -        }
  -
  -        m_keystorePassword = storeConfig.getChild( "password" ).getValue( null );
  -        m_keyPassword = storeConfig.getChild( "key-password" ).getValue( null );
  -        // key is named incorrectly, left as is for compatibility
  -        m_provider = storeConfig.getChild( "algorithm" ).getValue( "SunX509" );
  -        // key is named incorrectly, left as is for compatibility
  -        m_keystoreFormat = storeConfig.getChild( "type" ).getValue( "JKS" );
  -        // ugly compatibility workaround follows
  -        m_protocol = configuration.getChild( "protocol" ).
  -            getValue( storeConfig.getChild( "protocol" ).getValue( "TLS" ) );
  -    }
  -
  -    /**
  -     * Produces a fresh ssl socket factory with configured parameters.
  -     */
  -    public SSLSocketFactory buildSocketFactory()
  -    {
  -        return m_ctx.getSocketFactory();
  -    }
  -
  -    /**
  -     * Produces a fresh ssl server socket factory with configured
  -     * parameters.
  -     */
  -    public SSLServerSocketFactory buildServerSocketFactory()
  -    {
  -        return m_ctx.getServerSocketFactory();
  -    }
  -
  -    public void initialize()
  -        throws IOException, GeneralSecurityException
  -    {
  -        final FileInputStream keyStream = new FileInputStream( m_keystoreFile );
  -        try
  -        {
  -            m_ctx = makeContext( keyStream, m_keystorePassword,
  -                               m_keyPassword, m_protocol,
  -                               m_provider, m_keystoreFormat );
  -        }
  -        finally
  -        {
  -            try
  -            {
  -                keyStream.close();
  -            }
  -            catch ( IOException e )
  -            {
  -                // avoids hiding exceptions from makeContext
  -                // by catching this IOException
  -                getLogger().error( "Error keyStream.close failed", e );
  -            }
  -        }
  -    }
  -
  -    public void dispose()
  -    {
  -        m_keystorePassword = null;
  -        m_keyPassword = null;
  -    }
  -
  -    /**
  -     * Creates an SSL context which uses the keys and certificates
  -     * provided by the given <tt>keyStream</tt>.  For simplicity the
  -     * same key stream (keystore) is used for both key and trust
  -     * factory.
  -     *
  -     * @param keyStream to read the keys from
  -     * @param keystorePassword password for the keystore, can be null
  -     *                      if integrity verification is not desired
  -     * @param keyPassword passphrase which unlocks the keys in the key file
  -     *        (should really be a char[] so that it can be cleaned after use)
  -     * @param protocol the standard name of the requested protocol
  -     * @param provider the standard name of the requested algorithm
  -     * @param keystoreFormat the type of keystore
  -     *
  -     * @return context configured with these keys and certificates
  -     * @throws IOException if files can't be read
  -     * @throws GeneralSecurityException is something goes wrong inside
  -     *                                  cryptography framework
  -     */
  -    private static SSLContext makeContext (InputStream keyStream,
  -                                           String keystorePassword,
  -                                           String keyPassword,
  -                                           String protocol,
  -                                           String provider,
  -                                           String keystoreFormat )
  -        throws IOException, GeneralSecurityException
  -    {
  -        final KeyStore keystore = loadKeystore( keyStream,
  -                                                keystorePassword,
  -                                                keystoreFormat );
  -        final KeyManagerFactory kmf = KeyManagerFactory.getInstance( provider );
  -        // even though undocumented Sun's implementation doesn't allow
  -        // null passphrases, but zero sized arrays are OK
  -        final char [] passChars = ( keyPassword != null ) ?
  -            keyPassword.toCharArray() : new char [0];
  -        try
  -        {
  -            kmf.init( keystore, passChars );
  -        }
  -        finally
  -        {
  -            Arrays.fill( passChars, (char) 0 );
  -        }
  -
  -        final TrustManagerFactory tmf =
  -            TrustManagerFactory.getInstance( provider );
  -        tmf.init( keystore );
  -
  -        final SSLContext result = SSLContext.getInstance( protocol );
  -        result.init( kmf.getKeyManagers(),
  -                     tmf.getTrustManagers(),
  -                     new java.security.SecureRandom() );
  -        return result;
  -    }
  -
  -    /**
  -     * Builds a keystore loaded from the given stream. The passphrase
  -     * is used to verify the keystore file integrity.
  -     * @param file to load from
  -     * @param passphrase for the store integrity verification (or null if
  -     *                   integrity check is not wanted)
  -     * @param keystoreFormat the type of keystore
  -     * @return loaded key store
  -     * @throws IOException if file can not be read
  -     * @throws GeneralSecurityException if key store can't be built
  -     */
  -    private static KeyStore loadKeystore( InputStream keyStream,
  -                                          String passphrase,
  -                                          String keystoreFormat )
  -        throws GeneralSecurityException, IOException
  -    {
  -        final KeyStore ks = KeyStore.getInstance( keystoreFormat );
  -
  -        if ( passphrase != null )
  -        {
  -            final char [] passChars = passphrase.toCharArray();
  -            try
  -            {
  -                ks.load( keyStream, passChars );
  -            }
  -            finally
  -            {
  -                Arrays.fill( passChars, (char) 0 );
  -            }
  -        }
  -        else
  -        {
  -            ks.load( keyStream, null );
  -        }
  -
  -        return ks;
  -    }
  -}
  +/*
  + * 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.avalon.cornerstone.blocks.sockets;
  +
  +import com.sun.net.ssl.KeyManagerFactory;
  +import com.sun.net.ssl.SSLContext;
  +import com.sun.net.ssl.TrustManagerFactory;
  +import java.io.File;
  +import java.io.FileInputStream;
  +import java.io.IOException;
  +import java.io.InputStream;
  +import java.security.GeneralSecurityException;
  +import java.security.KeyStore;
  +import java.util.Arrays;
  +import javax.net.ssl.SSLServerSocketFactory;
  +import javax.net.ssl.SSLSocketFactory;
  +import org.apache.avalon.framework.activity.Disposable;
  +import org.apache.avalon.framework.activity.Initializable;
  +import org.apache.avalon.framework.configuration.Configurable;
  +import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.avalon.framework.context.Context;
  +import org.apache.avalon.framework.context.Contextualizable;
  +import org.apache.avalon.framework.logger.AbstractLogEnabled;
  +import org.apache.avalon.framework.context.*;
  +
  +/**
  + * Builds SSLContexts with desired properties. Hides all the gory
  + * details of SSLContext productions behind nice Avalon
  + * interfaces. Married to Sun JCA implementation.
  + * <p>
  + * Configuration looks like:
  + * <pre>
  + * &lt;ssl-factory&gt;
  + *    &lt;keystore&gt;
  + *      &lt;file&gt;conf/keystore&lt;/file&gt; &lt;!-- keystore file location --&gt;
  + *      &lt;password&gt;&lt;/password&gt; &lt;!-- Key Store file password, only used to check keystore integrity --&gt;
  + *      &lt;key-password&gt;&lt;/key-password&gt; &lt;!-- Only required when you need to decrypt a private key --&gt;
  + *     &lt;type&gt;JKS&lt;/type&gt; &lt;!-- Key Store file format, defaults to JKS --&gt;
  + *     &lt;algorithm&gt;SunX509&lt;/algorithm&gt; &lt;!-- Cryptography provider ID, defaults to SunX509 --&gt;
  + *   &lt;/keystore&gt;
  + *   &lt;!-- SSL protocol to use, defaults to TLS, another possible value is SSL --&gt;
  + *   &lt;protocol&gt;TLS&lt;/protocol&gt;
  + * &lt;/ssl-factory&gt;
  + * </pre>
  + * </p>
  + * <p>
  + * Notes on keystore files. Absolute paths are supported. Relative
  + * paths are interpreted relative to .sar base directory. Defaults to
  + * conf/keystore. Since keystore usually contains sensitive keys it
  + * maybe beneficial to <b>not</b> include the keystores into the .sar
  + * files.
  + * </p>
  + * @author <a href="mailto:greg-avalon-apps at nest.cx">Greg Steuck</a>
  + */
  +public class SSLFactoryBuilder extends AbstractLogEnabled
  +    implements Configurable, Contextualizable, Disposable, Initializable
  +{
  +    private File m_baseDirectory;
  +    private File m_keystoreFile;
  +
  +    private String m_keystorePassword;
  +    private String m_keyPassword;
  +    private String m_protocol;
  +    private String m_provider;
  +    private String m_keystoreFormat;
  +
  +    private SSLContext m_ctx;
  +
  +    static
  +    {
  +        // Registers Sun's providers
  +        java.security.Security.addProvider( new sun.security.provider.Sun() );
  +        java.security.Security.addProvider( new com.sun.net.ssl.internal.ssl.Provider() );
  +    }
  +
  +    /**
  +     * Requires a BlockContext. We'll see how we end up expressing
  +     * these dependencies.
  +     */
  +    public void contextualize( final Context context ) throws ContextException
  +    {
  +        m_baseDirectory = (File) context.get("app.home");
  +    }
  +
  +    public void configure( final Configuration configuration )
  +        throws ConfigurationException
  +    {
  +        final Configuration storeConfig = configuration.getChild( "keystore" );
  +        final String fileName = storeConfig.getChild( "file" ).getValue( "conf/keystore" );
  +        final File configuredFile = new File( fileName );
  +        if ( ! configuredFile.isAbsolute() )
  +        {
  +            m_keystoreFile = new File ( m_baseDirectory, fileName );
  +        }
  +        else
  +        {
  +            m_keystoreFile = configuredFile;
  +        }
  +
  +        m_keystorePassword = storeConfig.getChild( "password" ).getValue( null );
  +        m_keyPassword = storeConfig.getChild( "key-password" ).getValue( null );
  +        // key is named incorrectly, left as is for compatibility
  +        m_provider = storeConfig.getChild( "algorithm" ).getValue( "SunX509" );
  +        // key is named incorrectly, left as is for compatibility
  +        m_keystoreFormat = storeConfig.getChild( "type" ).getValue( "JKS" );
  +        // ugly compatibility workaround follows
  +        m_protocol = configuration.getChild( "protocol" ).
  +            getValue( storeConfig.getChild( "protocol" ).getValue( "TLS" ) );
  +    }
  +
  +    /**
  +     * Produces a fresh ssl socket factory with configured parameters.
  +     */
  +    public SSLSocketFactory buildSocketFactory()
  +    {
  +        return m_ctx.getSocketFactory();
  +    }
  +
  +    /**
  +     * Produces a fresh ssl server socket factory with configured
  +     * parameters.
  +     */
  +    public SSLServerSocketFactory buildServerSocketFactory()
  +    {
  +        return m_ctx.getServerSocketFactory();
  +    }
  +
  +    public void initialize()
  +        throws IOException, GeneralSecurityException
  +    {
  +        final FileInputStream keyStream = new FileInputStream( m_keystoreFile );
  +        try
  +        {
  +            m_ctx = makeContext( keyStream, m_keystorePassword,
  +                               m_keyPassword, m_protocol,
  +                               m_provider, m_keystoreFormat );
  +        }
  +        finally
  +        {
  +            try
  +            {
  +                keyStream.close();
  +            }
  +            catch ( IOException e )
  +            {
  +                // avoids hiding exceptions from makeContext
  +                // by catching this IOException
  +                getLogger().error( "Error keyStream.close failed", e );
  +            }
  +        }
  +    }
  +
  +    public void dispose()
  +    {
  +        m_keystorePassword = null;
  +        m_keyPassword = null;
  +    }
  +
  +    /**
  +     * Creates an SSL context which uses the keys and certificates
  +     * provided by the given <tt>keyStream</tt>.  For simplicity the
  +     * same key stream (keystore) is used for both key and trust
  +     * factory.
  +     *
  +     * @param keyStream to read the keys from
  +     * @param keystorePassword password for the keystore, can be null
  +     *                      if integrity verification is not desired
  +     * @param keyPassword passphrase which unlocks the keys in the key file
  +     *        (should really be a char[] so that it can be cleaned after use)
  +     * @param protocol the standard name of the requested protocol
  +     * @param provider the standard name of the requested algorithm
  +     * @param keystoreFormat the type of keystore
  +     *
  +     * @return context configured with these keys and certificates
  +     * @throws IOException if files can't be read
  +     * @throws GeneralSecurityException is something goes wrong inside
  +     *                                  cryptography framework
  +     */
  +    private static SSLContext makeContext (InputStream keyStream,
  +                                           String keystorePassword,
  +                                           String keyPassword,
  +                                           String protocol,
  +                                           String provider,
  +                                           String keystoreFormat )
  +        throws IOException, GeneralSecurityException
  +    {
  +        final KeyStore keystore = loadKeystore( keyStream,
  +                                                keystorePassword,
  +                                                keystoreFormat );
  +        final KeyManagerFactory kmf = KeyManagerFactory.getInstance( provider );
  +        // even though undocumented Sun's implementation doesn't allow
  +        // null passphrases, but zero sized arrays are OK
  +        final char [] passChars = ( keyPassword != null ) ?
  +            keyPassword.toCharArray() : new char [0];
  +        try
  +        {
  +            kmf.init( keystore, passChars );
  +        }
  +        finally
  +        {
  +            Arrays.fill( passChars, (char) 0 );
  +        }
  +
  +        final TrustManagerFactory tmf =
  +            TrustManagerFactory.getInstance( provider );
  +        tmf.init( keystore );
  +
  +        final SSLContext result = SSLContext.getInstance( protocol );
  +        result.init( kmf.getKeyManagers(),
  +                     tmf.getTrustManagers(),
  +                     new java.security.SecureRandom() );
  +        return result;
  +    }
  +
  +    /**
  +     * Builds a keystore loaded from the given stream. The passphrase
  +     * is used to verify the keystore file integrity.
  +     * @param file to load from
  +     * @param passphrase for the store integrity verification (or null if
  +     *                   integrity check is not wanted)
  +     * @param keystoreFormat the type of keystore
  +     * @return loaded key store
  +     * @throws IOException if file can not be read
  +     * @throws GeneralSecurityException if key store can't be built
  +     */
  +    private static KeyStore loadKeystore( InputStream keyStream,
  +                                          String passphrase,
  +                                          String keystoreFormat )
  +        throws GeneralSecurityException, IOException
  +    {
  +        final KeyStore ks = KeyStore.getInstance( keystoreFormat );
  +
  +        if ( passphrase != null )
  +        {
  +            final char [] passChars = passphrase.toCharArray();
  +            try
  +            {
  +                ks.load( keyStream, passChars );
  +            }
  +            finally
  +            {
  +                Arrays.fill( passChars, (char) 0 );
  +            }
  +        }
  +        else
  +        {
  +            ks.load( keyStream, null );
  +        }
  +
  +        return ks;
  +    }
  +}
  
  
  
  1.22      +301 -301  jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/transport/publishing/AbstractPublisher.java
  
  Index: AbstractPublisher.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/transport/publishing/AbstractPublisher.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- AbstractPublisher.java	2 Oct 2002 01:52:16 -0000	1.21
  +++ AbstractPublisher.java	23 Dec 2002 17:52:40 -0000	1.22
  @@ -1,301 +1,301 @@
  -/*
  - * 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.avalon.cornerstone.blocks.transport.publishing;
  -
  -import java.io.File;
  -import java.net.MalformedURLException;
  -import java.net.URL;
  -import java.util.StringTokenizer;
  -import java.util.Vector;
  -import org.apache.avalon.framework.activity.Initializable;
  -import org.apache.avalon.framework.activity.Startable;
  -import org.apache.avalon.framework.configuration.Configurable;
  -import org.apache.avalon.framework.configuration.Configuration;
  -import org.apache.avalon.framework.configuration.ConfigurationException;
  -import org.apache.avalon.framework.context.Context;
  -import org.apache.avalon.framework.context.Contextualizable;
  -import org.apache.avalon.framework.logger.AbstractLogEnabled;
  -import org.apache.avalon.framework.service.ServiceException;
  -import org.apache.avalon.framework.service.ServiceManager;
  -import org.apache.avalon.framework.service.Serviceable;
  -import org.apache.avalon.phoenix.BlockContext;
  -import org.apache.excalibur.altrmi.common.MethodRequest;
  -import org.apache.excalibur.altrmi.server.AltrmiAuthenticator;
  -import org.apache.excalibur.altrmi.server.AltrmiPublisher;
  -import org.apache.excalibur.altrmi.server.ClassRetriever;
  -import org.apache.excalibur.altrmi.server.MethodInvocationHandler;
  -import org.apache.excalibur.altrmi.server.PublicationDescription;
  -import org.apache.excalibur.altrmi.server.PublicationException;
  -import org.apache.excalibur.altrmi.server.impl.AbstractServer;
  -import org.apache.excalibur.altrmi.server.impl.classretrievers.AbstractDynamicGeneratorClassRetriever;
  -import org.apache.excalibur.altrmi.server.impl.classretrievers.BcelDynamicGeneratorClassRetriever;
  -import org.apache.excalibur.altrmi.server.impl.classretrievers.JarFileClassRetriever;
  -import org.apache.excalibur.altrmi.server.impl.classretrievers.NoClassRetriever;
  -
  -/**
  - * Abstract Publisher.
  - *
  - * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @author Thomas Kiesgen
  - * @version $Revision$
  - */
  -public abstract class AbstractPublisher
  -    extends AbstractLogEnabled
  -    implements AltrmiPublisher, Startable, Serviceable, Contextualizable, Configurable,
  -    Initializable
  -{
  -    private AbstractServer m_abstractServer;
  -    private ClassRetriever m_classRetriever;
  -    private AltrmiAuthenticator m_altrmiAuthenticator;
  -    protected File m_baseDirectory;
  -    private boolean m_isDynamicPublisher = false;
  -
  -    /**
  -     *
  -     * @param configuration
  -     * @throws ConfigurationException
  -     */
  -    public void configure( Configuration configuration )
  -        throws ConfigurationException
  -    {
  -        String classRetrieverType = configuration.getChild( "classRetrieverType" ).getValue();
  -
  -        if( classRetrieverType.equals( "jarFile" ) )
  -        {
  -            StringTokenizer st =
  -                new StringTokenizer( configuration.getChild( "gerneratedClassJarURLs" ).getValue(),
  -                                     "," );
  -            Vector vector = new Vector();
  -
  -            while( st.hasMoreTokens() )
  -            {
  -                try
  -                {
  -                    String url = st.nextToken();
  -
  -                    if( url.startsWith( "./" ) )
  -                    {
  -                        File file = new File( m_baseDirectory, url.substring( 2, url.length() ) );
  -
  -                        vector.add( file.toURL() );
  -                    }
  -                    else
  -                    {
  -                        vector.add( new URL( url ) );
  -                    }
  -                }
  -                catch( MalformedURLException e )
  -                {
  -                    getLogger()
  -                        .debug( "Can't create URL from config element 'gerneratedClassJarURLs'",
  -                                e );
  -                }
  -            }
  -
  -            URL[] urls = new URL[ vector.size() ];
  -
  -            vector.copyInto( urls );
  -
  -            m_classRetriever = new JarFileClassRetriever( urls );
  -        }
  -        else if( classRetrieverType.equals( "none" ) )
  -        {
  -            m_classRetriever = new NoClassRetriever();
  -        }
  -        else if( classRetrieverType.equals( "bcel" ) )
  -        {
  -            AbstractDynamicGeneratorClassRetriever generator = new BcelDynamicGeneratorClassRetriever();
  -            File classGenDir = new File( m_baseDirectory, configuration.getChild( "classGenDir" ).getValue( "" ) );
  -            generator.setClassGenDir( classGenDir.getAbsolutePath() );
  -            m_classRetriever = generator;
  -
  -            m_isDynamicPublisher = true;
  -            getLogger().debug( "setting classgen dir for generator to " + classGenDir.getAbsolutePath() );
  -            getLogger().debug( "setting class retriever to bcel dynamic generator" );
  -        }
  -
  -
  -        else
  -        {
  -            throw new ConfigurationException(
  -                "classRetrieverType must be 'bcel', 'jarFile' or 'none'" );
  -        }
  -    }
  -
  -    /**
  -     * contextualize as per Contextualizable interface
  -     * @param context
  -     */
  -    public void contextualize( final Context context )
  -    {
  -        m_baseDirectory = ( (BlockContext)context ).getBaseDirectory();
  -    }
  -
  -    /**
  -     * Service as per Serviceable interface
  -     * @param manager a service manager
  -     * @throws ServiceException if a problem during servicing
  -     * @phoenix:dependency name="org.apache.excalibur.altrmi.server.AltrmiAuthenticator"
  -     */
  -    public void service( ServiceManager manager )
  -        throws ServiceException
  -    {
  -        m_altrmiAuthenticator =
  -            (AltrmiAuthenticator)manager.lookup( AltrmiAuthenticator.class.getName() );
  -    }
  -
  -    /**
  -     * initialize as per Initializable interface
  -     * @throws Exception
  -     */
  -    public void initialize() throws Exception
  -    {
  -        m_abstractServer.setClassRetriever( m_classRetriever );
  -        m_abstractServer.setAuthenticator( m_altrmiAuthenticator );
  -    }
  -
  -    /**
  -     *
  -     * @param implementation
  -     * @param asName
  -     * @param interfaceToExpose
  -     * @throws PublicationException
  -     */
  -    public void publish( Object implementation, String asName, Class interfaceToExpose )
  -        throws PublicationException
  -    {
  -        if( getLogger().isDebugEnabled() )
  -            getLogger().debug( "Publishing object [as: " + asName + ", impl: " + implementation
  -                              + ", interf: "+ interfaceToExpose + "]" );
  -
  -        if( m_isDynamicPublisher )
  -        {
  -            ( ( AbstractDynamicGeneratorClassRetriever ) m_classRetriever ).generate( asName, interfaceToExpose, this.getClass().getClassLoader() );
  -                if( getLogger().isDebugEnabled() )
  -                {
  -                    getLogger().debug( "generated dynamic proxy for published interface " + asName );
  -                }
  -        }
  -
  -        m_abstractServer.publish( implementation, asName, interfaceToExpose );
  -    }
  -
  -    /**
  -     * Publish an service
  -     * @param implementation
  -     * @param asName
  -     * @param publicationDescription
  -     * @throws PublicationException
  -     */
  -    public void publish(
  -        Object implementation, String asName, PublicationDescription publicationDescription )
  -        throws PublicationException
  -    {
  -        if( getLogger().isDebugEnabled() )
  -            getLogger().debug( "Publishing object [as: " + asName + ", impl: " + implementation + "]" );
  -
  -        if( m_isDynamicPublisher )
  -        {
  -            ( ( AbstractDynamicGeneratorClassRetriever ) m_classRetriever ).generate( asName, publicationDescription, this.getClass().getClassLoader() );
  -                if( getLogger().isDebugEnabled() )
  -                {
  -                    getLogger().debug( "generated dynamic proxy for published interface " + asName );
  -                }
  -        }
  -
  -
  -
  -        m_abstractServer.publish( implementation, asName, publicationDescription );
  -    }
  -
  -    /**
  -     *
  -     * @param object
  -     * @param asName
  -     * @throws PublicationException
  -     */
  -    public void unPublish( Object object, String asName ) throws PublicationException
  -    {
  -        if( getLogger().isDebugEnabled() )
  -            getLogger().debug( "Unpublishing object [nane: " + asName + ", impl: " + object + "]" );
  -
  -        m_abstractServer.unPublish( object, asName );
  -    }
  -
  -    /**
  -     *
  -     * @param object
  -     * @param asName
  -     * @param o1
  -     * @throws PublicationException
  -     */
  -    public void replacePublished( Object object, String asName, Object o1 ) throws PublicationException
  -    {
  -        if( getLogger().isDebugEnabled() )
  -            getLogger().debug( "Replacing published object [nane: " + asName + ", existing: " + object + ", new: " + o1 + "]" );
  -
  -        m_abstractServer.replacePublished( object, asName, o1 );
  -    }
  -
  -    /**
  -     *
  -     * @throws Exception
  -     */
  -    public void start() throws Exception
  -    {
  -        m_abstractServer.start();
  -    }
  -
  -    /**
  -     *
  -     * @throws Exception
  -     */
  -    public void stop() throws Exception
  -    {
  -        m_abstractServer.stop();
  -    }
  -
  -    /**
  -     *
  -     * @param request
  -     * @param publishedName
  -     * @return
  -     */
  -    public MethodInvocationHandler getMethodInvocationHandler( MethodRequest request, String publishedName )
  -    {
  -        return m_abstractServer.getMethodInvocationHandler( request, publishedName );
  -    }
  -
  -    /**
  -     *
  -     * @param publishedName
  -     * @return
  -     */
  -    public MethodInvocationHandler getMethodInvocationHandler(String publishedName)
  -    {
  -        return m_abstractServer.getMethodInvocationHandler( publishedName );
  -    }
  -
  -    /**
  -     *
  -     * @return
  -     */
  -    protected AbstractServer getAbstractServer()
  -    {
  -        return m_abstractServer;
  -    }
  -
  -    /**
  -     *
  -     * @param abstractServer
  -     */
  -    protected void setAbstractServer( AbstractServer abstractServer )
  -    {
  -        m_abstractServer = abstractServer;
  -    }
  -}
  +/*
  + * 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.avalon.cornerstone.blocks.transport.publishing;
  +
  +import java.io.File;
  +import java.net.MalformedURLException;
  +import java.net.URL;
  +import java.util.StringTokenizer;
  +import java.util.Vector;
  +import org.apache.avalon.framework.activity.Initializable;
  +import org.apache.avalon.framework.activity.Startable;
  +import org.apache.avalon.framework.configuration.Configurable;
  +import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.avalon.framework.context.Context;
  +import org.apache.avalon.framework.context.Contextualizable;
  +import org.apache.avalon.framework.logger.AbstractLogEnabled;
  +import org.apache.avalon.framework.service.ServiceException;
  +import org.apache.avalon.framework.service.ServiceManager;
  +import org.apache.avalon.framework.service.Serviceable;
  +import org.apache.excalibur.altrmi.common.MethodRequest;
  +import org.apache.excalibur.altrmi.server.AltrmiAuthenticator;
  +import org.apache.excalibur.altrmi.server.AltrmiPublisher;
  +import org.apache.excalibur.altrmi.server.ClassRetriever;
  +import org.apache.excalibur.altrmi.server.MethodInvocationHandler;
  +import org.apache.excalibur.altrmi.server.PublicationDescription;
  +import org.apache.excalibur.altrmi.server.PublicationException;
  +import org.apache.excalibur.altrmi.server.impl.AbstractServer;
  +import org.apache.excalibur.altrmi.server.impl.classretrievers.AbstractDynamicGeneratorClassRetriever;
  +import org.apache.excalibur.altrmi.server.impl.classretrievers.BcelDynamicGeneratorClassRetriever;
  +import org.apache.excalibur.altrmi.server.impl.classretrievers.JarFileClassRetriever;
  +import org.apache.excalibur.altrmi.server.impl.classretrievers.NoClassRetriever;
  +import org.apache.avalon.framework.context.ContextException;
  +
  +/**
  + * Abstract Publisher.
  + *
  + * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  + * @author Thomas Kiesgen
  + * @version $Revision$
  + */
  +public abstract class AbstractPublisher
  +    extends AbstractLogEnabled
  +    implements AltrmiPublisher, Startable, Serviceable, Contextualizable, Configurable,
  +    Initializable
  +{
  +    private AbstractServer m_abstractServer;
  +    private ClassRetriever m_classRetriever;
  +    private AltrmiAuthenticator m_altrmiAuthenticator;
  +    protected File m_baseDirectory;
  +    private boolean m_isDynamicPublisher = false;
  +
  +    /**
  +     *
  +     * @param configuration
  +     * @throws ConfigurationException
  +     */
  +    public void configure( Configuration configuration )
  +        throws ConfigurationException
  +    {
  +        String classRetrieverType = configuration.getChild( "classRetrieverType" ).getValue();
  +
  +        if( classRetrieverType.equals( "jarFile" ) )
  +        {
  +            StringTokenizer st =
  +                new StringTokenizer( configuration.getChild( "gerneratedClassJarURLs" ).getValue(),
  +                                     "," );
  +            Vector vector = new Vector();
  +
  +            while( st.hasMoreTokens() )
  +            {
  +                try
  +                {
  +                    String url = st.nextToken();
  +
  +                    if( url.startsWith( "./" ) )
  +                    {
  +                        File file = new File( m_baseDirectory, url.substring( 2, url.length() ) );
  +
  +                        vector.add( file.toURL() );
  +                    }
  +                    else
  +                    {
  +                        vector.add( new URL( url ) );
  +                    }
  +                }
  +                catch( MalformedURLException e )
  +                {
  +                    getLogger()
  +                        .debug( "Can't create URL from config element 'gerneratedClassJarURLs'",
  +                                e );
  +                }
  +            }
  +
  +            URL[] urls = new URL[ vector.size() ];
  +
  +            vector.copyInto( urls );
  +
  +            m_classRetriever = new JarFileClassRetriever( urls );
  +        }
  +        else if( classRetrieverType.equals( "none" ) )
  +        {
  +            m_classRetriever = new NoClassRetriever();
  +        }
  +        else if( classRetrieverType.equals( "bcel" ) )
  +        {
  +            AbstractDynamicGeneratorClassRetriever generator = new BcelDynamicGeneratorClassRetriever();
  +            File classGenDir = new File( m_baseDirectory, configuration.getChild( "classGenDir" ).getValue( "" ) );
  +            generator.setClassGenDir( classGenDir.getAbsolutePath() );
  +            m_classRetriever = generator;
  +
  +            m_isDynamicPublisher = true;
  +            getLogger().debug( "setting classgen dir for generator to " + classGenDir.getAbsolutePath() );
  +            getLogger().debug( "setting class retriever to bcel dynamic generator" );
  +        }
  +
  +
  +        else
  +        {
  +            throw new ConfigurationException(
  +                "classRetrieverType must be 'bcel', 'jarFile' or 'none'" );
  +        }
  +    }
  +
  +    /**
  +     * contextualize as per Contextualizable interface
  +     * @param context
  +     */
  +    public void contextualize( final Context context ) throws ContextException
  +    {
  +        m_baseDirectory = ( File ) context.get("app.home");
  +    }
  +
  +    /**
  +     * Service as per Serviceable interface
  +     * @param manager a service manager
  +     * @throws ServiceException if a problem during servicing
  +     * @phoenix:dependency name="org.apache.excalibur.altrmi.server.AltrmiAuthenticator"
  +     */
  +    public void service( ServiceManager manager )
  +        throws ServiceException
  +    {
  +        m_altrmiAuthenticator =
  +            (AltrmiAuthenticator)manager.lookup( AltrmiAuthenticator.class.getName() );
  +    }
  +
  +    /**
  +     * initialize as per Initializable interface
  +     * @throws Exception
  +     */
  +    public void initialize() throws Exception
  +    {
  +        m_abstractServer.setClassRetriever( m_classRetriever );
  +        m_abstractServer.setAuthenticator( m_altrmiAuthenticator );
  +    }
  +
  +    /**
  +     *
  +     * @param implementation
  +     * @param asName
  +     * @param interfaceToExpose
  +     * @throws PublicationException
  +     */
  +    public void publish( Object implementation, String asName, Class interfaceToExpose )
  +        throws PublicationException
  +    {
  +        if( getLogger().isDebugEnabled() )
  +            getLogger().debug( "Publishing object [as: " + asName + ", impl: " + implementation
  +                              + ", interf: "+ interfaceToExpose + "]" );
  +
  +        if( m_isDynamicPublisher )
  +        {
  +            ( ( AbstractDynamicGeneratorClassRetriever ) m_classRetriever ).generate( asName, interfaceToExpose, this.getClass().getClassLoader() );
  +                if( getLogger().isDebugEnabled() )
  +                {
  +                    getLogger().debug( "generated dynamic proxy for published interface " + asName );
  +                }
  +        }
  +
  +        m_abstractServer.publish( implementation, asName, interfaceToExpose );
  +    }
  +
  +    /**
  +     * Publish an service
  +     * @param implementation
  +     * @param asName
  +     * @param publicationDescription
  +     * @throws PublicationException
  +     */
  +    public void publish(
  +        Object implementation, String asName, PublicationDescription publicationDescription )
  +        throws PublicationException
  +    {
  +        if( getLogger().isDebugEnabled() )
  +            getLogger().debug( "Publishing object [as: " + asName + ", impl: " + implementation + "]" );
  +
  +        if( m_isDynamicPublisher )
  +        {
  +            ( ( AbstractDynamicGeneratorClassRetriever ) m_classRetriever ).generate( asName, publicationDescription, this.getClass().getClassLoader() );
  +                if( getLogger().isDebugEnabled() )
  +                {
  +                    getLogger().debug( "generated dynamic proxy for published interface " + asName );
  +                }
  +        }
  +
  +
  +
  +        m_abstractServer.publish( implementation, asName, publicationDescription );
  +    }
  +
  +    /**
  +     *
  +     * @param object
  +     * @param asName
  +     * @throws PublicationException
  +     */
  +    public void unPublish( Object object, String asName ) throws PublicationException
  +    {
  +        if( getLogger().isDebugEnabled() )
  +            getLogger().debug( "Unpublishing object [nane: " + asName + ", impl: " + object + "]" );
  +
  +        m_abstractServer.unPublish( object, asName );
  +    }
  +
  +    /**
  +     *
  +     * @param object
  +     * @param asName
  +     * @param o1
  +     * @throws PublicationException
  +     */
  +    public void replacePublished( Object object, String asName, Object o1 ) throws PublicationException
  +    {
  +        if( getLogger().isDebugEnabled() )
  +            getLogger().debug( "Replacing published object [nane: " + asName + ", existing: " + object + ", new: " + o1 + "]" );
  +
  +        m_abstractServer.replacePublished( object, asName, o1 );
  +    }
  +
  +    /**
  +     *
  +     * @throws Exception
  +     */
  +    public void start() throws Exception
  +    {
  +        m_abstractServer.start();
  +    }
  +
  +    /**
  +     *
  +     * @throws Exception
  +     */
  +    public void stop() throws Exception
  +    {
  +        m_abstractServer.stop();
  +    }
  +
  +    /**
  +     *
  +     * @param request
  +     * @param publishedName
  +     * @return
  +     */
  +    public MethodInvocationHandler getMethodInvocationHandler( MethodRequest request, String publishedName )
  +    {
  +        return m_abstractServer.getMethodInvocationHandler( request, publishedName );
  +    }
  +
  +    /**
  +     *
  +     * @param publishedName
  +     * @return
  +     */
  +    public MethodInvocationHandler getMethodInvocationHandler(String publishedName)
  +    {
  +        return m_abstractServer.getMethodInvocationHandler( publishedName );
  +    }
  +
  +    /**
  +     *
  +     * @return
  +     */
  +    protected AbstractServer getAbstractServer()
  +    {
  +        return m_abstractServer;
  +    }
  +
  +    /**
  +     *
  +     * @param abstractServer
  +     */
  +    protected void setAbstractServer( AbstractServer abstractServer )
  +    {
  +        m_abstractServer = abstractServer;
  +    }
  +}
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message