You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by pr...@apache.org on 2002/07/31 22:37:27 UTC

cvs commit: jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/container Container.roles ContentPanelHelper.java DefaultPhyreContainer.java DefaultSubContext.java NavigationPanelHelper.java PhyreContainer.java SubContext.java

proyal      2002/07/31 13:37:27

  Added:       phyre/src/java/org/apache/avalon/phyre/container
                        Container.roles ContentPanelHelper.java
                        DefaultPhyreContainer.java DefaultSubContext.java
                        NavigationPanelHelper.java PhyreContainer.java
                        SubContext.java
  Log:
  Phyre container.
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/container/Container.roles
  
  Index: Container.roles
  ===================================================================
  <?xml version="1.0"?>
  <roles>
      <role name="navigation-component">
          <component shorthand="context-navigation"
              class="org.apache.avalon.phyre.panels.ContextNavigationPanel"
              handler="org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler"/>
      </role>
      <role name="content-component">
          <component shorthand="mbean-panel"
              class="org.apache.avalon.phyre.panels.MBeanPanel"
              handler="org.apache.excalibur.fortress.handler.FactoryComponentHandler"/>
          <component shorthand="grid-panel"
              class="org.apache.avalon.phyre.panels.grid.GridPanel"
              handler="org.apache.excalibur.fortress.handler.FactoryComponentHandler"/>
          <component shorthand="panel"
              class="org.apache.avalon.phyre.panels.LogEnabledJPanel"
              handler="org.apache.excalibur.fortress.handler.FactoryComponentHandler"/>
      </role>
      <role name="org.apache.avalon.phyre.actions.ActionFactory">
          <component shorthand="action-factory"
              class="org.apache.avalon.phyre.actions.DefaultActionFactory"
              handler="org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler"/>
      </role>
      <role name="org.apache.avalon.phyre.container.SubContext">
          <component shorthand="subcontext"
              class="org.apache.avalon.phyre.container.DefaultSubContext"
              handler="org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler"/>
      </role>
  </roles>
  
  
  1.1                  jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/container/ContentPanelHelper.java
  
  Index: ContentPanelHelper.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.container;
  
  import java.awt.Component;
  
  /**
   * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
   */
  public interface ContentPanelHelper
  {
      String CONTEXT = "content-panel-helper";
  
      void setContentPanel( final Component panel );
  }
  
  
  
  1.1                  jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/container/DefaultPhyreContainer.java
  
  Index: DefaultPhyreContainer.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.container;
  
  import java.awt.Component;
  
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.excalibur.fortress.container.DefaultContainer;
  import org.apache.excalibur.fortress.handler.ComponentHandler;
  
  /**
   * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
   */
  public class DefaultPhyreContainer extends DefaultContainer implements PhyreContainer
  {
      private NavigationPanelHelper m_navigationPanelHelper;
      private ContentPanelHelper m_contentPanelHelper;
  
      public void contextualize( Context containerContext )
          throws ContextException
      {
          super.contextualize( containerContext );
  
          m_navigationPanelHelper =
              ( NavigationPanelHelper ) containerContext.get( NavigationPanelHelper.CONTEXT );
          m_contentPanelHelper =
              ( ContentPanelHelper ) containerContext.get( ContentPanelHelper.CONTEXT );
      }
  
  //    public void initialize() throws Exception
  //    {
  //        super.initialize();
  //
  //        m_navigationPanelHelper.setNavigationPanel( getNavigationComponent() );
  //        m_contentPanelHelper.setContentPanel( getDefaultContentComponent() );
  //    }
  
      public Component getDefaultContentComponent() throws ServiceException
      {
          return getComponent( CONTENT_ROLE, "default" );
      }
  
      private Component getComponent( final String role, final String hint ) throws ServiceException
      {
          final ComponentHandler handler = ( ComponentHandler ) get( role, hint );
  
          try
          {
              if( !handler.isInitialized() )
              {
                  handler.initialize();
              }
  
              return ( Component ) handler.get();
          }
          catch( Exception e )
          {
              throw new ServiceException( role, "Could not return a reference to the Component", e );
          }
      }
  
      public Component getNavigationComponent() throws ServiceException
      {
          return getComponent( NAVIGATION_ROLE, null );
      }
  }
  
  
  
  1.1                  jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/container/DefaultSubContext.java
  
  Index: DefaultSubContext.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.container;
  
  import javax.management.MBeanAttributeInfo;
  
  import org.apache.avalon.framework.activity.Disposable;
  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.ContextException;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.context.DefaultContext;
  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.phyre.mbean.MBeanAccessor;
  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;
  
  /**
   * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
   */
  public class DefaultSubContext extends AbstractLogEnabled
      implements SubContext, Contextualizable, Configurable, Serviceable, Disposable
  {
      private Context m_context;
      private ServiceManager m_manager;
      private NavigationPanelHelper m_navPanelHelper;
      private ContentPanelHelper m_contentPanelHelper;
  
      private String m_configLocation;
  
      private ContextManager m_contextManager;
      private ContainerManager m_containerManager;
  
      public void contextualize( Context context )
          throws ContextException
      {
          m_context = context;
          m_contentPanelHelper = ( ContentPanelHelper ) context.get( ContentPanelHelper.CONTEXT );
      }
  
      public void service( ServiceManager manager )
          throws ServiceException
      {
          m_manager = manager;
          m_navPanelHelper = ( NavigationPanelHelper ) manager.lookup( PhyreContainer.NAVIGATION_ROLE );
      }
  
      public void configure( Configuration configuration )
          throws ConfigurationException
      {
          m_configLocation = configuration.getChild( "config" ).getValue();
      }
  
      private Context createContext( final MBeanAccessor contextMBean ) throws Exception
      {
          final DefaultContext ctx = new DefaultContext( m_context );
  
          if( null != contextMBean )
          {
              final MBeanAttributeInfo[] infos = contextMBean.info().getAttributes();
  
              for( int i = 0; i < infos.length; i++ )
              {
                  ctx.put( infos[i].getName(), contextMBean.get( infos[i].getName() ) );
              }
          }
  
          ctx.put( NavigationPanelHelper.CONTEXT, m_navPanelHelper );
  
          ctx.makeReadOnly();
  
          return ctx;
      }
  
      private Context createContainerContext( final Context parent )
      {
          final ContextBuilder builder = new ContextBuilder( parent );
  
          builder.setServiceManager( m_manager );
          builder.setContainerConfiguration( m_configLocation );
  
          return builder.getContext();
      }
  
      public void load( final MBeanAccessor contextMBean ) throws Exception
      {
          dispose();
  
          m_contextManager = new ContextManager(
              createContainerContext( createContext( contextMBean ) ),
              getLogger() );
  
          m_contextManager.initialize();
  
          m_containerManager = new DefaultContainerManager( m_contextManager, getLogger() );
          m_containerManager.initialize();
  
          final PhyreContainer container = ( PhyreContainer ) m_containerManager.getContainer();
  
          m_navPanelHelper.setNavigationPanel( container.getNavigationComponent() );
          m_contentPanelHelper.setContentPanel( container.getDefaultContentComponent() );
      }
  
      public void dispose()
      {
          if( m_containerManager != null )
          {
              m_containerManager.dispose();
          }
  
          if( m_contextManager != null )
          {
              m_contextManager.dispose();
          }
      }
  }
  
  
  
  1.1                  jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/container/NavigationPanelHelper.java
  
  Index: NavigationPanelHelper.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.container;
  
  import java.awt.Component;
  
  /**
   * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
   */
  public interface NavigationPanelHelper
  {
      String CONTEXT = "navigation-panel-helper";
  
      void setNavigationPanel( final Component panel );
  }
  
  
  
  1.1                  jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/container/PhyreContainer.java
  
  Index: PhyreContainer.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.container;
  
  import java.awt.Component;
  
  import org.apache.avalon.framework.service.ServiceException;
  
  /**
   * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
   */
  public interface PhyreContainer
  {
      String NAVIGATION_ROLE = "navigation-component";
      String CONTENT_ROLE = "content-component";
  
      Component getNavigationComponent() throws ServiceException;
  
      Component getDefaultContentComponent() throws ServiceException;
  }
  
  
  
  1.1                  jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/container/SubContext.java
  
  Index: SubContext.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.container;
  
  import org.apache.avalon.phyre.mbean.MBeanAccessor;
  
  /**
   * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
   */
  public interface SubContext
  {
      String ROLE = SubContext.class.getName();
  
      void load( final MBeanAccessor contextMBean ) throws Exception;
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>