avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pro...@apache.org
Subject cvs commit: jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/phoenix app.xconf logkit.xconf main.xconf
Date Wed, 31 Jul 2002 20:47:05 GMT
proyal      2002/07/31 13:47:05

  Added:       phyre/src/java/org/apache/avalon/phyre/phoenix/panels
                        ModifyConfigurationPanel.java
               phyre/src/java/org/apache/avalon/phyre/phoenix app.xconf
                        logkit.xconf main.xconf
  Log:
  * Custom panel for Phoenix to modify configs
  * Config files for Phoenix
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/phoenix/panels/ModifyConfigurationPanel.java
  
  Index: ModifyConfigurationPanel.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.avalon.phyre.phoenix.panels;
  
  import java.awt.BorderLayout;
  import java.awt.GridLayout;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.io.StringReader;
  import javax.swing.JButton;
  import javax.swing.JOptionPane;
  import javax.swing.JPanel;
  import javax.swing.JScrollPane;
  import javax.swing.JTextArea;
  
  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.configuration.DefaultConfigurationBuilder;
  import org.apache.avalon.framework.configuration.DefaultConfigurationSerializer;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  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.phyre.PhyreRuntimeException;
  import org.apache.avalon.phyre.mbean.MBeanAccessor;
  import org.apache.avalon.phyre.panels.EventContextualizable;
  import org.apache.avalon.phyre.panels.LogEnabledJPanel;
  
  import org.xml.sax.InputSource;
  
  /**
   * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
   */
  public class ModifyConfigurationPanel extends LogEnabledJPanel
      implements Serviceable, Configurable, EventContextualizable, Initializable
  {
      private static final String[] CONFIG_METHOD_TYPES =
          new String[]{String.class.getName(), String.class.getName(), Configuration.class.getName()};
  
      private Configuration m_config;
  
      private ServiceManager m_manager;
      private MBeanAccessor m_configManager;
      private MBeanAccessor m_configValidator;
  
      private String m_app;
      private String m_block;
  
      private final JTextArea m_textArea;
  
      public ModifyConfigurationPanel() throws Exception
      {
          super( new BorderLayout() );
  
          add( new JScrollPane( m_textArea = new JTextArea() ), BorderLayout.CENTER );
  
          addButtons();
      }
  
      public void service( ServiceManager manager )
          throws ServiceException
      {
          m_manager = manager;
      }
  
      public void configure( Configuration configuration )
          throws ConfigurationException
      {
          m_config = configuration;
      }
  
      public void initialize()
          throws Exception
      {
          m_configManager = ( MBeanAccessor ) m_manager.lookup(
              m_config.getChild( "repository-object-name" ).getValue() );
  
          m_configValidator = ( MBeanAccessor ) m_manager.lookup(
              m_config.getChild( "validator-object-name" ).getValue() );
      }
  
      public void eventContext( Context context ) throws ContextException
      {
          m_block = ( String ) context.get( "row-key" );
          m_app = ( String ) context.get( "name" );
  
          try
          {
              loadConfiguration();
          }
          catch( Exception e )
          {
              throw new PhyreRuntimeException( "Unable to load configuration", e );
          }
      }
  
      private void loadConfiguration() throws Exception
      {
          final Boolean b =
              ( Boolean ) m_configManager.invoke( "hasConfiguration", new Object[]{m_app,
m_block} );
  
          if( b.booleanValue() )
          {
              final Configuration c =
                  ( Configuration ) m_configManager.invoke( "getConfiguration",
                                                            new Object[]{m_app, m_block} );
  
              final DefaultConfigurationSerializer serializer = new DefaultConfigurationSerializer();
  
              serializer.setIndent( true );
  
              m_textArea.setText( serializer.serialize( c ) );
          }
      }
  
      private Configuration createConfiguration() throws ConfigurationException
      {
          final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
  
          try
          {
              return builder.build( new InputSource( new StringReader( m_textArea.getText()
) ) );
          }
          catch( ConfigurationException e )
          {
              throw e;
          }
          catch( Exception e )
          {
              throw new ConfigurationException( "Unable to create configuration: " + e.getMessage(),
                                                e );
          }
      }
  
      private boolean isConfigurationValid( final Configuration c )
      {
          try
          {
              final Boolean b =
                  ( Boolean ) m_configValidator.invoke( "isValid",
                                                        new Object[]{m_app, m_block, c},
                                                        CONFIG_METHOD_TYPES );
  
              return b.booleanValue();
          }
          catch( Exception e )
          {
              getLogger().error( "Exception validation configuration", e );
          }
  
          return false;
      }
  
      private void showValidationResult()
      {
          try
          {
              final boolean valid = isConfigurationValid( createConfiguration() );
  
              showValidationResultsDialog( valid );
          }
          catch( ConfigurationException e )
          {
              showConfigurationExceptionDialog( e );
          }
      }
  
      private void showValidationResultsDialog( final boolean valid )
      {
          JOptionPane.showMessageDialog( this,
                                         valid ? "Valid" : "Invalid",
                                         "Validation Results",
                                         JOptionPane.INFORMATION_MESSAGE,
                                         null );
      }
  
      private void showConfigurationExceptionDialog( ConfigurationException e )
      {
          JOptionPane.showMessageDialog( this,
                                         "Error in configuration: " + e.getMessage(),
                                         "Invalid Configuration",
                                         JOptionPane.ERROR_MESSAGE,
                                         null );
      }
  
      private void storeConfiguration()
      {
          Configuration c = null;
  
          try
          {
              c = createConfiguration();
          }
          catch( ConfigurationException e )
          {
              showConfigurationExceptionDialog( e );
  
              return;
          }
  
          if( isConfigurationValid( c ) )
          {
              try
              {
                  m_configManager.invoke( "storeConfiguration",
                                          new Object[]{m_app, m_block, c},
                                          CONFIG_METHOD_TYPES );
  
                  JOptionPane.showMessageDialog( this, "Configuration Updated!" );
              }
              catch( Exception e )
              {
                  throw new PhyreRuntimeException( "Unable to store configuration", e );
              }
          }
          else
          {
              showValidationResultsDialog( false );
          }
      }
  
      private void addButtons()
      {
          final JPanel buttons = new JPanel( new GridLayout( 1, 0 ) );
  
          final JButton validateButton = new JButton( "Validate" );
  
          validateButton.addActionListener( new ActionListener()
          {
              public void actionPerformed( ActionEvent e )
              {
                  if( ActionEvent.ACTION_PERFORMED == e.getID() )
                  {
                      showValidationResult();
                  }
              }
          } );
  
          buttons.add( validateButton );
  
          final JButton updateButton = new JButton( "Update" );
  
          updateButton.addActionListener( new ActionListener()
          {
              public void actionPerformed( ActionEvent e )
              {
                  if( ActionEvent.ACTION_PERFORMED == e.getID() )
                  {
                      storeConfiguration();
                  }
              }
          } );
  
          buttons.add( updateButton );
  
          add( buttons, BorderLayout.SOUTH );
      }
  }
  
  
  
  1.1                  jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/phoenix/app.xconf
  
  Index: app.xconf
  ===================================================================
  <?xml version="1.0"?>
  <phyre-container>
      <action-factory id="af"/>
      <context-navigation id="nav">
          <context>
              <caption>${displayName}</caption>
              <action type="switch-content-panel" panel="default"/>
          </context>
          <navigation>
              <button>
                  <caption>Configuration</caption>
                  <action type="switch-content-panel" panel="config-blocks"/>
              </button>
              <button>
                  <caption>Logging</caption>
              </button>
              <button>
                  <caption>Manageable Services</caption>
              </button>
              <button>
                  <caption>Permissions</caption>
              </button>
          </navigation>
      </context-navigation>
      <mbean-panel id="default" activation="request">
          <object-name>Phoenix:application=${name},topic=Application</object-name>
          <operation name="start">
              <caption>Start ${displayName}</caption>
          </operation>
          <operation name="stop">
              <caption>Stop ${displayName}</caption>
          </operation>
          <operation name="restart">
              <caption>Restart ${displayName}</caption>
          </operation>
      </mbean-panel>
      <grid-panel id="config-blocks" logger="config-blocks" activation="request">
          <title>Components</title>
          <action type="switch-content-panel" panel="configure-block"/>
          <grid>
              <source>
                  <object-name>Phoenix:application=${name},topic=ApplicationMBean</object-name>
                  <attribute>blockNames</attribute>
              </source>
              <column>
                  <caption>Component Name</caption>
                  <value>${row-key}</value>
              </column>
              <column>
                  <caption>Has Configuration?</caption>
                  <value>
                      <source>
                          <object-name>Phoenix:component=ConfigurationManager,topic=ConfigurationRepository</object-name>
                          <operation name="hasConfiguration">
                              <datatype>java.lang.Boolean</datatype>
                              <parameter>${name}</parameter>
                              <parameter>${row-key}</parameter>
                          </operation>
                      </source>
                  </value>
              </column>
          </grid>
      </grid-panel>
      <panel id="configure-block" class="org.apache.avalon.phyre.phoenix.panels.ModifyConfigurationPanel"
activation="request">
          <repository-object-name>Phoenix:component=ConfigurationManager,topic=ConfigurationRepository</repository-object-name>
          <validator-object-name>Phoenix:component=ConfigurationValidator,topic=ConfigurationValidator</validator-object-name>
      </panel>
  </phyre-container>
  
  
  1.1                  jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/phoenix/logkit.xconf
  
  Index: logkit.xconf
  ===================================================================
  <?xml version="1.0"?>
  <logs>
      <!--+ FACTORIES
            +   Factories define various types of output targets for log messages
            +-->
      <factories>
          <factory type="stream" class="org.apache.avalon.excalibur.logger.factory.StreamTargetFactory"/>
      </factories>
      <!--+ TARGETS
            +   Targets are named destinations of log events. Tag names for child
            +   elements, such as 'file' or 'screen', correspond to factory types above.
            +-->
      <targets>
          <!-- Outputs events to the screen. -->
          <stream id="sout">
              <stream>System.out</stream>
              <format type="avalon"/>
          </stream>
      </targets>
      <!--+ CATEGORIES
            +   Categories are named sinks for the application to output events to.
            +   First level category names correspond to block names in assembly.xml.
            +
            +   Each category has an attribute named log-level that controls the severity
            +   of messages to records. Valid severities are:
            +     DEBUG, INFO, WARN, ERROR, FATAL_ERROR
            +
            +   Each category can have children of other categories, and log-target elements
            +   log-target elements have an id-ref attribute that references the id of a target
            +   in the targets section.
            +-->
      <categories>
          <category name="" log-level="INFO">
              <log-target id-ref="sout"/>
          </category>
      </categories>
  </logs>
  
  
  
  1.1                  jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/phoenix/main.xconf
  
  Index: main.xconf
  ===================================================================
  <?xml version="1.0"?>
  <phyre-container>
      <action-factory id="af"/>
      <context-navigation id="nav">
          <context>
              <caption>Phoenix Management Console</caption>
              <action type="switch-content-panel" panel="default"/>
          </context>
          <navigation>
              <label>Hosted Components</label>
              <button>
                  <caption>Hosted Applications</caption>
                  <action type="switch-content-panel" panel="hosted-apps"/>
              </button>
              <button>
                  <caption>Extension Libraries</caption>
              </button>
              <button>
                  <caption>Loggers</caption>
              </button>
              <label>Container Components</label>
              <button>
                  <caption>Configuration Repository</caption>
              </button>
              <button>
                  <caption>Deployer</caption>
              </button>
              <button>
                  <caption>Log Manager</caption>
              </button>
              <button>
                  <caption>System Manager</caption>
              </button>
          </navigation>
      </context-navigation>
      <mbean-panel id="default" activation="request">
          <object-name>Phoenix:component=Embeddor,topic=EmbeddorMBean</object-name>
          <operation name="shutdown">
              <caption>Shutdown Phoenix</caption>
          </operation>
          <operation name="restart">
              <caption>Restart Phoenix</caption>
          </operation>
      </mbean-panel>
      <grid-panel id="hosted-apps" activation="request">
          <title>Applications</title>
          <button>
              <caption>Deploy an Application</caption>
          </button>
          <button>
              <caption>Query Applications</caption>
          </button>
          <action type="load-subcontext" id="apps">
              <context-object-name>Phoenix:application=${row-key},topic=Application</context-object-name>
          </action>
          <grid>
              <source>
                  <object-name>Phoenix:component=Kernel,topic=KernelMBean</object-name>
                  <attribute>applicationNames</attribute>
              </source>
              <column>
                  <caption>Name</caption>
                  <value>
                      <source>
                          <object-name>Phoenix:application=${row-key},topic=Application</object-name>
                          <attribute>displayName</attribute>
                      </source>
                  </value>
              </column>
              <column>
                  <caption>Description</caption>
                  <value>
                      <source>
                          <object-name>Phoenix:application=${row-key},topic=Application</object-name>
                          <attribute>description</attribute>
                      </source>
                  </value>
              </column>
              <column>
                  <caption>Running?</caption>
                  <value>
                      <source>
                          <object-name>Phoenix:application=${row-key},topic=Application</object-name>
                          <attribute>running</attribute>
                      </source>
                  </value>
              </column>
          </grid>
      </grid-panel>
      <subcontext id="apps" logger="apps" activation="request">
          <config>resource://org/apache/avalon/phyre/phoenix/app.xconf</config>
      </subcontext>
      <subcontext id="default">
          <config>resource://org/apache/avalon/phyre/phoenix/app.xconf</config>
      </subcontext>
  </phyre-container>
  
  

--
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