You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by do...@apache.org on 2002/06/27 05:30:51 UTC

cvs commit: jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/xdoclet AvalonTagHandler.java AvalonXDoclet.java componentinfo.xdt ComponentInfoSubTask.java

donaldp     2002/06/26 20:30:51

  Added:       containerkit/src/java/org/apache/excalibur/containerkit/xdoclet
                        AvalonTagHandler.java AvalonXDoclet.java
                        componentinfo.xdt ComponentInfoSubTask.java
  Log:
  Add in XDoclet task + template  + taglib that generates descriptors for avalon components
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/xdoclet/AvalonTagHandler.java
  
  Index: AvalonTagHandler.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.xdoclet;
  
  import java.util.Properties;
  import xdoclet.XDocletException;
  import xdoclet.tags.AbstractProgramElementTagsHandler;
  import xjavadoc.XTag;
  import xjavadoc.XClass;
  
  /**
   * A simpler tag handler to walk over attributes in a class.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/27 03:30:50 $
   */
  public class AvalonTagHandler
      extends AbstractProgramElementTagsHandler
  {
      private static String c_attribute;
  
      public void setCurrentClassTag( final Properties atributes )
          throws XDocletException
      {
          final String property = atributes.getProperty( "name", "" );
          final XClass currentClass = getCurrentClass();
          final XTag xTag = currentClass.doc().tag( property );
          setCurrentClassTag( xTag );
      }
  
      /**
       * Iterates over the attributes of current tag.
       */
      public void forAllAttributes( final String template )
          throws XDocletException
      {
          final XTag tag = getCurrentTag();
          final String[] attributes = tag.attributeValueNames();
          for( int i = 0; i < attributes.length; i++ )
          {
              c_attribute = attributes[ i ];
              generate( template );
          }
          c_attribute = null;
      }
  
      public String attributeName()
      {
          return c_attribute;
      }
  
      public String attributeValue()
      {
          final XTag tag = getCurrentTag();
          if( null == c_attribute )
          {
              return "";
          }
          else
          {
              return tag.attributeValue( c_attribute );
          }
      }
  
      public void ifAttributeNameNotEquals( final String template,
                                            final Properties attributes )
          throws XDocletException
      {
          final String value = attributes.getProperty( "value", "" );
          if( !value.equals( c_attribute ) )
          {
              generate( template );
          }
      }
  
      private XTag getCurrentTag()
      {
          XTag tag = getCurrentMethodTag();
          if( null == tag )
          {
              tag = getCurrentClassTag();
          }
          return tag;
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/xdoclet/AvalonXDoclet.java
  
  Index: AvalonXDoclet.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.xdoclet;
  
  import xdoclet.DocletTask;
  import java.util.List;
  
  /**
   * A simple XDoclet task that generates the .xinfo files for
   * services.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/27 03:30:50 $
   */
  public class AvalonXDoclet
      extends DocletTask
  {
      private ComponentInfoSubTask m_componentInfoSubTask;
  
      public ComponentInfoSubTask createComponentInfo()
      {
          m_componentInfoSubTask = new ComponentInfoSubTask();
          return m_componentInfoSubTask;
      }
  
      protected List getSubTasks()
      {
          final List subtasks = super.getSubTasks();
          subtasks.add( m_componentInfoSubTask );
          return subtasks;
      }
  }
  
  
  
  
  
  1.1                  jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/xdoclet/componentinfo.xdt
  
  Index: componentinfo.xdt
  ===================================================================
  <?xml version="1.0" encoding="utf-8" ?>
  
  <!DOCTYPE component-info
        PUBLIC "-//AVALON/Component Info DTD Version 1.0//EN"
        "http://jakarta.apache.org/avalon/componentinfo_1.0.dtd" >
  
  <!-- Autogenerated by XDoclet. Do not Edit! -->
  <component-info>
    <!-- section to describe Component -->
    <component>
      <XDtClass:ifHasClassTag tagName="avalon.component" paramName="name"><name><XDtClass:classTagValue tagName="avalon.component" paramName="name"/></name></XDtClass:ifHasClassTag>
      <version><XDtClass:classTagValue tagName="avalon.component" paramName="version" default="1.0"/></version>
      <XDtAvalon:setCurrentClassTag name="avalon.component"/>
      <attributes>
        <XDtAvalon:forAllAttributes>
          <XDtAvalon:ifAttributeNameNotEquals value="name">
            <XDtAvalon:ifAttributeNameNotEquals value="version">
        <attribute name="<XDtAvalon:attributeName/>" value="<XDtAvalon:attributeValue/>"/>
            </XDtAvalon:ifAttributeNameNotEquals>
          </XDtAvalon:ifAttributeNameNotEquals>
        </XDtAvalon:forAllAttributes>
      </attributes>
    </component>
  
    <!-- services that are offered by this Component -->
    <services>
      <XDtClass:forAllClassTags tagName="avalon.service">
      <service>
        <service-ref name="<XDtClass:classTagValue tagName="avalon.service" paramName="interface"/>"<XDtClass:ifHasClassTag tagName="avalon.service" paramName="version"> version="<XDtClass:classTagValue tagName="avalon.service" paramName="version"/>"</XDtClass:ifHasClassTag>/>
        <attributes>
        <XDtAvalon:forAllAttributes>
          <XDtAvalon:ifAttributeNameNotEquals value="interface">
            <XDtAvalon:ifAttributeNameNotEquals value="version">
          <attribute name="<XDtAvalon:attributeName/>" value="<XDtAvalon:attributeValue/>"/>
            </XDtAvalon:ifAttributeNameNotEquals>
          </XDtAvalon:ifAttributeNameNotEquals>
        </XDtAvalon:forAllAttributes>
        </attributes>
      </service>
      </XDtClass:forAllClassTags>
    </services>
  
    <!-- 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">
      <dependency>
        <XDtMethod:ifHasMethodTag tagName="avalon.dependency" paramName="role"><role><XDtMethod:methodTagValue tagName="avalon.dependency" paramName="role"/></role></XDtMethod:ifHasMethodTag>
        <service name="<XDtMethod:methodTagValue tagName="avalon.dependency" paramName="interface"/>"<XDtMethod:ifHasMethodTag tagName="avalon.dependency" paramName="version"> version="<XDtMethod:methodTagValue tagName="avalon.dependency" paramName="version"/>"</XDtMethod:ifHasMethodTag>/>
        <attributes>
        <XDtAvalon:forAllAttributes>
          <XDtAvalon:ifAttributeNameNotEquals value="interface">
            <XDtAvalon:ifAttributeNameNotEquals value="version">
              <XDtAvalon:ifAttributeNameNotEquals value="role">
          <attribute name="<XDtAvalon:attributeName/>" value="<XDtAvalon:attributeValue/>"/>
              </XDtAvalon:ifAttributeNameNotEquals>
            </XDtAvalon:ifAttributeNameNotEquals>
          </XDtAvalon:ifAttributeNameNotEquals>
        </XDtAvalon:forAllAttributes>
        </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="role"><role><XDtMethod:methodTagValue tagName="avalon.dependency" paramName="role"/></role></XDtMethod:ifHasMethodTag>
        <service name="<XDtMethod:methodTagValue tagName="avalon.dependency" paramName="interface"/>"<XDtMethod:ifHasMethodTag tagName="avalon.dependency" paramName="version"> version="<XDtMethod:methodTagValue tagName="avalon.dependency" paramName="version"/>"</XDtMethod:ifHasMethodTag>/>
        <attributes>
        <XDtAvalon:forAllAttributes>
          <XDtAvalon:ifAttributeNameNotEquals value="interface">
            <XDtAvalon:ifAttributeNameNotEquals value="version">
              <XDtAvalon:ifAttributeNameNotEquals value="role">
          <attribute name="<XDtAvalon:attributeName/>" value="<XDtAvalon:attributeValue/>"/>
              </XDtAvalon:ifAttributeNameNotEquals>
            </XDtAvalon:ifAttributeNameNotEquals>
          </XDtAvalon:ifAttributeNameNotEquals>
        </XDtAvalon:forAllAttributes>
        </attributes>
      </dependency>
          </XDtMethod:forAllMethodTags>
        </XDtMethod:setCurrentMethod>
      </XDtMethod:ifHasMethod>
    </dependencies>
  
  </component-info>
  
  
  
  1.1                  jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/xdoclet/ComponentInfoSubTask.java
  
  Index: ComponentInfoSubTask.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.xdoclet;
  
  import xdoclet.TemplateSubTask;
  import xdoclet.XDocletException;
  import xdoclet.template.TemplateException;
  import java.net.URL;
  import java.io.File;
  import xjavadoc.XClass;
  
  /**
   * Generates ComponentInfo 'xinfo' files for Components.
   *
   * @author <a href="mailto:vinay_chandran@users.sourceforge.net">Vinay Chandrasekharan</a>
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/27 03:30:50 $
   */
  public class ComponentInfoSubTask
      extends TemplateSubTask
  {
      public static final String SUBTASK_NAME = "componentinfo";
  
      private static final String GENERATED_FILE_NAME = "{0}.xinfo";
      private static final String DEFAULT_TEMPLATE_FILE =
          "/org/apache/excalibur/containerkit/xdoclet/componentinfo.xdt";
  
      private static String c_classPattern;
  
      private String m_templatePath;
  
      public ComponentInfoSubTask()
      {
          final URL resource = getClass().getResource( DEFAULT_TEMPLATE_FILE );
          setTemplateURL( resource );
          setDestinationFile( GENERATED_FILE_NAME );
          setHavingClassTag( "avalon.component" );
  
          final TemplateSubTask.ExtentTypes extent = new TemplateSubTask.ExtentTypes();
          extent.setValue( "hierarchy" );
          setExtent( extent );
      }
  
      /**
       * Initialises the subtask.  Add a tag handler for avalon type tags.
       */
      public void init() throws XDocletException
      {
          super.init();
          try
          {
              final AvalonTagHandler tagHandler = new AvalonTagHandler();
              getEngine().setTagHandlerFor( "Avalon", tagHandler );
          }
          catch( final TemplateException e )
          {
              throw new XDocletException( e, e.getMessage() );
          }
      }
  
      public void setTemplatePath( final String templatePath )
      {
          m_templatePath = templatePath;
          setTemplateFile( new File( templatePath ) );
      }
  
      public static String getClassPattern()
      {
          return c_classPattern;
      }
  
      public String getSubTaskName()
      {
          return SUBTASK_NAME;
      }
  
      public void setPattern( final String classPattern )
      {
          c_classPattern = classPattern;
      }
  
      /**
       * Called to validate configuration parameters.
       */
      public void validateOptions()
          throws XDocletException
      {
          super.validateOptions();
  
          if( null == m_templatePath )
          {
              throw new XDocletException( "'templatePath' attribute is missing ." );
          }
  
          final URL template = getTemplateURL();
          if( null == template )
          {
              throw new XDocletException( "'template' is missing." );
          }
  
          if( null == getClassPattern() || getClassPattern().trim().equals( "" ) )
          {
              throw new XDocletException( "'pattern' parameter missing or empty." );
          }
  
          if( -1 == getClassPattern().indexOf( "{0}" ) )
          {
              throw new XDocletException( "'pattern' parameter does not have a " +
                                          "'{0}' in it. '{0}' is replaced by Component " +
                                          "name of the class under processing." );
          }
      }
  
      protected boolean matchesGenerationRules( final XClass clazz )
          throws XDocletException
      {
          if( !super.matchesGenerationRules( clazz ) )
          {
              return false;
          }
          else if( clazz.isAbstract() )
          {
              return false;
          }
          else
          {
              return true;
          }
      }
  }
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>