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/containerkit/src/java/org/apache/excalibur/containerkit/tools/xdoclet IsServiceProvisionFilter.java AvalonTagHandler.java componentinfo.xdt
Date Sun, 25 Aug 2002 12:10:02 GMT
donaldp     2002/08/25 05:10:02

  Modified:    containerkit/src/java/org/apache/excalibur/containerkit/demo/components
                        Component1.java
               containerkit/src/java/org/apache/excalibur/containerkit/tools/xdoclet
                        AvalonTagHandler.java componentinfo.xdt
  Added:       containerkit/src/java/org/apache/excalibur/containerkit/tools/xdoclet
                        IsServiceProvisionFilter.java
  Log:
  Start integrating the next generation of xdoclet and vastly simplifying the
  syntax of the template file.
  
  Revision  Changes    Path
  1.2       +1 -0      jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/demo/components/Component1.java
  
  Index: Component1.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/demo/components/Component1.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Component1.java	23 Aug 2002 08:51:15 -0000	1.1
  +++ Component1.java	25 Aug 2002 12:10:02 -0000	1.2
  @@ -45,6 +45,7 @@
   
       /**
        * @avalon.dependency role="fred" interface="Service1" optional="true" shareable="true"
  +     * @avalon.dependency role="fred" interface="Service1" shareable="true"
        */
       public void service( final ServiceManager manager )
           throws ServiceException
  
  
  
  1.3       +172 -45   jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/tools/xdoclet/AvalonTagHandler.java
  
  Index: AvalonTagHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/tools/xdoclet/AvalonTagHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AvalonTagHandler.java	25 Aug 2002 07:11:24 -0000	1.2
  +++ AvalonTagHandler.java	25 Aug 2002 12:10:02 -0000	1.3
  @@ -7,12 +7,16 @@
    */
   package org.apache.excalibur.containerkit.tools.xdoclet;
   
  -import java.util.Properties;
   import java.util.Collection;
   import java.util.Iterator;
  +import java.util.Properties;
  +import java.util.StringTokenizer;
  +import org.apache.commons.logging.Log;
   import xdoclet.XDocletException;
   import xdoclet.XDocletTagSupport;
  +import xdoclet.util.LogUtil;
   import xjavadoc.XClass;
  +import xjavadoc.XDoc;
   import xjavadoc.XMethod;
   import xjavadoc.XPackage;
   import xjavadoc.XTag;
  @@ -28,6 +32,148 @@
   {
       private static String c_attribute;
   
  +    public void forAllDeps( final String template )
  +        throws XDocletException
  +    {
  +        final IsServiceProvisionFilter filter = new IsServiceProvisionFilter();
  +        final Collection methods =
  +            getCurrentClass().getMethods( filter, false );
  +        final Iterator iterator = methods.iterator();
  +        while( iterator.hasNext() )
  +        {
  +            final XMethod method = (XMethod)iterator.next();
  +            setCurrentMethod( method );
  +            final XDoc doc = method.getDoc();
  +            final Iterator tags =
  +                doc.getTags( "avalon.dependency" ).iterator();
  +            while( tags.hasNext() )
  +            {
  +                final XTag tag = (XTag)tags.next();
  +                setCurrentMethodTag( tag );
  +                generate( template );
  +            }
  +        }
  +    }
  +
  +    public void forAllMethodAttributes( final String template,
  +                                        final Properties attributes )
  +        throws XDocletException
  +    {
  +        final XTag tag = getCurrentMethodTag();
  +        forAllMethodAttributes( tag, template, attributes );
  +    }
  +
  +    private void forAllMethodAttributes( final XTag tag,
  +                                         final String template,
  +                                         final Properties attributes )
  +        throws XDocletException
  +    {
  +        final String[] skips = getSkips( attributes );
  +        final Iterator attributeNames = tag.getAttributeNames().iterator();
  +        while( attributeNames.hasNext() )
  +        {
  +            final String name = (String)attributeNames.next();
  +            if( !matchesSkip( name, skips ) )
  +            {
  +                c_attribute = name;
  +                generate( template );
  +            }
  +        }
  +        c_attribute = null;
  +    }
  +
  +    private boolean matchesSkip( final String name,
  +                                 final String[] skips )
  +    {
  +        for( int i = 0; i < skips.length; i++ )
  +        {
  +            if( skips[ i ].equals( name ) )
  +            {
  +                return true;
  +            }
  +        }
  +        return false;
  +    }
  +
  +    private String[] getSkips( final Properties attributes )
  +    {
  +        final String skipList =
  +            attributes.getProperty( "skip", "" );
  +        return split( skipList, ", " );
  +    }
  +
  +    public String getAttributeValueAsType( final Properties attributes )
  +    {
  +        final Log log =
  +            LogUtil.getLog( AvalonTagHandler.class, "getAttributeValueAsType" );
  +        final String name = attributes.getProperty( "name", "" );
  +        final XTag tag = getCurrentMethodTag();
  +        final String value = tag.getAttributeValue( name );
  +        if( null == value )
  +        {
  +            log.fatal( "Missing attribute value with key '" +
  +                       name + "' in tag" + tag + " in class " +
  +                       getCurrentClass() );
  +            return "";
  +        }
  +
  +        return getQualifiedTypeName( value );
  +    }
  +
  +    private String getQualifiedTypeName( final String typeName )
  +    {
  +        if( -1 != typeName.indexOf( '.' ) )
  +        {
  +            //User has specified full
  +            return typeName;
  +        }
  +        else
  +        {
  +            final XClass currentClass = getCurrentClass();
  +
  +            XClass xClass = null;
  +            Collection classes = null;
  +
  +            classes =
  +                currentClass.getImportedClasses();
  +            xClass = findClass( typeName, classes );
  +            if( null != xClass )
  +            {
  +                return xClass.getQualifiedName();
  +            }
  +
  +            classes =
  +                currentClass.getContainingPackage().getClasses();
  +            xClass = findClass( typeName, classes );
  +            if( null != xClass )
  +            {
  +                return xClass.getQualifiedName();
  +            }
  +
  +            final Iterator xPackages =
  +                currentClass.getImportedPackages().iterator();
  +            while( xPackages.hasNext() )
  +            {
  +                final XPackage xPackage = (XPackage)xPackages.next();
  +                classes = xPackage.getClasses();
  +                xClass = findClass( typeName, classes );
  +                if( null != xClass )
  +                {
  +                    return xClass.getQualifiedName();
  +                }
  +            }
  +
  +            classes = getDefaultPackage().getClasses();
  +            xClass = findClass( typeName, classes );
  +            if( null != xClass )
  +            {
  +                return xClass.getQualifiedName();
  +            }
  +
  +            return typeName;
  +        }
  +    }
  +
       public void setCurrentClassTag( final Properties atributes )
           throws XDocletException
       {
  @@ -93,49 +239,9 @@
   
       public String attributeValueAsType( final Properties attributes )
       {
  -        final String typeName = attributeValue( attributes );
  -        if( -1 != typeName.indexOf( '.' ) )
  -        {
  -            //User has specified full
  -            return typeName;
  -        }
  -        else
  -        {
  -            XClass xClass = null;
  -
  -            xClass = findClass( typeName, getCurrentClass().getImportedClasses() );
  -            if( null != xClass )
  -            {
  -                return xClass.getQualifiedName();
  -            }
  -
  -            final Collection classes = getCurrentClass().getContainingPackage().getClasses();
  -            xClass = findClass( typeName, classes );
  -            if( null != xClass )
  -            {
  -                return xClass.getQualifiedName();
  -            }
  -
  -            final Iterator xPackages =
  -                getCurrentClass().getImportedPackages().iterator();
  -            while( xPackages.hasNext() )
  -            {
  -                final XPackage xPackage = (XPackage)xPackages.next();
  -                xClass = findClass( typeName, xPackage.getClasses() );
  -                if( null != xClass )
  -                {
  -                    return xClass.getQualifiedName();
  -                }
  -            }
  -
  -            xClass = findClass( typeName, getDefaultPackage().getClasses() );
  -            if( null != xClass )
  -            {
  -                return xClass.getQualifiedName();
  -            }
  -
  -            return typeName;
  -        }
  +        final String typeName =
  +            attributeValue( attributes );
  +        return getQualifiedTypeName( typeName );
       }
   
       private XPackage getDefaultPackage()
  @@ -217,4 +323,25 @@
               return getCurrentMethodTag();
           }
       }
  +
  +    /**
  +     * Splits the string on every token into an array of strings.
  +     *
  +     * @param string the string
  +     * @param onToken the token
  +     * @return the resultant array
  +     */
  +    private static final String[] split( final String string, final String onToken )
  +    {
  +        final StringTokenizer tokenizer = new StringTokenizer( string, onToken );
  +        final String[] result = new String[ tokenizer.countTokens() ];
  +
  +        for( int i = 0; i < result.length; i++ )
  +        {
  +            result[ i ] = tokenizer.nextToken();
  +        }
  +
  +        return result;
  +    }
   }
  +
  
  
  
  1.2       +5 -48     jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/tools/xdoclet/componentinfo.xdt
  
  Index: componentinfo.xdt
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/tools/xdoclet/componentinfo.xdt,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- componentinfo.xdt	18 Aug 2002 06:39:00 -0000	1.1
  +++ componentinfo.xdt	25 Aug 2002 12:10:02 -0000	1.2
  @@ -68,60 +68,17 @@
   
     <!-- services that are required by this Component -->
     <dependencies>
  -    <XDtMethod:ifHasMethod name="compose"
  -                           parameters="org.apache.avalon.framework.component.ComponentManager">
  -      <XDtMethod:setCurrentMethod name="compose"
  -                                  parameters="org.apache.avalon.framework.component.ComponentManager">
  -        <XDtMethod:forAllMethodTags tagName="avalon.dependency">
  +  <XDtAvalon:forAllDeps>
       <dependency<XDtMethod:ifHasMethodTag tagName="avalon.dependency" paramName="optional">
optional="<XDtMethod:methodTagValue tagName="avalon.dependency" paramName="optional"/>"</XDtMethod:ifHasMethodTag>>
         <XDtMethod:ifHasMethodTag tagName="avalon.dependency" paramName="role"><role><XDtMethod:methodTagValue
tagName="avalon.dependency" paramName="role"/></role></XDtMethod:ifHasMethodTag>
  -      <XDtAvalon:setCurrentAttribute name="interface"/>
  -      <service-ref type="<XDtAvalon:attributeValueAsType/>"<XDtMethod:ifHasMethodTag
tagName="avalon.dependency" paramName="version"> version="<XDtMethod:methodTagValue
tagName="avalon.dependency" paramName="version"/>"</XDtMethod:ifHasMethodTag>/>
  -      <XDtAvalon:unsetCurrentAttribute/>
  +      <service-ref type="<XDtAvalon:getAttributeValueAsType name="interface"/>"<XDtMethod:ifHasMethodTag
tagName="avalon.dependency" paramName="version"> version="<XDtMethod:methodTagValue
tagName="avalon.dependency" paramName="version"/>"</XDtMethod:ifHasMethodTag>/>
         <attributes>
  -      <XDtAvalon:forAllAttributes isMethod="true">
  -        <XDtAvalon:ifAttributeNameNotEquals value="interface">
  -          <XDtAvalon:ifAttributeNameNotEquals value="version">
  -            <XDtAvalon:ifAttributeNameNotEquals value="role">
  -              <XDtAvalon:ifAttributeNameNotEquals value="optional">
  +      <XDtAvalon:forAllMethodAttributes skip="interface,version,role,optional">
           <attribute key="<XDtAvalon:attributeName/>" value="<XDtAvalon:attributeValue/>"/>
  -              </XDtAvalon:ifAttributeNameNotEquals>
  -            </XDtAvalon:ifAttributeNameNotEquals>
  -          </XDtAvalon:ifAttributeNameNotEquals>
  -        </XDtAvalon:ifAttributeNameNotEquals>
  -      </XDtAvalon:forAllAttributes>
  +      </XDtAvalon:forAllMethodAttributes>
         </attributes>
       </dependency>
  -        </XDtMethod:forAllMethodTags>
  -      </XDtMethod:setCurrentMethod>
  -    </XDtMethod:ifHasMethod>
  -    <XDtMethod:ifHasMethod name="service"
  -                           parameters="org.apache.avalon.framework.service.ServiceManager">
  -      <XDtMethod:setCurrentMethod name="service"
  -                                  parameters="org.apache.avalon.framework.service.ServiceManager">
  -        <XDtMethod:forAllMethodTags tagName="avalon.dependency">
  -    <dependency<XDtMethod:ifHasMethodTag tagName="avalon.dependency" paramName="optional">
optional="<XDtMethod:methodTagValue tagName="avalon.dependency" paramName="optional"/>"</XDtMethod:ifHasMethodTag>>
  -      <XDtMethod:ifHasMethodTag tagName="avalon.dependency" paramName="role"><role><XDtMethod:methodTagValue
tagName="avalon.dependency" paramName="role"/></role></XDtMethod:ifHasMethodTag>
  -      <XDtAvalon:setCurrentAttribute name="interface"/>
  -      <service-ref type="<XDtAvalon:attributeValueAsType/>"<XDtMethod:ifHasMethodTag
tagName="avalon.dependency" paramName="version"> version="<XDtMethod:methodTagValue
tagName="avalon.dependency" paramName="version"/>"</XDtMethod:ifHasMethodTag>/>
  -      <XDtAvalon:unsetCurrentAttribute/>
  -      <attributes>
  -      <XDtAvalon:forAllAttributes isMethod="true">
  -        <XDtAvalon:ifAttributeNameNotEquals value="interface">
  -          <XDtAvalon:ifAttributeNameNotEquals value="version">
  -            <XDtAvalon:ifAttributeNameNotEquals value="role">
  -              <XDtAvalon:ifAttributeNameNotEquals value="optional">
  -        <attribute key="<XDtAvalon:attributeName/>" value="<XDtAvalon:attributeValue/>"/>
  -              </XDtAvalon:ifAttributeNameNotEquals>
  -            </XDtAvalon:ifAttributeNameNotEquals>
  -          </XDtAvalon:ifAttributeNameNotEquals>
  -        </XDtAvalon:ifAttributeNameNotEquals>
  -      </XDtAvalon:forAllAttributes>
  -      </attributes>
  -    </dependency>
  -        </XDtMethod:forAllMethodTags>
  -      </XDtMethod:setCurrentMethod>
  -    </XDtMethod:ifHasMethod>
  +  </XDtAvalon:forAllDeps>
     </dependencies>
   
   </component-info>
  
  
  
  1.1                  jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/tools/xdoclet/IsServiceProvisionFilter.java
  
  Index: IsServiceProvisionFilter.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.containerkit.tools.xdoclet;
  
  import java.util.Collection;
  import xjavadoc.Filter;
  import xjavadoc.XMethod;
  import xjavadoc.XParameter;
  import xjavadoc.XProgramElement;
  
  /**
   * Filter for getting Service Provision methods (ie Serviceable/Composable).
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/08/25 12:10:02 $
   */
  public class IsServiceProvisionFilter
      implements Filter
  {
      private static final String SM_NAME =
          "org.apache.avalon.framework.service.ServiceManager";
      private static final String CM_NAME =
          "org.apache.avalon.framework.component.ComponentManager";
  
      public boolean accept( final XProgramElement element )
      {
          final String name = element.getName();
          final boolean serviceName = name.equals( "service" );
          final boolean composeName = name.equals( "compose" );
          if( !serviceName && !composeName )
          {
              //Need to be named service/compose
              return false;
          }
  
          //need to be a method
          if( !(element instanceof XMethod) )
          {
              return false;
          }
  
          final XMethod method = (XMethod)element;
          final Collection parameters = method.getParameters();
          if( 1 != parameters.size() )
          {
              return false;
          }
  
          final XParameter parameter = (XParameter)parameters.iterator().next();
  
          final String paramType = parameter.getType().getQualifiedName();
          if( serviceName && !paramType.equals( SM_NAME ) )
          {
              return false;
          }
          else if( composeName && !paramType.equals( CM_NAME ) )
          {
              return false;
          }
  
          return true;
      }
  }
  
  
  

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