And why there's no simple forAllProeprties method? What if you just want
to iterate on getter/setters and not getter/setters having @tag x?

Ara.

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:xdoclet-devel-
> [EMAIL PROTECTED]] On Behalf Of David Jencks
> Sent: Thursday, February 28, 2002 7:59 PM
> To: [EMAIL PROTECTED]
> Subject: [Xdoclet-devel] CVS update: xdoclet/core/src/xdoclet/tags
> PropertyTagsHandler.java
> 
>   User: d_jencks
>   Date: 02/02/28 08:28:44
> 
>   Added:       core/src/xdoclet/tags PropertyTagsHandler.java
>   Log:
>   New PropertyTagsHandler. For use with getter/setter methods having a
> specified tag.  Provides access to the other method of the pair.
> Generally other method tags should be located on the first method in
the
> file of the getter/setter pair
> 
>   Revision  Changes    Path
>   1.1
> xdoclet/core/src/xdoclet/tags/PropertyTagsHandler.java
> 
>   Index: PropertyTagsHandler.java
>   ===================================================================
> 
>   package xdoclet.tags;
> 
>   import com.sun.javadoc.*;
> 
>   import xdoclet.XDocletException;
>   import xdoclet.ejb.DataObjectSubTask;
>   import xdoclet.template.PrettyPrintWriter;
>   import xdoclet.util.DocletUtil;
>   import xdoclet.util.TypeConversionUtil;
>   import xdoclet.util.Log;
>   import xdoclet.util.Translator;
> 
>   import java.beans.Introspector;
>   import java.util.*;
> 
>   import org.apache.log4j.Category;
> 
>   /**
>    * PropertyTagsHandler.java
>    *
>    * @author    <a href="mailto:[EMAIL PROTECTED]";>David
> Jencks</a>
>    * @created   Wed Feb 27 21:53:15 2002
>    * @version   $$
>    */
> 
>   public class PropertyTagsHandler extends
> AbstractProgramElementTagsHandler
>   {
> 
>       /**
>        * Evaluates the body block for each managed attribute of
current
> mbean.You may
>        * set whether superclasses are examined also with the
superclass
> attribute.
>        * Finds attributes with getter, setter, or both. The getter and
> setter should
>        * have javabean naming convention. (david jencks)
>        *
>        * @param template              The body of the block tag
>        * @param attributes
>        * @exception XDocletException  Description of Exception
>        * @doc:tag                     type="block"
>        * @doc:param                   name="superclasses"
optional="true"
>        *      values="true,false" description="Include properties of
> superclasses.
>        *      True by default."
>        * @doc:param                   name="tagName" optional="false"
>        *      description="The required tag for methods to be
considered a
> getter or
>        *      setter. For example, jmx:managed-attribute."
>        */
>       public void forAllPropertiesWithTag( String template, Properties
> attributes ) throws XDocletException
>       {
>               Category cat = Log.getCategory(
PropertyTagsHandler.class,
> "forAllPropertiesHavingTag" );
> 
>               cat.debug( "in forAllPropertiesHavingTag" );
> 
>               boolean superclasses =
TypeConversionUtil.stringToBoolean(
> attributes.getProperty( "superclasses" ), true );
> 
>               String requiredTag = attributes.getProperty( "tagName"
);
> 
>               if( requiredTag == null )
>               {
>                       throw new XDocletException( "missing required
tag
> parameter in forAllPropertiesHavingTag" );
>               }
> 
>               // end of if ()
> 
>               ClassDoc oldClass = getCurrentClass();
>               List already = new ArrayList();
> 
>               //loop over superclasses
>               do
>               {
>                       MethodDoc[] methods =
getCurrentClass().methods();
>                       MethodDoc old_cur_method = getCurrentMethod();
> 
>                       for( int j = 0; j < methods.length; j++ )
>                       {
>                               MethodDoc current_method = methods[j];
> 
>                               cat.debug( "looking at method " +
> current_method.name() );
>                               if( DocletUtil.hasTag( current_method,
requiredTag
> ) )
>                               {
>                                       setCurrentMethod( current_method
);
> 
>                                       String property_name =
> MethodTagsHandler.getMethodNameWithoutPrefixFor( current_method );
> 
>                                       cat.debug( "property identified
" +
> property_name );
> 
>                                       if( !already.contains(
property_name ) )
>                                       {
>                                               generate( template );
> 
>                                               already.add(
property_name );
>                                       }
>                               }
> 
>                               setCurrentMethod( old_cur_method );
> 
>                       }
>                       // Add super class info
>                       pushCurrentClass( getCurrentClass().superclass()
);
>               }while ( superclasses && getCurrentClass() != null );
> 
>               setCurrentClass( oldClass );
>       }
> 
>       /**
>        * The block tag <code>ifHasGetMethod</code> looks for a get
method
> based on
>        * the attribute name from the current method, sets the current
> method to that
>        * get method, and applies the template if found. This is used
to
> look for
>        * getters for mbean managed attributes. The get method found
may be
> the
>        * current method.
>        *
>        * @param template              a <code>String</code> value
>        * @param attributes            a <code>Properties</code> value
>        * @exception XDocletException  if an error occurs
>        * @doc:tag                     type="block"
>        * @doc:param                   name="tagName" optional="false"
>        *      description="The required tag for methods to be
considered a
> getter or
>        *      setter. For example, jmx:managed-attribute.
>        */
>       public void ifHasGetMethodWithTag( String template, Properties
> attributes ) throws XDocletException
>       {
>               MethodDoc get_method = getGetMethodWithTag( attributes
);
> 
>               if( get_method != null )
>               {
>                       MethodDoc old_method = getCurrentMethod();
> 
>                       setCurrentMethod( get_method );
>                       try
>                       {
>                               generate( template );
>                       }
>                       finally
>                       {
>                               setCurrentMethod( old_method );
>                       }
>                       // end of try-catch
>               }
>       }
> 
>       /**
>        * The block tag <code>ifHasSetMethod</code> looks for a set
method
> based on
>        * the attribute name from the current method, sets the current
> method to that
>        * set method, and applies the template if found. This is used
to
> look for
>        * setters for mbean managed attributes. The set method found
may be
> the
>        * current method.
>        *
>        * @param template              a <code>String</code> value
>        * @param attributes            a <code>Properties</code> value
>        * @exception XDocletException  if an error occurs
>        * @doc:tag                     type="block"
>        * @doc:param                   name="tagName" optional="false"
>        *      description="The required tag for methods to be
considered a
> getter or
>        *      setter. For example, jmx:managed-attribute."
>        */
>       public void ifHasSetMethodWithTag( String template, Properties
> attributes ) throws XDocletException
>       {
>               MethodDoc set_method = getSetMethodWithTag( attributes
);
> 
>               if( set_method != null )
>               {
>                       MethodDoc old_method = getCurrentMethod();
> 
>                       setCurrentMethod( set_method );
>                       try
>                       {
>                               generate( template );
>                       }
>                       finally
>                       {
>                               setCurrentMethod( old_method );
>                       }
>                       // end of try-catch
>               }
>       }
> 
>       /**
>        * The <code>propertyTypeWithTag</code> method figures out the
type
> for the
>        * current property with tag by looking for a getter, then a
setter.
>        *
>        * @param attributes            a <code>Properties</code> value
> including the
>        *      tagName required.
>        * @return                      the <code>String</code> fully
> qualified name of
>        *      the property type.
>        * @exception XDocletException  if an error occurs
>        * @doc:tag                     type="content"
>        * @doc:param                   name="tagName" optional="false"
>        *      description="The required tag for methods to be
considered a
> getter or
>        *      setter. For example, jmx:managed-attribute."
>        */
>       public String propertyTypeWithTag( Properties attributes )
throws
> XDocletException
>       {
>               MethodDoc getter = getGetMethodWithTag( attributes );
> 
>               if( getter != null )
>               {
>                       return MethodTagsHandler.getMethodTypeFor(
getter );
>               }
> 
>               // end of if ()
> 
>               MethodDoc setter = getSetMethodWithTag( attributes );
> 
>               if( setter != null )
>               {
>                       Parameter parameter = setter.parameters()[0];
> 
>                       return parameter.type().toString();
>               }
>               // end of if ()
>               throw new XDocletException( "no current property found"
);
>       }
> 
>       /**
>        * Searches for the MethodDoc of the method with name methodName
and
> returns
>        * it. Copied from MethodTagsHandler
>        *
>        * @param methodName  Description of Parameter
>        * @return            The MethodDocForMethodName value
>        */
>       protected MethodDoc getMethodDocForMethodName( String methodName
)
>       {
>               if( methodName != null )
>                       return extractMethodDoc( getCurrentClass(),
methodName
> );
> 
>               return null;
>       }
> 
>       private MethodDoc getGetMethodWithTag( Properties attributes )
> throws XDocletException
>       {
>               String requiredTag = attributes.getProperty( "tagName"
);
> 
>               if( requiredTag == null )
>               {
>                       throw new XDocletException( "missing required
tag
> parameter in forAllPropertiesHavingTag" );
>               }
> 
>               // end of if ()
> 
>               MethodDoc current_method = getCurrentMethod();
> 
>               if( current_method.name().startsWith( "get" ) ||
> current_method.name().startsWith( "is" ) )
>               {
>                       if( DocletUtil.hasTag( current_method,
requiredTag ) )
>                       {
>                               return current_method;
>                       }
>                       // end of if ()
> 
>                       return null;
>               }
> 
>               // end of if ()
> 
>               String attributeName =
> MethodTagsHandler.getMethodNameWithoutPrefixFor( current_method );
>               MethodDoc getter = getMethodDocForMethodName( "get" +
> attributeName );
> 
>               if( getter != null )
>               {
>                       if( DocletUtil.hasTag( getter, requiredTag ) )
>                       {
> 
>                               return getter;
>                       }
>                       // end of if ()
> 
>                       return null;
>               }
>               // end of if ()
>               getter = getMethodDocForMethodName( "is" + attributeName
);
>               //not too safe.. should check it's boolean.
>               if( getter != null && DocletUtil.hasTag( getter,
requiredTag )
> )
>               {
>                       return getter;
>               }
>               return null;
>       }
> 
>       private MethodDoc getSetMethodWithTag( Properties attributes )
> throws XDocletException
>       {
>               String requiredTag = attributes.getProperty( "tagName"
);
> 
>               if( requiredTag == null )
>               {
>                       throw new XDocletException( "missing required
tag
> parameter in forAllPropertiesHavingTag" );
>               }
> 
>               // end of if ()
> 
>               MethodDoc current_method = getCurrentMethod();
> 
>               if( current_method.name().startsWith( "set" ) )
>               {
>                       if( DocletUtil.hasTag( current_method,
requiredTag ) )
>                       {
>                               return current_method;
>                       }
>                       // end of if ()
> 
>                       return null;
>               }
> 
>               // end of if ()
> 
>               String attributeName =
> MethodTagsHandler.getMethodNameWithoutPrefixFor( current_method );
>               MethodDoc setter = getMethodDocForMethodName( "set" +
> attributeName );
> 
>               if( setter != null && DocletUtil.hasTag( setter,
requiredTag )
> )
>               {
> 
>                       return setter;
>               }
>               // end of if ()
> 
>               return null;
>       }
> 
>       //copied from MethodTagsHandler
>       private MethodDoc extractMethodDoc( ClassDoc clazz, String
> methodName )
>       {
>               MethodDoc[] methods = clazz.methods();
> 
>               for( int i = 0; i < methods.length; i++ )
>               {
>                       if( methods[i].name().equals( methodName ) )
>                       {
>                               return methods[i];
>                       }
>               }
> 
>               return null;
>       }
> 
>   }
>   // PropertyTagsHandler
> 
> 
> 
> 
> _______________________________________________
> Xdoclet-devel mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/xdoclet-devel


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


_______________________________________________
Xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel

Reply via email to