avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/model/builder XMLProfileCreator.java Resources.properties ProfileCreator.java ProfileBuilder.java package.html
Date Mon, 11 Nov 2002 10:38:24 GMT
mcconnell    2002/11/11 02:38:24

  Added:       meta/src/java/org/apache/excalibur/meta/model/builder
                        XMLProfileCreator.java Resources.properties
                        ProfileCreator.java ProfileBuilder.java
                        package.html
  Log:
  Profile builder resources.
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/model/builder/XMLProfileCreator.java
  
  Index: XMLProfileCreator.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 apache@apache.org.
   *
   * 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.builder;
  
  import java.io.InputStream;
  import java.util.ArrayList;
  import java.util.Vector;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.configuration.DefaultConfiguration;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.excalibur.meta.model.LoggingDirective;
  import org.apache.excalibur.meta.model.Category;
  import org.apache.excalibur.meta.model.ContextDirective;
  import org.apache.excalibur.meta.model.Entry;
  import org.apache.excalibur.meta.model.Import;
  import org.apache.excalibur.meta.model.Parameter;
  import org.apache.excalibur.meta.model.Profile;
  import org.apache.excalibur.meta.ConfigurationBuilder;
  import org.apache.excalibur.meta.info.Type;
  import org.apache.excalibur.meta.info.builder.XMLTypeCreator;
  import org.xml.sax.InputSource;
  
  /**
   * Handles internalization of an XML based description of a {@link Profile}
   * from a Configuration object. The format for Configuration object
   * is specified in the <a href="package-summary.html#external">package summary</a>.
   *
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @version $Revision: 1.1 $ $Date: 2002/11/11 10:38:24 $
   */
  public class XMLProfileCreator
      implements ProfileCreator
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( XMLTypeCreator.class );
  
      /**
       * Create an array of packaged {@link Profile} objects for specified
       * type, loaded from specified {@link InputStream}.  If the
       * input stream is null, an implicit profile will be created.
       *
       * @param loader the classloader
       * @param type the base type
       * @param inputStream the InputStream to load Type from
       * @return the created set of profiles
       * @throws Exception if an error occurs
       */
      public Profile[] createPackagedProfiles(
          ClassLoader loader, Type type, InputStream inputStream )
          throws Exception
      {
          if( inputStream != null )
          {
              final InputSource input = new InputSource( inputStream );
              final Configuration configuration =
                  ConfigurationBuilder.build( input );
              return createPackagedProfiles( loader, type, configuration );
          }
          else
          {
              Profile profile = createImplicitProfile( type );
              return new Profile[]{profile};
          }
      }
  
      /**
       * Create an explicit {@link Profile} instance from a configuration.
       * @param type the component type
       * @param config the profile description
       * @return the profile
       * @exception Exception if an error occurs during profile creation
       */
      public Profile createProfile( Type type, Configuration config )
          throws Exception
      {
          return buildProfile( type, config, Profile.EXPLICIT );
      }
  
      /**
       * Create an array of {@link Profile} object for specified type from
       * specified configuration data associated with a single type.
       *
       * @param loader the classloader to use
       * @param type the base component type
       * @param info the configuration
       * @return the created set of profiles
       * @throws Exception if an error occurs
       */
      private Profile[] createPackagedProfiles(
          ClassLoader loader, Type type, final Configuration info )
          throws Exception
      {
          Vector vector = new Vector();
          Configuration[] profiles = info.getChildren( "component" );
          if( profiles.length == 0 )
          {
              Profile profile = createImplicitProfile( type );
              return new Profile[]{profile};
          }
          for( int i = 0; i < profiles.length; i++ )
          {
              vector.add( buildProfile(
                  type, profiles[ i ], Profile.PACKAGED ) );
          }
          return (Profile[])vector.toArray( new Profile[ 0 ] );
      }
  
      private Profile buildProfile(
          Type type, Configuration profile, int mode )
          throws Exception
      {
  
          //
          // create the logging categories for this profile
          //
  
          final String name = profile.getAttribute( "name" );
  
          LoggingDirective categories =
              createLoggingDirective(
                  name, profile.getChild( "categories" ) );
  
          //
          // build the profile directives
          //
  
          final boolean enabled =
              profile.getAttributeAsBoolean( "enabled", true );
          final boolean activation =
              getActivationMode( profile );
          final Parameters params =
              Parameters.fromConfiguration( profile.getChild( "parameters" ) );
          final ContextDirective context =
              createContextDirective( profile.getChild( "context" ) );
          final Configuration config =
              profile.getChild( "configuration" );
  
          //
          // create the profile instance
          //
  
          return new Profile(
              name, params, config, context, categories, type, enabled,
              activation, mode );
      }
  
      /**
       * Utility method to get the activation mode for the profile.
       * If the activation attribute value is equal to "startup"
       * TRUE is returned.  If the value if "lazy", FALSE is returned.
       * Otherwise the value will be resolved as a boolean.
       *
       * @param config the profile configuration
       * @return boolean TRUE if activation on startup
       */
      public boolean getActivationMode( Configuration config )
      {
          String value =
              config.getAttribute( "activation", "lazy" );
          if( value.equalsIgnoreCase( "startup" ) )
          {
              return true;
          }
          if( value.equalsIgnoreCase( "lazy" ) )
          {
              return false;
          }
          return config.getAttributeAsBoolean(
              "activation", false );
      }
  
      /**
       * Utility method to create a new context directive.
       *
       * @param config the context directive configuration
       * @return the context directive
       * @throws ConfigurationException if an error occurs
       */
      public ContextDirective createContextDirective( Configuration config )
          throws ConfigurationException
      {
          String classname = config.getAttribute(
              "class", ContextDirective.DEFAULT_CONTEXT_CLASS );
          Import[] imports = createImports( config.getChildren( "import" ) );
          Entry[] entries = createEntries( config.getChildren( "entry" ) );
          return new ContextDirective( classname, imports, entries );
      }
  
      /**
       * Utility method to create a set of import directive.
       *
       * @param configs the import directive configurations
       * @return the import directives
       * @throws ConfigurationException if an error occurs
       */
      public Import[] createImports( Configuration[] configs )
          throws ConfigurationException
      {
          ArrayList list = new ArrayList();
          for( int i = 0; i < configs.length; i++ )
          {
              list.add( createImport( configs[ i ] ) );
          }
          return (Import[])list.toArray( new Import[ 0 ] );
      }
  
      /**
       * Utility method to create a new import directive.
       *
       * @param config the import directive configuration
       * @return the import directive
       * @throws ConfigurationException if an error occurs
       */
      public Import createImport( Configuration config )
          throws ConfigurationException
      {
          final String key = config.getAttribute( "key" );
          final String path = config.getAttribute( "name", null );
          return new Import( key, path );
      }
  
      /**
       * Utility method to create a set of entry directives.
       *
       * @param configs the entry directive configurations
       * @return the entry directives
       * @throws ConfigurationException if an error occurs
       */
      public Entry[] createEntries( Configuration[] configs )
          throws ConfigurationException
      {
          ArrayList list = new ArrayList();
          for( int i = 0; i < configs.length; i++ )
          {
              Entry entry = createEntry( configs[ i ] );
              list.add( entry );
          }
          return (Entry[])list.toArray( new Entry[ 0 ] );
      }
  
      /**
       * Utility method to create a new entry directive.
       *
       * @param config the entry directive configuration
       * @return the entry directive
       * @throws ConfigurationException if an error occurs
       */
      public Entry createEntry( Configuration config )
          throws ConfigurationException
      {
          String key = config.getAttribute( "key" );
          String classname = config.getAttribute( "class", "java.lang.String" );
          String value = config.getValue( null );
          if( value != null )
          {
              return new Entry( key, classname, value );
          }
          else
          {
              Configuration[] params = config.getChildren( "parameter" );
              Parameter[] parameters = createParameters( params );
              return new Entry( key, classname, parameters );
          }
      }
  
      /**
       * Utility method to create a set of parameter directive.
       *
       * @param configs the parameter directive configurations
       * @return the parameter directives
       * @throws ConfigurationException if an error occurs
       */
      public Parameter[] createParameters( Configuration[] configs )
          throws ConfigurationException
      {
          ArrayList list = new ArrayList();
          for( int i = 0; i < configs.length; i++ )
          {
              Parameter parameter = createParameter( configs[ i ] );
              list.add( parameter );
          }
          return (Parameter[])list.toArray( new Parameter[ 0 ] );
      }
  
      /**
       * Utility method to create a new parameter directive.
       *
       * @param config the parameter directive configuration
       * @return the parameter directive
       * @throws ConfigurationException if an error occurs
       */
      public Parameter createParameter( Configuration config )
          throws ConfigurationException
      {
          String classname = config.getAttribute( "class", "java.lang.String" );
          String value = config.getValue( null );
          if( value != null )
          {
              return new Parameter( classname, value );
          }
          else
          {
              Configuration[] params = config.getChildren( "parameter" );
              Parameter[] parameters = createParameters( params );
              return new Parameter( classname, parameters );
          }
      }
  
      /**
       * Utility method to create a new categories directive.
       *
       * @param name the categories base path
       * @param config the categories directive configuration
       * @return the categories directive
       * @throws Exception if an error occurs
       */
      public LoggingDirective createLoggingDirective(
          String name, Configuration config )
          throws Exception
      {
          final String priority = config.getAttribute( "priority", null );
          final String target = config.getAttribute( "target", null );
          ArrayList list = new ArrayList();
          Configuration[] configs = config.getChildren( "category" );
          for( int i = 0; i < configs.length; i++ )
          {
              Category category = createCategory( configs[ i ] );
              list.add( category );
          }
          Category[] categories =
              (Category[])list.toArray( new Category[ 0 ] );
          return new LoggingDirective(
              name, priority, target, categories );
      }
  
      /**
       * Utility method to create a new category directive.
       *
       * @param config the category directive configuration
       * @return the category directive
       * @throws ConfigurationException if an error occurs
       */
      public Category createCategory( Configuration config )
          throws ConfigurationException
      {
          final String name = config.getAttribute( "name" );
          final String priority = config.getAttribute( "priority", null );
          final String target = config.getAttribute( "target", null );
          return new Category( name, priority, target );
      }
  
      /**
       * Utility method to create a new category directive.
       *
       * @param config the category directive configuration
       * @param def the default category name
       * @return the category directive
       * @throws ConfigurationException if an error occurs
       */
      public Category createCategory( Configuration config, String def )
          throws ConfigurationException
      {
          final String name = config.getAttribute( "name", def );
          final String priority = config.getAttribute( "priority", null );
          final String target = config.getAttribute( "target", null );
          return new Category( name, priority, target );
      }
  
      private Profile createImplicitProfile( Type type ) throws Exception
      {
          ContextDirective context =
              new ContextDirective(
                  ContextDirective.DEFAULT_CONTEXT_CLASS,
                  new Import[ 0 ], new Entry[ 0 ] );
          final Configuration defaults =
              new DefaultConfiguration( "default", null );
          final LoggingDirective categories =
              createDefaultLoggingDirective( type );
  
          return new Profile(
              null, null, defaults, context, categories, type, true, false,
              Profile.IMPLICIT
          );
      }
  
      /**
       * Utility method to create a new categories directive.
       *
       * @param type the component type
       * @return the categories directive
       */
      protected LoggingDirective createDefaultLoggingDirective( Type type )
      {
          final String name = type.getInfo().getName();
          return new LoggingDirective( name, null, null, new Category[ 0 ] );
      }
  
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/model/builder/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  builder.redundent-role.notice=Warning: Type for class {0} redundently specifies role name
"{1}" in dependency when it is identical to the name of service. It is recomended that the
<role/> section be elided.
  builder.creating-info.notice=Creating a Type for class "{0}".
  builder.created-info.notice=Constructed Type object for class {0}. Type contains {1} services,
{2} dependencies, {3} context entrys and {4} loggers.
  builder.bad-toplevel-element.error=Error the component implemented by "{0}" has an invalid
element at top level of component info descriptor. Expected: "component-info". Actual: "{1}"
  builder.missing-info.error=Unable to locate resource from which to load info for component
implemented by class "{0}".
  builder.missing-xml-creator.error=Unable to create XMLTypeCreator, usually due to not having
XML classes on Classpath. Thus unable to lookup XML descriptor for component type "{0}".
  
  builder.creating-profile.notice=Creating Profiles for class "{0}".
  
  target.nocreate=Error creating LogTarget named "{0}" for file {0}. (Reason: {2}).
  unknown-priority=Unknown priority "{0}" for Logger named "{1}".
  category-create=Creating a log category named "{0}" that writes to "{1}" target at priority
"{2}".
  
  missing.extension=Unable to locate an extension that is required by application.\n  Extension
Name: {0}\n  Specification Vendor: {1}\n  Specification Version: {2}\n  Implementation Vendor:
{3}\n  Implementation Vendor-Id: {4}\n  Implementation Version: {5}\n  Implementation URL:
{6}
  unsatisfied.extensions=Missing {0} extensions and thus can not build ClassLoader for application.
  bad-classpath-entry=There is a bad entry ("{0}") on classpath that made it impossible to
load a manifest.
  available-extensions=Available extensions: {0}
  required-extensions=The list of required extensions for application includes: {0}
  optional-packages-added=The list of "Optional Packages" added to the application include:
{0}
  classpath-entries=The list of classpath entrys for the application include: {0}
  
  
  
  
  1.1                  jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/model/builder/ProfileCreator.java
  
  Index: ProfileCreator.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 apache@apache.org.
   *
   * 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.builder;
  
  import java.io.InputStream;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.excalibur.meta.model.Profile;
  import org.apache.excalibur.meta.info.Type;
  
  /**
   * Simple interface used to create {@link Profile}
   * from stream or Configuration sorce.
   *
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @version $Revision: 1.1 $ $Date: 2002/11/11 10:38:24 $
   */
  public interface ProfileCreator
  {
      /**
       * Create a set of packaged {@link Profile} instances from stream
       *
       * @param loader the classloader
       * @param type the base type
       * @param inputStream the stream that the resource is loaded from
       * @return the newly created {@link Profile} array
       * @exception Exception if a error occurs during profile creation
       */
      Profile[] createPackagedProfiles(
          ClassLoader loader,
          Type type,
          InputStream inputStream )
          throws Exception;
  
      /**
       * Create an explicit {@link Profile} instances from a configuration.
       * @param type the component type
       * @param config the profile description
       * @return the profile
       * @exception Exception if an error occurs during profile creation
       */
      Profile createProfile( Type type, Configuration config )
          throws Exception;
  
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/model/builder/ProfileBuilder.java
  
  Index: ProfileBuilder.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 apache@apache.org.
   *
   * 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.builder;
  
  import java.io.InputStream;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.excalibur.meta.model.Profile;
  import org.apache.excalibur.meta.info.Type;
  import org.apache.excalibur.meta.info.builder.TypeBuilder;
  
  /**
   * A ProfileBuilder is responsible for building {@link Profile}
   * objects from Configuration objects.
   *
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @version $Revision: 1.1 $ $Date: 2002/11/11 10:38:24 $
   */
  public final class ProfileBuilder
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( TypeBuilder.class );
  
      private final ProfileCreator m_xmlProfileCreator = createXMLProfileCreator();
  
      /**
       * Build Profile from the XML descriptor format.
       *
       * @param loader the ClassLoader to load info from
       * @param type the Type on which the profile is based
       * @return the created Profile
       * @throws Exception if an error occurs
       */
      public Profile[] build( ClassLoader loader, Type type )
          throws Exception
      {
          final String xprofile =
              type.getInfo().getImplementationKey().replace( '.', '/' ) + ".xprofile";
          final InputStream inputStream =
              loader.getResourceAsStream( xprofile );
  
          final ProfileCreator creator = getXMLProfileCreator( xprofile );
          return creator.createPackagedProfiles( loader, type, inputStream );
  
      }
  
      /**
       * Utility to get xml info builder, else throw
       * an exception if missing descriptor.
       *
       * @return the ProfileCreator
       */
      private ProfileCreator getXMLProfileCreator( final String classname )
          throws Exception
      {
          if( null != m_xmlProfileCreator )
          {
              return m_xmlProfileCreator;
          }
          else
          {
              final String message =
                  REZ.getString( "builder.missing-xml-creator.error", classname );
              throw new Exception( message );
          }
      }
  
      /**
       * Utility to get XMLProfileCreator if XML files are on
       * ClassPath.
       *
       * @return the XML {@link ProfileCreator}
       */
      private static ProfileCreator createXMLProfileCreator()
      {
          ProfileCreator xmlProfileCreator = null;
          try
          {
              xmlProfileCreator = new XMLProfileCreator();
          }
          catch( final Exception e )
          {
              //Ignore it if ClassNot found due to no
              //XML Classes on classpath
          }
          return xmlProfileCreator;
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/model/builder/package.html
  
  Index: package.html
  ===================================================================
  <html><body>
  <p>Merlin model information builders that handle internalization of a model supplied
as a configuration instance.</P>
  </body></html>
  
  
  

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