avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/qdox AbstractInfoBuilder.java QDoxInfoBuilder.java
Date Sat, 16 Nov 2002 05:14:07 GMT
donaldp     2002/11/15 21:14:07

  Modified:    info/src/java/org/apache/avalon/framework/tools/qdox
                        QDoxInfoBuilder.java
  Added:       info/src/java/org/apache/avalon/framework/tools/qdox
                        AbstractInfoBuilder.java
  Log:
  Extract superclass so it is easier to create InfoBuilders that read different javadoc dialects
  
  Revision  Changes    Path
  1.4       +3 -112    jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/qdox/QDoxInfoBuilder.java
  
  Index: QDoxInfoBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/qdox/QDoxInfoBuilder.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- QDoxInfoBuilder.java	16 Nov 2002 04:34:50 -0000	1.3
  +++ QDoxInfoBuilder.java	16 Nov 2002 05:14:07 -0000	1.4
  @@ -10,17 +10,15 @@
   import com.thoughtworks.qdox.model.DocletTag;
   import com.thoughtworks.qdox.model.JavaClass;
   import com.thoughtworks.qdox.model.JavaMethod;
  -import com.thoughtworks.qdox.model.Type;
   import java.util.ArrayList;
  -import org.apache.avalon.framework.info.Attribute;
   import org.apache.avalon.framework.info.ComponentDescriptor;
   import org.apache.avalon.framework.info.ComponentInfo;
   import org.apache.avalon.framework.info.ContextDescriptor;
   import org.apache.avalon.framework.info.DependencyDescriptor;
   import org.apache.avalon.framework.info.EntryDescriptor;
   import org.apache.avalon.framework.info.LoggerDescriptor;
  -import org.apache.avalon.framework.info.ServiceDescriptor;
   import org.apache.avalon.framework.info.SchemaDescriptor;
  +import org.apache.avalon.framework.info.ServiceDescriptor;
   
   /**
    * This is a utility class that is used to build a ComponentInfo object
  @@ -31,22 +29,8 @@
    * @version $Revision$ $Date$
    */
   public class QDoxInfoBuilder
  +    extends AbstractInfoBuilder
   {
  -    private static final String LOGGER_CLASS =
  -        "org.apache.avalon.framework.logger.Logger";
  -    private static final String CONTEXT_CLASS =
  -        "org.apache.avalon.framework.context.Context";
  -    private static final String COMPONENT_MANAGER_CLASS =
  -        "org.apache.avalon.framework.component.ComponentManager";
  -    private static final String SERVICE_MANAGER_CLASS =
  -        "org.apache.avalon.framework.service.ServiceManager";
  -    private static final String CONFIGURATION_CLASS =
  -        "org.apache.avalon.framework.configuration.Configuration";
  -    private static final String PARAMETERS_CLASS =
  -        "org.apache.avalon.framework.parameters.Parameters";
  -
  -    private static final Attribute[] EMPTY_ATTRIBUTES = new Attribute[ 0 ];
  -
       /**
        * Build a ComponentInfo object for specified class.
        *
  @@ -247,98 +231,5 @@
               }
               return (DependencyDescriptor[])deps.toArray( new DependencyDescriptor[ deps.size()
] );
           }
  -    }
  -
  -    /**
  -     * Resolve the specified type.
  -     * Resolving essentially means finding the fully qualified name of
  -     * a class from just it's short name.
  -     *
  -     * @param javaClass the java class relative to which the type must be resolved
  -     * @param type the unresolved type
  -     * @return the resolved type
  -     */
  -    private String resolveType( final JavaClass javaClass,
  -                                final String type )
  -    {
  -        return javaClass.getParentSource().resolveType( type );
  -    }
  -
  -    /**
  -     * Retrieve a method with specified name and one parameter of specified
  -     * type. The method must also return void.
  -     *
  -     * @param javaClass the java class to retrieve method for
  -     * @param methodName the name of the method
  -     * @param parameterType the class name of parameter
  -     * @return the method if such a method exists
  -     */
  -    private JavaMethod getLifecycleMethod( final JavaClass javaClass,
  -                                           final String methodName,
  -                                           final String parameterType )
  -    {
  -        final JavaMethod[] methods = javaClass.getMethods();
  -        for( int i = 0; i < methods.length; i++ )
  -        {
  -            final JavaMethod method = methods[ i ];
  -            if( methodName.equals( method.getName() ) &&
  -                method.getReturns().equals( new Type( "void", 0 ) ) &&
  -                method.getParameters().length == 1 &&
  -                method.getParameters()[ 0 ].getType().getValue().equals( parameterType
) )
  -            {
  -                return method;
  -            }
  -        }
  -        return null;
  -    }
  -
  -    /**
  -     * Retrieve specified named parameter from tag. If the parameter
  -     * does not exist then return specified default value.
  -     *
  -     * @param tag the tag
  -     * @param name the name of parameter
  -     * @return the value of named parameter
  -     */
  -    private String getNamedParameter( final DocletTag tag,
  -                                      final String name,
  -                                      final String defaultValue )
  -    {
  -        String value = tag.getNamedParameter( name );
  -        if( null == value )
  -        {
  -            return defaultValue;
  -        }
  -        value = value.trim();
  -        if( value.startsWith( "\"" ) || value.startsWith( "'" ) )
  -        {
  -            value = value.substring( 1 );
  -        }
  -        if( value.endsWith( "\"" ) || value.endsWith( "'" ) )
  -        {
  -            value = value.substring( 0, value.length() - 1 );
  -        }
  -        return value;
  -    }
  -
  -    /**
  -     * Retrieve specified named parameter from tag. If the parameter
  -     * does not exist then throw an exception.
  -     *
  -     * @param tag the tag
  -     * @param name the name of parameter
  -     * @return the value of named parameter
  -     */
  -    private String getNamedParameter( final DocletTag tag, final String name )
  -    {
  -        final String value = getNamedParameter( tag, name, null );
  -        if( null == value )
  -        {
  -            final String message =
  -                "Malformed tag '" + tag.getName() + "'. " +
  -                "Missing required parameter '" + name + "'";
  -            throw new IllegalArgumentException( message );
  -        }
  -        return value;
       }
   }
  
  
  
  1.1                  jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/qdox/AbstractInfoBuilder.java
  
  Index: AbstractInfoBuilder.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.framework.tools.qdox;
  
  import com.thoughtworks.qdox.model.JavaClass;
  import com.thoughtworks.qdox.model.JavaMethod;
  import com.thoughtworks.qdox.model.Type;
  import com.thoughtworks.qdox.model.DocletTag;
  import org.apache.avalon.framework.info.Attribute;
  
  /**
   * This is an abstract base class that is used to build a ComponentInfo object
   * from QDoxs JavaClass object model. Subclasses interpret different dialects
   * of javadocs markup.
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/11/16 05:14:07 $
   */
  class AbstractInfoBuilder
  {
      protected static final String LOGGER_CLASS =
          "org.apache.avalon.framework.logger.Logger";
      protected static final String CONTEXT_CLASS =
          "org.apache.avalon.framework.context.Context";
      protected static final String COMPONENT_MANAGER_CLASS =
          "org.apache.avalon.framework.component.ComponentManager";
      protected static final String SERVICE_MANAGER_CLASS =
          "org.apache.avalon.framework.service.ServiceManager";
      protected static final String CONFIGURATION_CLASS =
          "org.apache.avalon.framework.configuration.Configuration";
      protected static final String PARAMETERS_CLASS =
          "org.apache.avalon.framework.parameters.Parameters";
      protected static final Attribute[] EMPTY_ATTRIBUTES = new Attribute[ 0 ];
  
      /**
       * Resolve the specified type.
       * Resolving essentially means finding the fully qualified name of
       * a class from just it's short name.
       *
       * @param javaClass the java class relative to which the type must be resolved
       * @param type the unresolved type
       * @return the resolved type
       */
      protected String resolveType( final JavaClass javaClass,
                                    final String type )
      {
          return javaClass.getParentSource().resolveType( type );
      }
  
      /**
       * Retrieve a method with specified name and one parameter of specified
       * type. The method must also return void.
       *
       * @param javaClass the java class to retrieve method for
       * @param methodName the name of the method
       * @param parameterType the class name of parameter
       * @return the method if such a method exists
       */
      protected JavaMethod getLifecycleMethod( final JavaClass javaClass,
                                               final String methodName,
                                               final String parameterType )
      {
          final JavaMethod[] methods = javaClass.getMethods();
          for( int i = 0; i < methods.length; i++ )
          {
              final JavaMethod method = methods[ i ];
              if( methodName.equals( method.getName() ) &&
                  method.getReturns().equals( new Type( "void", 0 ) ) &&
                  method.getParameters().length == 1 &&
                  method.getParameters()[ 0 ].getType().getValue().equals( parameterType )
)
              {
                  return method;
              }
          }
          return null;
      }
  
      /**
       * Retrieve specified named parameter from tag. If the parameter
       * does not exist then return specified default value.
       *
       * @param tag the tag
       * @param name the name of parameter
       * @return the value of named parameter
       */
      protected String getNamedParameter( final DocletTag tag,
                                          final String name,
                                          final String defaultValue )
      {
          String value = tag.getNamedParameter( name );
          if( null == value )
          {
              return defaultValue;
          }
          value = value.trim();
          if( value.startsWith( "\"" ) || value.startsWith( "'" ) )
          {
              value = value.substring( 1 );
          }
          if( value.endsWith( "\"" ) || value.endsWith( "'" ) )
          {
              value = value.substring( 0, value.length() - 1 );
          }
          return value;
      }
  
      /**
       * Retrieve specified named parameter from tag. If the parameter
       * does not exist then throw an exception.
       *
       * @param tag the tag
       * @param name the name of parameter
       * @return the value of named parameter
       */
      protected String getNamedParameter( final DocletTag tag, final String name )
      {
          final String value = getNamedParameter( tag, name, null );
          if( null == value )
          {
              final String message =
                  "Malformed tag '" + tag.getName() + "'. " +
                  "Missing required parameter '" + name + "'";
              throw new IllegalArgumentException( message );
          }
          return value;
      }
  }
  
  
  

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