avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: avalon-excalibur/fortress/examples/src/java/org/apache/avalon/fortress/examples/extended/components ExtendedComponentImpl.java
Date Fri, 30 May 2003 20:55:10 GMT
bloritsch    2003/05/30 13:55:10

  Modified:    fortress/examples/src/java/org/apache/avalon/fortress/examples/extended
                        ExtendedContainer.xconf ExtendedContainer.java
                        Main.java
               fortress/examples/src/java/org/apache/avalon/fortress/examples/viewer
                        Main.java
               fortress/examples/src/java/org/apache/avalon/fortress/examples/swing
                        Main.java
               fortress/examples/src/java/org/apache/avalon/fortress/examples/components
                        TranslatorImpl.java
               fortress/examples/src/java/org/apache/avalon/fortress/examples/servlet
                        servlet.java
               fortress/examples/src/java/org/apache/avalon/fortress/examples/extended/components
                        ExtendedComponentImpl.java
  Removed:     fortress/examples/src/java/org/apache/avalon/fortress/examples/extended
                        ExtendedContainer.roles
               fortress/examples/src/java/org/apache/avalon/fortress/examples/viewer
                        ComponentViewer.roles
               fortress/examples/src/java/org/apache/avalon/fortress/examples/swing
                        SwingContainer.roles
               fortress/examples/src/java/org/apache/avalon/fortress/examples/servlet
                        ServletContainer.roles
  Log:
  Update all the examples to be a better representation of how to do things.
  
  Revision  Changes    Path
  1.2       +1 -4      avalon-excalibur/fortress/examples/src/java/org/apache/avalon/fortress/examples/extended/ExtendedContainer.xconf
  
  Index: ExtendedContainer.xconf
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/examples/src/java/org/apache/avalon/fortress/examples/extended/ExtendedContainer.xconf,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ExtendedContainer.xconf	28 Jan 2003 21:19:18 -0000	1.1
  +++ ExtendedContainer.xconf	30 May 2003 20:55:09 -0000	1.2
  @@ -1,7 +1,4 @@
   <test>
  -  <component id="extended-component"
  -     class="org.apache.avalon.fortress.examples.extended.components.ExtendedComponentImpl"
  -     logger="extended-component">
  -  </component>
  +    <extended-component id="extended-component"/>
   </test>
   
  
  
  
  1.8       +4 -10     avalon-excalibur/fortress/examples/src/java/org/apache/avalon/fortress/examples/extended/ExtendedContainer.java
  
  Index: ExtendedContainer.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/examples/src/java/org/apache/avalon/fortress/examples/extended/ExtendedContainer.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ExtendedContainer.java	11 Apr 2003 07:36:20 -0000	1.7
  +++ ExtendedContainer.java	30 May 2003 20:55:09 -0000	1.8
  @@ -50,18 +50,12 @@
   package org.apache.avalon.fortress.examples.extended;
   
   import org.apache.avalon.fortress.examples.extended.extensions.Extensions;
  +import org.apache.avalon.fortress.examples.extended.components.ExtendedComponent;
  +import org.apache.avalon.fortress.impl.DefaultContainer;
   
   public final class ExtendedContainer
  -    extends org.apache.avalon.fortress.impl.DefaultContainer
  +    extends DefaultContainer
   {
  -    public void initialize()
  -        throws Exception
  -    {
  -        super.initialize();
  -
  -        m_extManager.addAccessorExtension( new Extensions() );
  -    }
  -
       public void doLookups()
           throws Exception
       {
  @@ -69,7 +63,7 @@
   
           for( int i = 0; i < 10; ++i )
           {
  -            org.apache.avalon.fortress.examples.extended.components.ExtendedComponent comp
= (org.apache.avalon.fortress.examples.extended.components.ExtendedComponent)m_serviceManager.lookup(
org.apache.avalon.fortress.examples.extended.components.ExtendedComponent.ROLE );
  +            ExtendedComponent comp = (ExtendedComponent)m_serviceManager.lookup( ExtendedComponent.ROLE
);
               m_serviceManager.release( comp );
           }
   
  
  
  
  1.7       +15 -5     avalon-excalibur/fortress/examples/src/java/org/apache/avalon/fortress/examples/extended/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/examples/src/java/org/apache/avalon/fortress/examples/extended/Main.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Main.java	22 Mar 2003 12:46:31 -0000	1.6
  +++ Main.java	30 May 2003 20:55:09 -0000	1.7
  @@ -50,9 +50,12 @@
   package org.apache.avalon.fortress.examples.extended;
   
   import org.apache.avalon.fortress.ContainerManager;
  +import org.apache.avalon.fortress.examples.extended.extensions.Extensions;
   import org.apache.avalon.fortress.impl.DefaultContainerManager;
   import org.apache.avalon.fortress.util.FortressConfig;
  +import org.apache.avalon.fortress.util.LifecycleExtensionManager;
   import org.apache.avalon.framework.container.ContainerUtil;
  +import org.apache.avalon.framework.logger.NullLogger;
   
   /**
    * Fortress container example with custom extensions
  @@ -73,12 +76,10 @@
           throws Exception
       {
           FortressConfig config = new FortressConfig();
  -        config.setContainerClass( ExtendedContainer.class.getName() );
  -        config.setContextDirectory( "./" );
  -        config.setWorkDirectory( "./" );
  +        config.setContainerClass( ExtendedContainer.class );
           config.setContainerConfiguration( "resource://org/apache/avalon/fortress/examples/extended/ExtendedContainer.xconf"
);
           config.setLoggerManagerConfiguration( "resource://org/apache/avalon/fortress/examples/extended/ExtendedContainer.xlog"
);
  -        config.setRoleManagerConfiguration( "resource://org/apache/avalon/fortress/examples/extended/ExtendedContainer.roles"
);
  +        setupExtensions(config);
   
           final ContainerManager cm = new DefaultContainerManager( config.getContext() );
           ContainerUtil.initialize( cm );
  @@ -88,6 +89,15 @@
           m_container.doLookups();
   
           ContainerUtil.dispose( cm );
  +    }
  +
  +    private static void setupExtensions( FortressConfig config )
  +    {
  +        LifecycleExtensionManager extensions = new LifecycleExtensionManager();
  +        extensions.enableLogging(new NullLogger());
  +        extensions.addAccessorExtension( new Extensions() );
  +
  +        config.setLifecycleExtensionManager(extensions);
       }
   }
   
  
  
  
  1.8       +12 -14    avalon-excalibur/fortress/examples/src/java/org/apache/avalon/fortress/examples/viewer/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/examples/src/java/org/apache/avalon/fortress/examples/viewer/Main.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Main.java	11 Apr 2003 07:36:21 -0000	1.7
  +++ Main.java	30 May 2003 20:55:10 -0000	1.8
  @@ -50,6 +50,10 @@
   package org.apache.avalon.fortress.examples.viewer;
   
   import org.apache.avalon.fortress.impl.DefaultContainerManager;
  +import org.apache.avalon.fortress.util.FortressConfig;
  +import org.apache.avalon.fortress.ContainerManager;
  +import org.apache.avalon.framework.CascadingException;
  +import org.apache.avalon.framework.container.ContainerUtil;
   
   /**
    * Fortress container example allowing you to perform lookups on components
  @@ -67,25 +71,22 @@
       public static final void main( String[] args )
           throws Exception
       {
  -        org.apache.avalon.fortress.ContainerManager cm = null;
  +        ContainerManager cm = null;
   
           try
           {
  -            final org.apache.avalon.fortress.util.FortressConfig config = new org.apache.avalon.fortress.util.FortressConfig();
  -            config.setContainerClass( "org.apache.avalon.fortress.examples.viewer.ComponentViewer"
);
  -            config.setContextDirectory( "./" );
  -            config.setWorkDirectory( "./" );
  +            final FortressConfig config = new FortressConfig();
  +            config.setContainerClass( ComponentViewer.class );
               config.setContainerConfiguration( "resource://org/apache/avalon/fortress/examples/viewer/ComponentViewer.xconf"
);
               config.setLoggerManagerConfiguration( "resource://org/apache/avalon/fortress/examples/viewer/ComponentViewer.xlog"
);
  -            config.setRoleManagerConfiguration( "resource://org/apache/avalon/fortress/examples/viewer/ComponentViewer.roles"
);
               config.setInstrumentManagerConfiguration( "resource://org/apache/avalon/fortress/examples/viewer/ComponentViewer.instruments"
);
   
               cm = new DefaultContainerManager( config.getContext() );
               org.apache.avalon.framework.container.ContainerUtil.initialize( cm );
   
  -            ( (org.apache.avalon.fortress.examples.viewer.ComponentViewer)cm.getContainer()
).run();
  +            ( (ComponentViewer)cm.getContainer() ).run();
           }
  -        catch( org.apache.avalon.framework.CascadingException e )
  +        catch( CascadingException e )
           {
               e.printStackTrace();
   
  @@ -95,15 +96,12 @@
               {
                   t.printStackTrace();
   
  -                if( t instanceof org.apache.avalon.framework.CascadingException )
  -                    t = ( (org.apache.avalon.framework.CascadingException)t ).getCause();
  -                else
  -                    t = null;
  +                t = t.getCause();
               }
           }
           finally
           {
  -            org.apache.avalon.framework.container.ContainerUtil.dispose( cm );
  +            ContainerUtil.dispose( cm );
           }
       }
   }
  
  
  
  1.7       +9 -9      avalon-excalibur/fortress/examples/src/java/org/apache/avalon/fortress/examples/swing/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/examples/src/java/org/apache/avalon/fortress/examples/swing/Main.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Main.java	11 Apr 2003 07:36:21 -0000	1.6
  +++ Main.java	30 May 2003 20:55:10 -0000	1.7
  @@ -50,6 +50,9 @@
   package org.apache.avalon.fortress.examples.swing;
   
   import org.apache.avalon.fortress.impl.DefaultContainerManager;
  +import org.apache.avalon.fortress.util.FortressConfig;
  +import org.apache.avalon.fortress.ContainerManager;
  +import org.apache.avalon.framework.container.ContainerUtil;
   
   /**
    * Fortress container example.
  @@ -69,18 +72,15 @@
           throws Exception
       {
           // Set up all the preferences for Fortress
  -        final org.apache.avalon.fortress.util.FortressConfig config = new org.apache.avalon.fortress.util.FortressConfig();
  -        config.setContainerClass( "org.apache.avalon.fortress.examples.swing.SwingContainer"
);
  -        config.setContextDirectory( "./" );
  -        config.setWorkDirectory( "./" );
  +        final FortressConfig config = new FortressConfig();
  +        config.setContainerClass( SwingContainer.class );
           config.setContainerConfiguration( "resource://org/apache/avalon/fortress/examples/swing/SwingContainer.xconf"
);
           config.setLoggerManagerConfiguration( "resource://org/apache/avalon/fortress/examples/swing/SwingContainer.xlog"
);
  -        config.setRoleManagerConfiguration( "resource://org/apache/avalon/fortress/examples/swing/SwingContainer.roles"
);
           config.setInstrumentManagerConfiguration( "resource://org/apache/avalon/fortress/examples/swing/SwingContainer.instruments"
);
   
           // Get the root container initialized
  -        org.apache.avalon.fortress.ContainerManager cm = new DefaultContainerManager( config.getContext()
);
  -        org.apache.avalon.framework.container.ContainerUtil.initialize( cm );
  +        ContainerManager cm = new DefaultContainerManager( config.getContext() );
  +        ContainerUtil.initialize( cm );
   
           /* Special containers such as Swing applications run in a different
            * thread in the background.  This is only one method of handling
  @@ -93,7 +93,7 @@
           ( (SwingContainer)cm.getContainer() ).run();
   
           // Properly clean up when we are done
  -        org.apache.avalon.framework.container.ContainerUtil.dispose( cm );
  +        ContainerUtil.dispose( cm );
       }
   }
   
  
  
  
  1.8       +8 -2      avalon-excalibur/fortress/examples/src/java/org/apache/avalon/fortress/examples/components/TranslatorImpl.java
  
  Index: TranslatorImpl.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/examples/src/java/org/apache/avalon/fortress/examples/components/TranslatorImpl.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TranslatorImpl.java	11 Apr 2003 07:36:20 -0000	1.7
  +++ TranslatorImpl.java	30 May 2003 20:55:10 -0000	1.8
  @@ -54,6 +54,7 @@
   import java.util.Set;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.excalibur.instrument.AbstractLogEnabledInstrumentable;
   import org.apache.excalibur.instrument.CounterInstrument;
   
  @@ -75,11 +76,16 @@
    * </pre>
    * </p>
    *
  + * @avalon.component
  + * @avalon.service type=Translator
  + * @x-avalon.info name=translator
  + * @x-avalon.lifestyle type=singleton
  + *
    * @author <a href="mailto:crafterm@apache.org">Marcus Crafter</a>
    * @version CVS $Revision$ $Date$
    */
   public class TranslatorImpl extends AbstractLogEnabledInstrumentable
  -    implements Translator, org.apache.avalon.framework.configuration.Configurable
  +    implements Translator, Configurable
   {
       // Instrument to count the number of translations performed
       private CounterInstrument m_translationsInstrument;
  
  
  
  1.7       +13 -9     avalon-excalibur/fortress/examples/src/java/org/apache/avalon/fortress/examples/servlet/servlet.java
  
  Index: servlet.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/examples/src/java/org/apache/avalon/fortress/examples/servlet/servlet.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- servlet.java	11 Apr 2003 07:36:20 -0000	1.6
  +++ servlet.java	30 May 2003 20:55:10 -0000	1.7
  @@ -49,7 +49,12 @@
   */
   package org.apache.avalon.fortress.examples.servlet;
   
  +import org.apache.avalon.fortress.ContainerManager;
  +import org.apache.avalon.fortress.impl.DefaultContainerManager;
  +import org.apache.avalon.framework.container.ContainerUtil;
  +
   import java.io.IOException;
  +import java.io.File;
   import javax.servlet.ServletException;
   import javax.servlet.ServletRequest;
   import javax.servlet.ServletResponse;
  @@ -64,7 +69,7 @@
   public final class servlet extends HttpServlet
   {
       private ServletContainer m_container;
  -    private org.apache.avalon.fortress.ContainerManager m_containerManager;
  +    private ContainerManager m_containerManager;
   
       /**
        * Initializes Servlet and creates a <code>ServletContainer</code> instance
  @@ -79,15 +84,14 @@
           try
           {
               final org.apache.avalon.fortress.util.FortressConfig config = new org.apache.avalon.fortress.util.FortressConfig();
  -            config.setContainerClass( "org.apache.avalon.fortress.examples.servlet.ServletContainer"
);
  -            config.setContextDirectory( "./" );
  -            config.setWorkDirectory( "./" );
  +            config.setContainerClass( ServletContainer.class );
  +            config.setContextDirectory( getServletContext().getRealPath("/") );
  +            config.setWorkDirectory( (File) getServletContext().getAttribute( "javax.servlet.context.tempdir"
) );
               config.setContainerConfiguration( "resource://org/apache/avalon/fortress/examples/servlet/ServletContainer.xconf"
);
               config.setLoggerManagerConfiguration( "resource://org/avalon/excalibur/fortress/examples/servlet/ServletContainer.xlog"
);
  -            config.setRoleManagerConfiguration( "resource://org/avalon/excalibur/fortress/examples/servlet/ServletContainer.roles"
);
   
  -            m_containerManager = new org.apache.avalon.fortress.impl.DefaultContainerManager(
config.getContext() );
  -            org.apache.avalon.framework.container.ContainerUtil.initialize( m_containerManager
);
  +            m_containerManager = new DefaultContainerManager( config.getContext() );
  +            ContainerUtil.initialize( m_containerManager );
   
               m_container = (ServletContainer)m_containerManager.getContainer();
           }
  @@ -119,6 +123,6 @@
        */
       public void destroy()
       {
  -        org.apache.avalon.framework.container.ContainerUtil.dispose( m_containerManager
);
  +        ContainerUtil.dispose( m_containerManager );
       }
   }
  
  
  
  1.7       +11 -3     avalon-excalibur/fortress/examples/src/java/org/apache/avalon/fortress/examples/extended/components/ExtendedComponentImpl.java
  
  Index: ExtendedComponentImpl.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/examples/src/java/org/apache/avalon/fortress/examples/extended/components/ExtendedComponentImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ExtendedComponentImpl.java	11 Apr 2003 07:36:20 -0000	1.6
  +++ ExtendedComponentImpl.java	30 May 2003 20:55:10 -0000	1.7
  @@ -49,18 +49,26 @@
   */
   package org.apache.avalon.fortress.examples.extended.components;
   
  +import org.apache.avalon.framework.logger.AbstractLogEnabled;
  +import org.apache.avalon.fortress.examples.extended.extensions.SecurityManageable;
  +
   /**
    * <code>TestComponentImpl</code>, demonstrating the use of a custom
    * lifecycle stage <code>SecurityManageable</code>. This code does
    * a simple access check for several files on the file system and logs
    * the results accordingly.
    *
  + * @avalon.component
  + * @avalon.service type=ExtendedComponent
  + * @x-avalon.info name=extended-component
  + * @x-avalon.lifestyle type=singleton
  + *
    * @author <a href="mailto:crafterm@apache.org">Marcus Crafter</a>
    * @version CVS $Revision$ $Date$
    */
   public class ExtendedComponentImpl
  -    extends org.apache.avalon.framework.logger.AbstractLogEnabled
  -    implements org.apache.avalon.fortress.examples.extended.components.ExtendedComponent,
org.apache.avalon.fortress.examples.extended.extensions.SecurityManageable
  +    extends AbstractLogEnabled
  +    implements ExtendedComponent, SecurityManageable
   {
       /**
        * Pass a SecurityManager object to the component
  
  
  

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


Mime
View raw message