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/assembly/src/java/org/apache/excalibur/merlin/model/builder XMLContainerUtil.java
Date Fri, 02 Aug 2002 12:31:38 GMT
mcconnell    2002/08/02 05:31:38

  Added:       assembly/src/java/org/apache/excalibur/merlin/model/builder
                        XMLContainerUtil.java
  Log:
  no message
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/model/builder/XMLContainerUtil.java
  
  Index: XMLContainerUtil.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.merlin.model.builder;
  
  import java.util.ArrayList;
  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.excalibur.merlin.model.Profile;
  import org.apache.excalibur.merlin.model.CategoriesDescriptor;
  import org.apache.excalibur.merlin.model.Category;
  import org.apache.excalibur.merlin.model.ContainerDescriptor;
  import org.apache.excalibur.merlin.model.IncludeDescriptor;
  import org.apache.excalibur.merlin.model.FilesetDescriptor;
  import org.apache.excalibur.merlin.model.DirsetDescriptor;
  import org.apache.excalibur.merlin.model.ClasspathDescriptor;
  import org.apache.excalibur.merlin.model.LoggingDescriptor;
  import org.apache.excalibur.merlin.model.TargetDescriptor;
  import org.apache.excalibur.merlin.model.TargetProvider;
  import org.apache.excalibur.merlin.model.FileTargetProvider;
  import org.apache.excalibur.merlin.model.ExtensionsDescriptor;
  import org.apache.excalibur.merlin.model.ModelException;
  import org.apache.excalibur.merlin.model.builder.XMLProfileCreator;
  
  /**
   * Handles internalization of an XML based description of a {@link ContainerDescriptor}
   * 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/08/02 12:31:38 $
   */
  public class XMLContainerUtil 
    extends XMLProfileCreator
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( XMLContainerUtil.class );
  
  
      public ClasspathDescriptor createClasspathDescriptor( Configuration config )
        throws ConfigurationException
      {
          ArrayList list = new ArrayList();
          Configuration[] configs = config.getChildren("fileset");
          for( int i=0; i<configs.length; i++ )
          {
              Configuration c = configs[i];
              list.add( createFilesetDescriptor( c ) );
          }
          FilesetDescriptor[] filesets = (FilesetDescriptor[]) list.toArray( new FilesetDescriptor[0]
);
          return new ClasspathDescriptor( filesets );
      }
  
      public FilesetDescriptor createFilesetDescriptor( Configuration config ) 
        throws ConfigurationException
      {
          String base = config.getAttribute("dir");
          ArrayList list = new ArrayList();
          Configuration[] includeConfigs = config.getChildren("include");
          for( int i=0; i<includeConfigs.length; i++ )
          {
              Configuration includeConfig = includeConfigs[i];
              list.add( createIncludeDescriptor( includeConfig ) );
          }
          IncludeDescriptor[] includes = (IncludeDescriptor[]) list.toArray( new IncludeDescriptor[0]
);
          return new FilesetDescriptor( base, includes );
      }
  
      public IncludeDescriptor createIncludeDescriptor( Configuration config ) 
        throws ConfigurationException
      {
          String filename = config.getAttribute("name");
          return new IncludeDescriptor( filename );
      }
  
      public LoggingDescriptor createLoggingDescriptor( Configuration config, String name
)
        throws ConfigurationException
      {
          final String target = config.getAttribute( 
             "target", Category.DEFAULT_LOGGING_TARGET );
          final String priority = config.getAttribute( "priority", null );
  
          ArrayList list = new ArrayList();
          Configuration[] configs = config.getChildren("target");
          for( int i=0; i<configs.length; i++ )
          {
              Configuration c = configs[i];
              list.add( createTargetDescriptor( c ) );
          }
          TargetDescriptor[] targets = (TargetDescriptor[]) list.toArray( new TargetDescriptor[0]
);
          return new LoggingDescriptor( name, priority, target, targets );
      }
  
      public TargetDescriptor createTargetDescriptor( Configuration config )
        throws ConfigurationException
      {
          final String name = config.getAttribute("name");
          if( config.getChildren().length == 0 )
            throw new ConfigurationException(
              "missing target provider elememt in '" + config.getName() + "'.");
          final Configuration c = config.getChildren()[0];
          TargetProvider provider = null;
          if( c.getName().equals("file") )
          {
              provider = createFileTargetProvider( c );
          }
          else
          {
              throw new ConfigurationException(
                "Unrecognized provider: " + c.getName() + " in " + config.getName() );
          }
          return new TargetDescriptor( name, provider );
      }
  
      public FileTargetProvider createFileTargetProvider( Configuration config )
        throws ConfigurationException
      {
          String file = config.getAttribute("location");
          return new FileTargetProvider( file );
      }
  
      public ExtensionsDescriptor createExtensionsDescriptor( Configuration config )
        throws ConfigurationException
      {
          ArrayList list = new ArrayList();
          Configuration[] configs = config.getChildren("dirset");
          for( int i=0; i<configs.length; i++ )
          {
              Configuration c = configs[i];
              list.add( createDirsetDescriptor( c ) );
          }
          DirsetDescriptor[] dirs = (DirsetDescriptor[]) list.toArray( new DirsetDescriptor[0]
);
          return new ExtensionsDescriptor( dirs );
      }
  
      public DirsetDescriptor createDirsetDescriptor( Configuration config ) 
        throws ConfigurationException
      {
          String base = config.getAttribute("dir");
          ArrayList list = new ArrayList();
          Configuration[] includeConfigs = config.getChildren("include");
          for( int i=0; i<includeConfigs.length; i++ )
          {
              Configuration includeConfig = includeConfigs[i];
              list.add( createIncludeDescriptor( includeConfig ) );
          }
          IncludeDescriptor[] includes = (IncludeDescriptor[]) list.toArray( new IncludeDescriptor[0]
);
          return new DirsetDescriptor( base, includes );
      }
  
  }
  
  
  

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