Return-Path: Delivered-To: apmail-jakarta-avalon-cvs-archive@apache.org Received: (qmail 38858 invoked from network); 22 Jul 2002 17:54:37 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 22 Jul 2002 17:54:37 -0000 Received: (qmail 19115 invoked by uid 97); 22 Jul 2002 17:54:55 -0000 Delivered-To: qmlist-jakarta-archive-avalon-cvs@jakarta.apache.org Received: (qmail 19094 invoked by uid 97); 22 Jul 2002 17:54:55 -0000 Mailing-List: contact avalon-cvs-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Avalon CVS List" Reply-To: "Avalon Developers List" Delivered-To: mailing list avalon-cvs@jakarta.apache.org Received: (qmail 19072 invoked by uid 97); 22 Jul 2002 17:54:54 -0000 X-Antivirus: nagoya (v4198 created Apr 24 2002) Date: 22 Jul 2002 17:54:32 -0000 Message-ID: <20020722175432.75414.qmail@icarus.apache.org> From: crafterm@apache.org To: jakarta-avalon-excalibur-cvs@apache.org Subject: cvs commit: jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/viewer ComponentViewer.java ComponentViewer.roles ComponentViewer.xconf ComponentViewer.xlog Main.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N crafterm 2002/07/22 10:54:32 Added: fortress/examples/bin runviewer.sh fortress/examples/src/java/org/apache/excalibur/fortress/examples/viewer ComponentViewer.java ComponentViewer.roles ComponentViewer.xconf ComponentViewer.xlog Main.java Log: Initial commit of a small component 'viewer' tool I wrote to test out the different initialization policies a component can specify about it's respective ComponentHandler. It provides a small gui with a combobox list of all registered components this container has, and the ability fire a 'lookup' event on any one of them. (by tracing the log, it's possible to see the difference on a lookup() between request/startup based inits). Perhaps this might be useful for others, or maybe extended to become a gui component testing tool, etc ? Ideas more than welcome. Revision Changes Path 1.1 jakarta-avalon-excalibur/fortress/examples/bin/runviewer.sh Index: runviewer.sh =================================================================== #!/bin/bash # # Startup script. # # # Determine if JAVA_HOME is set and if so then use it # if [ -z "$JAVA_HOME" ] ; then JAVA=`which java` if [ -z "$JAVA" ] ; then echo "Cannot find JAVA. Please set your PATH." exit 1 fi JAVA_BINDIR=`dirname $JAVA` JAVA_HOME=$JAVA_BINDIR/.. fi if [ "$JAVACMD" = "" ] ; then # it may be defined in env - including flags!! JAVACMD=$JAVA_HOME/bin/java fi # Main.java has hard coded config values so this script must be run from # altprofile/bin (any better ideas ?) EXAMPLE_HOME=.. # # Build the runtime classpath # for i in ${EXAMPLE_HOME}/lib/*.jar ; do CP=${CP}:$i done CP=${CP}:${EXAMPLE_HOME}/build/classes echo $CP # Run the example application $JAVACMD -classpath $CP org.apache.excalibur.fortress.examples.viewer.Main $@ 1.1 jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/viewer/ComponentViewer.java Index: ComponentViewer.java =================================================================== /* * 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.excalibur.fortress.examples.viewer; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Iterator; import java.util.Set; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JPanel; import org.apache.avalon.framework.activity.Startable; import org.apache.avalon.framework.service.ServiceException; import org.apache.avalon.framework.service.ServiceManager; import org.apache.excalibur.fortress.AbstractContainer; /** * Simple Fortress container containing a Swing based viewer for performing * lookups on registered components. * *

* The intention of the viewer is to allow you to perform a lookup of a component * manually, (currently) so you can check the see the effect of lazy vs startup * initialization. *

* *

* REVISIT: add a text component which tracks the log file to make it easier to * see a component being initialized upon first lookup. *

* * @author Marcus Crafter * @version CVS $Revision: 1.1 $ $Date: 2002/07/22 17:54:31 $ */ public final class ComponentViewer extends AbstractContainer implements Startable, ActionListener { // GUI references private JFrame m_frame; private JComboBox m_components; /** * Initializes this component. Creates simple Swing GUI containing * available translations for the key 'hello-world'. * * @exception Exception if an error occurs */ public void initialize() throws Exception { super.initialize(); // create main frame m_frame = new JFrame( "Component Viewer" ); m_frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); m_components = new JComboBox( getRoles() ); JButton button = new JButton( "Lookup!" ); button.addActionListener( this ); /* // can we output the log data into this text area somehow ? JTextArea logData = new JTextArea(); logData.setEditable( false ); */ JPanel selectionPanel = new JPanel(); selectionPanel.add( m_components ); selectionPanel.add( button ); JPanel mainPanel = new JPanel(); mainPanel.setLayout( new BoxLayout( mainPanel, BoxLayout.Y_AXIS) ); mainPanel.add( selectionPanel ); m_frame.setContentPane( mainPanel ); m_frame.pack(); // all done if ( getLogger().isDebugEnabled() ) { getLogger().debug( "Initialized" ); } } /** * Helper method to obtain a list of all Roles registered with this container * * @return an array of roles */ private Object[] getRoles() { Set keys = m_mapper.keySet(); Object[] roles = new Object[ keys.size() ]; int j = 0; for ( Iterator i = keys.iterator(); i.hasNext(); ) { roles[j++] = (String) i.next(); } return roles; } /** * Starts the component, makes GUI visible, ready for use. */ public void start() { m_frame.setVisible( true ); if ( getLogger().isDebugEnabled() ) { getLogger().debug( "GUI Activated" ); } } /** * Stops component, make GUI invisible, ready for decomissioning. */ public void stop() { m_frame.setVisible( false ); if ( getLogger().isDebugEnabled() ) { getLogger().debug( "GUI Disactivated" ); } } /** * Handles the lookup event. Finds out which component * was selected and performs a lookup and release on this component. * * @param evt an ActionEvent value */ public void actionPerformed( ActionEvent evt ) { String selected = (String) m_components.getSelectedItem(); if ( getLogger().isDebugEnabled() ) { getLogger().debug("Looking up component " + selected); } Object component = null; try { component = m_serviceManager.lookup( selected ); } catch (ServiceException e) { if ( getLogger().isWarnEnabled() ) { getLogger().warn( "Error looking up component: " + e.getRole(), e ); } } finally { if ( component != null) m_serviceManager.release( component ); } } } 1.1 jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/viewer/ComponentViewer.roles Index: ComponentViewer.roles =================================================================== 1.1 jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/viewer/ComponentViewer.xconf Index: ComponentViewer.xconf =================================================================== Hallo Welt Hello World Bonjour la monde Apa kabar Dunia Hola Mundo Ciao Mondo 1.1 jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/viewer/ComponentViewer.xlog Index: ComponentViewer.xlog =================================================================== fortress-viewer.log %7.7{priority} %5.5{time} [%8.8{category}] (%{context}): %{message}\n%{throwable} 1.1 jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/viewer/Main.java Index: Main.java =================================================================== /* * 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.excalibur.fortress.examples.viewer; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; import org.apache.avalon.framework.context.Context; import org.apache.avalon.framework.context.DefaultContext; import org.apache.avalon.framework.logger.LogKitLogger; import org.apache.avalon.framework.logger.Logger; import org.apache.avalon.framework.CascadingException; import org.apache.excalibur.fortress.Container; import org.apache.excalibur.fortress.ContainerManager; import org.apache.excalibur.fortress.DefaultContainerManager; import org.apache.excalibur.fortress.util.ContextBuilder; import org.apache.excalibur.fortress.util.ContextManager; /** * Fortress container example allowing you to perform lookups on components * via a simple swing gui. * * @author Marcus Crafter * @version $Id: Main.java,v 1.1 2002/07/22 17:54:31 crafterm Exp $ */ public final class Main { // container reference private static ComponentViewer m_container; /** * @param args a String[] array of command line arguments * @exception Exception if an error occurs */ public static final void main( String[] args ) throws Exception { try { ContextBuilder contextBuilder = new ContextBuilder(); contextBuilder.setContainerClass( "org.apache.excalibur.fortress.examples.viewer.ComponentViewer" ); contextBuilder.setContextDirectory( "./" ); contextBuilder.setWorkDirectory( "./" ); contextBuilder.setContainerConfiguration( "resource://org/apache/excalibur/fortress/examples/viewer/ComponentViewer.xconf" ); contextBuilder.setLoggerManagerConfiguration( "resource://org/apache/excalibur/fortress/examples/viewer/ComponentViewer.xlog" ); contextBuilder.setRoleManagerConfiguration( "resource://org/apache/excalibur/fortress/examples/viewer/ComponentViewer.roles" ); ContextManager contextManager = new ContextManager( contextBuilder.getContext(), null ); contextManager.initialize(); ContainerManager cm = new DefaultContainerManager( contextManager ); cm.initialize(); m_container = ( ComponentViewer ) cm.getContainer(); } catch (CascadingException e) { e.printStackTrace(); Throwable t = e.getCause(); while ( t != null ) { t.printStackTrace(); if ( t instanceof CascadingException ) t = ((CascadingException) t).getCause(); else t = null; } } } } -- To unsubscribe, e-mail: For additional commands, e-mail: