Hi,

when I used the javadocs-tags for all my merlin services I finally came across the need, to collect all the tags
from the overwritten service-methods of the complete inehritance graph, to produce the correct xtype-file.


the attached patch just does this for service, enableLogging and context methods and their tags.

the test does OK and it works for my services, but I wonder if there is a need to extends the testcase to reflect this
extra functionality. if yes I can do this extension.


best wishes Kristian

PS
let me know if you need another format for the patch




? patch
Index: src/java/org/apache/avalon/meta/info/builder/tags/AbstractTag.java
===================================================================
RCS file: 
/home/cvspublic/avalon-sandbox/merlin/meta-tools/src/java/org/apache/avalon/meta/info/builder/tags/AbstractTag.java,v
retrieving revision 1.4
diff -u -r1.4 AbstractTag.java
--- src/java/org/apache/avalon/meta/info/builder/tags/AbstractTag.java  14 May 2003 
09:36:10 -0000      1.4
+++ src/java/org/apache/avalon/meta/info/builder/tags/AbstractTag.java  22 May 2003 
06:17:33 -0000
@@ -49,12 +49,16 @@
 
 package org.apache.avalon.meta.info.builder.tags;
 
-import org.apache.avalon.framework.Version;
 
 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 java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import org.apache.avalon.framework.Version;
 
 /**
  * A doclet tag representing the name of the Type.
@@ -250,20 +254,23 @@
 
 
     /**
-     * Retrieve a method with specified name and one parameter of specified
-     * type. The method must also return void.
+     * Retrieves all methods in the inheritance graph with specified name and 
+     * one parameter of specified type. The methods must also return void.
      *
-     * @param methodName the name of the method
+     * @param methodName the name of the methods
      * @param parameterType the class name of parameter
-     * @return the method if such a method exists
+     * @return an array of such methods
      */
-    protected JavaMethod getLifecycleMethod( final String methodName,
-                                             final String parameterType )
+    protected JavaMethod[] getLifecycleMethods( final String methodName,
+                                                   final String parameterType )
     {
-        return findLifecycleMethod( getJavaClass(), methodName, parameterType );
+       List result = new ArrayList();
+       findLifecycleMethod( result, getJavaClass(), methodName, parameterType );
+       return (JavaMethod[]) result.toArray( new JavaMethod[ result.size() ] );
     }
 
-    private JavaMethod findLifecycleMethod( 
+    private void findLifecycleMethod( 
+            final List result,
             final JavaClass clazz,
             final String methodName,
             final String parameterType )
@@ -277,20 +284,17 @@
                 && method.getParameters().length == 1
                 && method.getParameters()[ 0 ].getType().getValue().equals( 
parameterType ) )
             {
-                return method;
+                result.add( method );
+               break;          
             }
         }
 
         if( 
-            clazz.getSuperJavaClass() == null 
-            || JavaClass.OBJECT.equals( clazz.getSuperClass() ) )
-        {
-            return null;
-        }
-        else
+            clazz.getSuperJavaClass() != null 
+            && !JavaClass.OBJECT.equals( clazz.getSuperClass() ) )
         {
-            return this.findLifecycleMethod( 
-              clazz.getSuperJavaClass(), methodName, parameterType );
+            this.findLifecycleMethod( 
+              result, clazz.getSuperJavaClass(), methodName, parameterType );
         }
     }
 }
Index: src/java/org/apache/avalon/meta/info/builder/tags/ContextTag.java
===================================================================
RCS file: 
/home/cvspublic/avalon-sandbox/merlin/meta-tools/src/java/org/apache/avalon/meta/info/builder/tags/ContextTag.java,v
retrieving revision 1.3
diff -u -r1.3 ContextTag.java
--- src/java/org/apache/avalon/meta/info/builder/tags/ContextTag.java   16 Apr 2003 
14:19:42 -0000      1.3
+++ src/java/org/apache/avalon/meta/info/builder/tags/ContextTag.java   22 May 2003 
06:17:33 -0000
@@ -49,15 +49,17 @@
 
 package org.apache.avalon.meta.info.builder.tags;
 
-import java.util.ArrayList;
 
-import org.apache.avalon.meta.info.ContextDescriptor;
-import org.apache.avalon.meta.info.EntryDescriptor;
-import org.apache.avalon.meta.info.ReferenceDescriptor;
 
 import com.thoughtworks.qdox.model.DocletTag;
 import com.thoughtworks.qdox.model.JavaClass;
 import com.thoughtworks.qdox.model.JavaMethod;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Set;
+import org.apache.avalon.meta.info.ContextDescriptor;
+import org.apache.avalon.meta.info.EntryDescriptor;
+import org.apache.avalon.meta.info.ReferenceDescriptor;
 
 /**
  * A doclet tag handler for the 'extension' tag.
@@ -118,9 +120,9 @@
     */
     public ContextDescriptor getContext()
     {
-        final JavaMethod method =
-            getLifecycleMethod( "contextualize", CONTEXT_CLASS );
-        if( null == method )
+        final JavaMethod[] methods =
+            getLifecycleMethods( "contextualize", CONTEXT_CLASS );
+        if( methods.length == 0 )//null == method )
         {
             return new ContextDescriptor(
               new ReferenceDescriptor( CONTEXT_CLASS  ),
@@ -129,7 +131,7 @@
         else
         {
             String type = CONTEXT_CLASS;
-            final DocletTag tag = method.getTagByName( getNS() + Tags.DELIMITER + KEY 
);
+            final DocletTag tag = methods[0].getTagByName( getNS() + Tags.DELIMITER + 
KEY );
             if( null != tag && null != tag.getNamedParameter( TYPE_PARAM ) )
             {
                 final String value = getNamedParameter( tag, TYPE_PARAM );
@@ -137,14 +139,21 @@
             }
 
             final ArrayList list = new ArrayList();
-            final DocletTag[] tags = method.getTagsByName( getNS() + Tags.DELIMITER + 
ENTRY );
-            for( int i = 0; i < tags.length; i++ )
-            {
-                list.add( getEntry( tags[i] ) );
-            }
-
-            final EntryDescriptor[] entries =
-                (EntryDescriptor[])list.toArray( new EntryDescriptor[ list.size() ] );
+            final Set marked = new HashSet( 10 );
+           for( int j = 0; j < methods.length; j++ )
+           {
+               final DocletTag[] tags = methods[j].getTagsByName( getNS() + 
Tags.DELIMITER + ENTRY );
+               for( int i = 0; i < tags.length; i++ )
+               {
+                   final String key = getNamedParameter( tags[i], KEY_PARAM );
+                   if( !marked.contains( key ) ){
+                       list.add( getEntry( tags[i] ) );
+                       marked.add( key );
+                   }
+               }
+           }
+           final EntryDescriptor[] entries =
+               (EntryDescriptor[])list.toArray( new EntryDescriptor[ list.size() ] );
             return new ContextDescriptor(
               new ReferenceDescriptor( type ), entries, null );
         }
Index: src/java/org/apache/avalon/meta/info/builder/tags/DependencyTag.java
===================================================================
RCS file: 
/home/cvspublic/avalon-sandbox/merlin/meta-tools/src/java/org/apache/avalon/meta/info/builder/tags/DependencyTag.java,v
retrieving revision 1.4
diff -u -r1.4 DependencyTag.java
--- src/java/org/apache/avalon/meta/info/builder/tags/DependencyTag.java        14 May 
2003 09:36:10 -0000      1.4
+++ src/java/org/apache/avalon/meta/info/builder/tags/DependencyTag.java        22 May 
2003 06:17:33 -0000
@@ -49,15 +49,17 @@
 
 package org.apache.avalon.meta.info.builder.tags;
 
-import java.util.ArrayList;
 
-import org.apache.avalon.framework.Version;
-import org.apache.avalon.meta.info.DependencyDescriptor;
-import org.apache.avalon.meta.info.ReferenceDescriptor;
 
 import com.thoughtworks.qdox.model.DocletTag;
 import com.thoughtworks.qdox.model.JavaClass;
 import com.thoughtworks.qdox.model.JavaMethod;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Set;
+import org.apache.avalon.framework.Version;
+import org.apache.avalon.meta.info.DependencyDescriptor;
+import org.apache.avalon.meta.info.ReferenceDescriptor;
 
 /**
  * A doclet tag representing the lifestyle assigned to the Type.
@@ -99,7 +101,7 @@
     protected static final String SERVICE_MANAGER_CLASS =
         "org.apache.avalon.framework.service.ServiceManager";
 
-    private JavaMethod m_method;
+    private JavaMethod[] m_methods;
 
 
    /**
@@ -109,7 +111,7 @@
     public DependencyTag( final JavaClass clazz )
     {
         super( clazz );
-        setMethod();
+        setMethods();
     }
 
    /**
@@ -119,20 +121,23 @@
     */
     public DependencyDescriptor[] getDependencies()
     {
-        if( null == m_method )
-        {
-            return new DependencyDescriptor[0];
-        }
-
         final ArrayList deps = new ArrayList();
-        final DocletTag[] tags = 
-          getMethod().getTagsByName( getNS() 
-          + Tags.DELIMITER + KEY );
-
-        for( int i = 0; i < tags.length; i++ )
-        {
-            deps.add( getDependency( tags[i] ) );
-        }
+        final Set marked = new HashSet( 10 );
+        for( int j = 0; j < m_methods.length; j++ )
+       {
+           final DocletTag[] tags = 
+               m_methods[j].getTagsByName( getNS() 
+                                             + Tags.DELIMITER + KEY );
+
+           for( int i = 0; i < tags.length; i++ )
+           {
+               final String key = getNamedParameter( tags[i], TYPE_PARAM );
+               if( !marked.contains( key ) ){
+                   deps.add( getDependency( tags[i] ) );
+                   marked.add( key );
+               }
+           }
+       }
         return (DependencyDescriptor[])deps.toArray( new DependencyDescriptor[ 
deps.size() ] );
     }
 
@@ -151,20 +156,20 @@
    /**
     * Set the value of the composition method.
     */
-    private void setMethod()
+    private void setMethods()
     {
-        m_method = getLifecycleMethod( "compose", COMPONENT_MANAGER_CLASS );
-        if( null == m_method )
+        m_methods = getLifecycleMethods( "compose", COMPONENT_MANAGER_CLASS );
+        if( m_methods.length == 0 )
         {
-            m_method = getLifecycleMethod( "service", SERVICE_MANAGER_CLASS );
+            m_methods = getLifecycleMethods( "service", SERVICE_MANAGER_CLASS );
         }
     }
 
    /**
     * Return the composition method.
     */
-    private JavaMethod getMethod()
+    private JavaMethod[] getMethods()
     {
-        return m_method;
+        return m_methods;
     }
 }
Index: src/java/org/apache/avalon/meta/info/builder/tags/LoggerTag.java
===================================================================
RCS file: 
/home/cvspublic/avalon-sandbox/merlin/meta-tools/src/java/org/apache/avalon/meta/info/builder/tags/LoggerTag.java,v
retrieving revision 1.3
diff -u -r1.3 LoggerTag.java
--- src/java/org/apache/avalon/meta/info/builder/tags/LoggerTag.java    16 Apr 2003 
14:19:42 -0000      1.3
+++ src/java/org/apache/avalon/meta/info/builder/tags/LoggerTag.java    22 May 2003 
06:17:34 -0000
@@ -49,13 +49,15 @@
 
 package org.apache.avalon.meta.info.builder.tags;
 
-import java.util.ArrayList;
 
-import org.apache.avalon.meta.info.LoggerDescriptor;
 
 import com.thoughtworks.qdox.model.DocletTag;
 import com.thoughtworks.qdox.model.JavaClass;
 import com.thoughtworks.qdox.model.JavaMethod;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Set;
+import org.apache.avalon.meta.info.LoggerDescriptor;
 
 /**
  * A doclet tag handler supporting 'logger' tags.
@@ -97,27 +99,30 @@
     */
     public LoggerDescriptor[] getLoggers()
     {
-        final JavaMethod method =
-            getLifecycleMethod( "enableLogging", LOGGER_CLASS );
-
-        if( null == method )
-        {
-            return new LoggerDescriptor[0];
-        }
-        else
-        {
-            final ArrayList loggers = new ArrayList();
-            final DocletTag[] tags = method.getTagsByName( getNS() + Tags.DELIMITER + 
KEY  );
-
-            for( int i = 0; i < tags.length; i++ )
-            {
-                final String name =
+        final JavaMethod[] methods =
+            getLifecycleMethods( "enableLogging", LOGGER_CLASS );
+       final ArrayList loggers = new ArrayList();
+       final Set marked = new HashSet( 10 );
+        
+       for( int j = 0; j < methods.length; j++ )
+       {
+           final DocletTag[] tags = 
+               methods[j].getTagsByName( getNS() 
+                                         + Tags.DELIMITER + KEY );
+
+           for( int i = 0; i < tags.length; i++ )
+           {
+               final String name =
                     getNamedParameter( tags[ i ], NAME_PARAM, "" );
-                final LoggerDescriptor logger =
-                    new LoggerDescriptor( name, null );
-                loggers.add( logger );
-            }
-            return (LoggerDescriptor[])loggers.toArray( new LoggerDescriptor[ 
loggers.size() ] );
-        }
+                
+               if( !marked.contains( name ) ){
+                   final LoggerDescriptor logger =
+                       new LoggerDescriptor( name, null );
+                   loggers.add( logger );
+                   marked.add( name );
+               }
+           }
+       }
+       return (LoggerDescriptor[])loggers.toArray( new LoggerDescriptor[ 
loggers.size() ] );
     }
 }

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to