mcconnell    2002/11/11 02:29:22

  Added:       meta/src/java/org/apache/excalibur/meta/model
                        ContextDirective.java
  Log:
  Initial commit of the ContextDirective. A context directive holds information
  context values to be imported from a container, and context entries that
  are declarative in nature.  A context directive is contained and exposed by
  the Profile class.
  
  Revision  Changes    Path
  1.1                  
jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/model/ContextDirective.java
  
  Index: ContextDirective.java
  ===================================================================
  /* ==================================================================== 
   * The Apache Software License, Version 1.1 
   * 
   * Copyright (c) 2002 The Apache Software Foundation. All rights 
   * reserved. 
   * 
   * Redistribution and use in source and binary forms, with or without 
   * modification, are permitted provided that the following conditions 
   * are met: 
   * 
   * 1. Redistributions of source code must retain the above copyright 
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *    "This product includes software developed by the
   *    Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software 
   *    itself, if and wherever such third-party acknowledgments  
   *    normally appear.
   *
   * 4. The names "Jakarta", "Avalon", and "Apache Software Foundation" 
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation. For more
   * information on the Apache Software Foundation, please see 
   * <http://www.apache.org/>.
   */ 
  
  package org.apache.excalibur.meta.model;
  
  import org.apache.avalon.framework.context.Context;
  
  /**
   * A context descriptor declares the context creation criteria for
   * the context instance and context entries.
   *
   * <p><b>XML</b></p>
   * <p>A context directive may contain multiple import statements.  Each import
   * statement corresponds to a request for a context value from the container.</p>
   * <pre>
   *    &lt;context class="<font color="darkred">MyContextCLass</font>"&gt;
   *       &lt;import name="<font color="darkred">classloader</font>" key="<font 
color="darkred">special.classloader</font>"/&gt;
   *       &lt;import name="<font color="darkred">avalon:home</font>" key="<font 
color="darkred">base</font>"/&gt;
   *       &lt;entry key="<font color="darkred">location</font>" value="<font 
color="darkred">Paris</font>"/&gt;
   *       &lt;entry key="<font color="darkred">special</font>" class="<font 
color="darkred">MySpecialClass</font>"&gt;
   *         &lt;parameter&gt<font color="darkred">hello</font>&lt;/parameter&gt;
   *         &lt;parameter class="<font 
color="darkred">java.lang.ClassLoader</font>"&gt<font 
color="darkred">%{special.classloader}</font>&lt;/parameter&gt;
   *       &lt;/entry&gt
   *    &lt;/context&gt;
   * </pre>
   *
   * @see Entry
   * @see Import
   * @see Parameter
   * @author <a href="mailto:mcconnell@;apache.org">Stephen McConnell</a>
   * @version $Revision: 1.1 $ $Date: 2002/11/11 10:29:22 $
   */
  public class ContextDirective
  {
  
      /**
       * The default context implementation class to be used if not
       * no context class is defined.
       */
      public static final String DEFAULT_CONTEXT_CLASS =
          "org.apache.avalon.framework.context.DefaultContext";
  
      /**
       * The set of entry directives.
       */
      private final Entry[] m_entries;
  
      /**
       * The set of import directives.
       */
      private final Import[] m_imports;
  
      /**
       * The context implementation classname.
       */
      private final String m_classname;
  
      /**
       * Cached reference to created context value.
       */
      private Context m_context;
  
      /**
       * Creation of a new file target.
       * @param classname the context implementation class
       * @param imports the set of import directives
       * @param entries the set of entry descriptors
       */
      public ContextDirective( final String classname, final Import[] imports, final 
Entry[] entries )
      {
          if( classname != null )
          {
              m_classname = classname;
          }
          else
          {
              m_classname = DEFAULT_CONTEXT_CLASS;
          }
          m_imports = imports;
          m_entries = entries;
      }
  
      /**
       * Return the classname of the context implementation to use.
       * @return the classname
       */
      public String getClassname()
      {
          return m_classname;
      }
  
      /**
       * Return the set of entry directives.
       * @return the entries
       */
      public Entry[] getEntries()
      {
          return m_entries;
      }
  
      /**
       * Return a named entry.
       * @param key the context entry key
       * @return the entry corresponding to the supplied key or null if the
       *   key is unknown
       */
      public Entry getEntry( String key )
      {
          for( int i = 0; i < m_entries.length; i++ )
          {
              Entry entry = m_entries[ i ];
              if( entry.getKey().equals( key ) )
              {
                  return entry;
              }
          }
          return null;
      }
  
      /**
       * Return the set of import directives.
       * @return the imports
       */
      public Import[] getImports()
      {
          return m_imports;
      }
  
      /**
       * Return a named import directive.
       * @param key the import key
       * @return the import directive corresponding to the supplied key or null if the
       *   key is unknown
       */
      public Import getImport( String key )
      {
          for( int i = 0; i < m_imports.length; i++ )
          {
              Import imp = m_imports[ i ];
              if( imp.getKey().equals( key ) )
              {
                  return imp;
              }
          }
          return null;
      }
  }
  
  
  

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

Reply via email to