mcconnell 2003/08/18 20:24:02
Modified: meta/tools/src/java/org/apache/avalon/meta/info/builder/tags
AbstractTag.java ContextTag.java
Log:
Update theb @avalon.context handlering to be more flexible with respect to the stage
strategy.
Revision Changes Path
1.3 +29 -1
avalon-sandbox/meta/tools/src/java/org/apache/avalon/meta/info/builder/tags/AbstractTag.java
Index: AbstractTag.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/meta/tools/src/java/org/apache/avalon/meta/info/builder/tags/AbstractTag.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractTag.java 14 Jul 2003 20:14:24 -0000 1.2
+++ AbstractTag.java 19 Aug 2003 03:24:02 -0000 1.3
@@ -309,4 +309,32 @@
result, clazz.getSuperJavaClass(), methodName, parameterType );
}
}
+
+ JavaMethod[] findTaggedMethods( final JavaClass clazz, String key )
+ {
+ ArrayList list = new ArrayList();
+ return findTaggedMethods( clazz, key, list );
+ }
+
+ private JavaMethod[] findTaggedMethods( final JavaClass clazz, String key, List
list )
+ {
+ final JavaMethod[] methods = clazz.getMethods();
+ for( int i=0; i<methods.length; i++ )
+ {
+ JavaMethod method = methods[i];
+ final DocletTag tag =
+ method.getTagByName( key );
+ if( tag != null ) list.add( method );
+ }
+
+ if(
+ clazz.getSuperJavaClass() != null
+ && !JavaClass.OBJECT.equals( clazz.getSuperClass() ) )
+ {
+ return this.findTaggedMethods( clazz.getSuperJavaClass(), key, list );
+ }
+
+ return (JavaMethod[]) list.toArray( new JavaMethod[0] );
+
+ }
}
1.6 +43 -16
avalon-sandbox/meta/tools/src/java/org/apache/avalon/meta/info/builder/tags/ContextTag.java
Index: ContextTag.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/meta/tools/src/java/org/apache/avalon/meta/info/builder/tags/ContextTag.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ContextTag.java 18 Aug 2003 17:24:25 -0000 1.5
+++ ContextTag.java 19 Aug 2003 03:24:02 -0000 1.6
@@ -49,14 +49,14 @@
package org.apache.avalon.meta.info.builder.tags;
-
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.Properties;
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;
@@ -81,6 +81,11 @@
public static final String KEY = "context";
/**
+ * The javadoc context context strategy parameter.
+ */
+ public static final String STRATEGY_PARAM = "strategy";
+
+ /**
* The javadoc context tag key parameter.
*/
public static final String KEY_PARAM = "key";
@@ -120,22 +125,19 @@
*/
public ContextDescriptor getContext()
{
- final JavaMethod[] methods =
- getLifecycleMethods( "contextualize", CONTEXT_CLASS );
+ JavaMethod[] methods = findTaggedMethods(
+ getJavaClass(), getNS() + Tags.DELIMITER + ENTRY );
if( methods.length == 0 )
{
return new ContextDescriptor( new EntryDescriptor[0] );
}
else
{
- String type = CONTEXT_CLASS;
- 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 );
- type = resolveType( value );
- }
+
+ //
+ // collect the @avalon.entry tags from this class and
+ // all supertypes methods marked with @avalon.entry
+ //
final ArrayList list = new ArrayList();
final Set marked = new HashSet( 10 );
@@ -153,9 +155,34 @@
}
}
}
+
final EntryDescriptor[] entries =
(EntryDescriptor[])list.toArray( new EntryDescriptor[ list.size() ] );
- return new ContextDescriptor( type, entries );
+
+ String type = null;
+ String strategy = null;
+ for( int j = 0; j < methods.length; j++ )
+ {
+ JavaMethod method = methods[j];
+ final DocletTag tag = method.getTagByName( getNS() + Tags.DELIMITER
+ KEY );
+ if( tag != null )
+ {
+ type =
+ resolveType( getNamedParameter( tag, TYPE_PARAM,
CONTEXT_CLASS ) );
+ strategy = getNamedParameter( tag, STRATEGY_PARAM, null );
+ break;
+ }
+ }
+
+ Properties properties = null;
+ if( strategy != null )
+ {
+ properties = new Properties();
+ properties.setProperty(
+ ContextDescriptor.STRATEGY_KEY, strategy );
+ }
+
+ return new ContextDescriptor( type, entries, properties );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]