User: vharcq  
  Date: 02/04/02 03:29:42

  Modified:    core/src/xdoclet/ejb/tags FinderTagsHandler.java
                        HomeTagsHandler.java InterfaceTagsHandler.java
  Log:
  Custome finders are also handled by FinderTagsHandler from now.
  They also works for CMP beans.
  No ejb:finder is needed above the definition of the custom finder, the tag handler 
will do the work to transform the bean finder definition into a home definition with 
proper attributes and exceptions
  
  Revision  Changes    Path
  1.2       +129 -10   xdoclet/core/src/xdoclet/ejb/tags/FinderTagsHandler.java
  
  Index: FinderTagsHandler.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/ejb/tags/FinderTagsHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- FinderTagsHandler.java    2 Apr 2002 10:12:32 -0000       1.1
  +++ FinderTagsHandler.java    2 Apr 2002 11:29:41 -0000       1.2
  @@ -2,6 +2,7 @@
   
   import xdoclet.XDocletException;
   import xdoclet.util.TypeConversionUtil;
  +import xdoclet.util.Log;
   
   import java.util.Properties;
   import java.util.Set;
  @@ -9,17 +10,21 @@
   import java.util.StringTokenizer;
   
   import xjavadoc.XTag;
  +import xjavadoc.XMethod;
  +import xjavadoc.XClass;
  +import org.apache.log4j.Category;
   
   /**
    * Tag handler for finder methods (ejb:finder)
    *
    * @author    Vincent Harcq ([EMAIL PROTECTED])
    * @created   April 2, 2002
  - * @version   $Revision: 1.1 $
  + * @version   $Revision: 1.2 $
    */
   public class FinderTagsHandler extends HomeTagsHandler{
   
       private String currentSignature;
  +    private String currentExceptions;
   
       /**
         * Iterates over all finder methods defined in a class and super classes
  @@ -39,6 +44,7 @@
         */
        public void forAllFinders( String template, Properties attributes ) throws 
XDocletException
        {
  +        Category cat = Log.getCategory(FinderTagsHandler.class,"forAllFinders");
           boolean superclasses = TypeConversionUtil.stringToBoolean( 
attributes.getProperty( "superclasses" ), false );
           String type = attributes.getProperty( "type" );
           if (type == null)
  @@ -47,16 +53,68 @@
           Set already = new HashSet();
   
           // Exclude definition coming from super classes
  -        XTag[] superTags = getCurrentClass().superclass().doc().tags( "ejb:finder", 
true);
  +        XClass currentClass = getCurrentClass().superclass();
  +        while ( currentClass != null )
  +        {
  +            if (cat.isDebugEnabled()) cat.debug("Looking for super definition in 
"+currentClass.name());
  +            // 1. METHOD tags
  +            XMethod[] methods = currentClass.methods();
  +            for (int i = 0; i < methods.length; i++) {
  +                XMethod method = methods[i];
  +                if ( ! isFinderMethod(method))
  +                    continue;
  +                String signature = getHomeFinderDefinition(method);
  +                if (cat.isDebugEnabled()) cat.debug("Found "+signature);
  +                already.add(signature);
  +            }
  +
  +            // 2. CLASS tags
  +            XTag[] superTags = currentClass.doc().tags( "ejb:finder", true);
           for (int i = 0; i < superTags.length; i++) {
               String signature = fullPackageChange(superTags[i].attributeValue( 
"signature" ));
               String typeMapping = superTags[i].attributeValue( "result-type-mapping" 
);
               if (typeMapping == null || typeMapping.equalsIgnoreCase(type) )
               {
  +                    if (cat.isDebugEnabled()) cat.debug("Found "+signature);
                   already.add(signature);
               }
           }
  +            currentClass = currentClass.superclass();
  +        }
  +
  +        // 1. Handle METHOD Tag level ejb:finder
  +        XMethod[] methods = getCurrentClass().methods();
  +        for (int i = 0; i < methods.length; i++) {
  +            XMethod method = methods[i];
  +            if ( ! isFinderMethod(method))
  +                continue;
  +            String signature = getHomeFinderDefinition(method);
  +
  +            if ( !already.add(signature) )
  +                continue;
  +
  +            if (cat.isDebugEnabled()) cat.debug("Finder Method = "+signature);
  +            setCurrentSignature(signature);
  +            XClass[] exceptions = method.thrownExceptions();
  +            StringBuffer exc = new StringBuffer();
  +            for (int j = 0; j < exceptions.length; j++) {
  +                XClass exception = exceptions[j];
  +                exc.append(exception.getClass().getName());
  +                if (j != exceptions.length - 1)
  +                    exc.append(",");
  +            }
  +            if (exc.length() == 0)
  +                exc.append("javax.ejb.FinderException");
  +            if (type.equalsIgnoreCase("remote"))
  +                exc.append(",java.rmi.RemoteException");
  +            setCurrentExceptions(exc.toString());
  +            // For javadoc comment only
  +            setCurrentMethod(method);
  +
  +            generate( template );
  +        }
   
  +        // 2. Handle CLASS Tag level ejb:finder
                XTag[] tags = getCurrentClass().doc().tags( "ejb:finder", superclasses 
);
           for( int i = 0; i < tags.length; i++ )
                {
  @@ -67,10 +125,15 @@
                   if ( !already.add(signature) )
                       continue;
   
  -                System.out.println("key="+signature);
  +                if (cat.isDebugEnabled()) cat.debug("Finder Method = "+signature);
   
                   setCurrentTag( tags[i] );
                   setCurrentSignature(signature);
  +                StringBuffer exc = new StringBuffer();
  +                if (type.equalsIgnoreCase("remote"))
  +                    exc.append("java.rmi.RemoteException,");
  +                exc.append("javax.ejb.FinderException");
  +                setCurrentExceptions(exc.toString());
   
                   generate( template );
               }
  @@ -78,7 +141,8 @@
   
                setCurrentTag( null );
           setCurrentSignature(null);
  -
  +        setCurrentExceptions(null);
  +        setCurrentMethod(null);
   
       }
   
  @@ -87,12 +151,48 @@
           return currentSignature;
       }
   
  +    public String currentExceptions() throws XDocletException
  +     {
  +        return currentExceptions;
  +    }
  +
       protected void setCurrentSignature(String cs)
       {
           this.currentSignature = cs;
       }
   
  -    private String fullPackageChange(String s)
  +    protected void setCurrentExceptions(String es)
  +    {
  +        this.currentExceptions = es;
  +    }
  +
  +    /**
  +      * Returns true if method is an ejbFind method, false otherwise.
  +      *
  +      * @param method                Description of Parameter
  +      * @return                      The FinderMethod value
  +      * @exception XDocletException  Description of Exception
  +      */
  +     public static boolean isFinderMethod( XMethod method ) throws XDocletException
  +     {
  +             return method.name().startsWith( "ejbFind" );
  +     }
  +
  +    /**
  +      * Converts ejbFind<em>blabla</em> to find<em>blabla</em> , the one that should
  +      * appear in home interface.
  +      *
  +      * @param methodName            Description of Parameter
  +      * @return                      Description of the Returned Value
  +      * @exception XDocletException  Description of Exception
  +      */
  +     public static String toFinderMethod( String methodName ) throws 
XDocletException
  +     {
  +             // Remove "ejb" prefix and lower case first char in rest: 
"ejbFindByPrimaryKey"->"findByPrimaryKey"
  +             return Character.toLowerCase( methodName.charAt( 3 ) ) + 
methodName.substring( 4 );
  +     }
  +
  +    public static String fullPackageChange(String s)
       {
           StringTokenizer st = new StringTokenizer(s," ");
           String sign = st.nextToken();
  @@ -111,4 +211,23 @@
           return ret.toString();
       }
   
  +    public static String getHomeFinderDefinition(XMethod method)
  +    {
  +        String methodName = method.name().substring(3);
  +        StringBuffer homeMethodName = new StringBuffer();
  +        homeMethodName.append(method.returnType()).append(" ");
  +        homeMethodName.append(methodName.substring(0,1).toLowerCase());
  +        homeMethodName.append(methodName.substring(1));
  +        homeMethodName.append("(");
  +        StringTokenizer st = new 
StringTokenizer(method.signature().substring(1,method.signature().length() - 1),",");
  +        int k = 1;
  +        while (st.hasMoreTokens())
  +        {
  +            homeMethodName.append(st.nextToken()).append(" 
").append("param").append(k++);
  +            if (st.hasMoreTokens()) homeMethodName.append(" , ");
  +        }
  +        homeMethodName.append(")");
  +        return fullPackageChange(homeMethodName.toString());
  +
  +    }
   }
  
  
  
  1.21      +27 -53    xdoclet/core/src/xdoclet/ejb/tags/HomeTagsHandler.java
  
  Index: HomeTagsHandler.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/ejb/tags/HomeTagsHandler.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -w -r1.20 -r1.21
  --- HomeTagsHandler.java      24 Mar 2002 17:44:13 -0000      1.20
  +++ HomeTagsHandler.java      2 Apr 2002 11:29:41 -0000       1.21
  @@ -20,7 +20,7 @@
   /**
    * @author    Ara Abrahamian ([EMAIL PROTECTED])
    * @created   Oct 15, 2001
  - * @version   $Revision: 1.20 $
  + * @version   $Revision: 1.21 $
    */
   public class HomeTagsHandler extends EjbTagsHandler
   {
  @@ -109,18 +109,6 @@
        }
   
        /**
  -      * Returns true if method is an ejbFind method, false otherwise.
  -      *
  -      * @param method                Description of Parameter
  -      * @return                      The FinderMethod value
  -      * @exception XDocletException  Description of Exception
  -      */
  -     public static boolean isFinderMethod( XMethod method ) throws XDocletException
  -     {
  -             return method.name().startsWith( "ejbFind" );
  -     }
  -
  -     /**
         * Returns true if method is an ejbRemove method, false otherwise.
         *
         * @param method                Description of Parameter
  @@ -201,20 +189,6 @@
                        return "create";
        }
   
  -     /**
  -      * Converts ejbFind<em>blabla</em> to find<em>blabla</em> , the one that should
  -      * appear in home interface.
  -      *
  -      * @param methodName            Description of Parameter
  -      * @return                      Description of the Returned Value
  -      * @exception XDocletException  Description of Exception
  -      */
  -     public static String toFinderMethod( String methodName ) throws 
XDocletException
  -     {
  -             // Remove "ejb" prefix and lower case first char in rest: 
"ejbFindByPrimaryKey"->"findByPrimaryKey"
  -             return Character.toLowerCase( methodName.charAt( 3 ) ) + 
methodName.substring( 4 );
  -     }
  -
        public static XMethod findFirstCreateMethodFor( XClass clazz ) throws 
XDocletException
        {
                XMethod[] methods = clazz.methods();
  @@ -350,32 +324,32 @@
                        generate( template );
        }
   
  -     /**
  -      * Evaluates the body block if current method is a ejbFind method.
  -      *
  -      * @param template              The body of the block tag
  -      * @param attributes            The attributes of the template tag
  -      * @exception XDocletException  Description of Exception
  -      * @see                         #isHomeMethod(xjavadoc.XMethod)
  -      * @doc:tag                     type="block"
  -      * @doc:param                   name="superclasses" optional="true"
  -      *      description="Traverse superclasses too. With false value used in
  -      *      remote/local home interface templates. Default is False."
  -      */
  -     public void ifIsFinderMethod( String template, Properties attributes ) throws 
XDocletException
  -     {
  -             String superclasses_str = attributes.getProperty( "superclasses" );
  -             boolean superclasses = TypeConversionUtil.stringToBoolean( 
superclasses_str, true );
  -
  -             if( isFinderMethod( getCurrentMethod() ) )
  -             {
  -                     if( superclasses == false && 
getCurrentMethod().containingClass() != getCurrentClass() && 
shouldTraverseSuperclassForDependentClass( getCurrentMethod().containingClass(), 
"ejb:home" ) == false )
  -                             return;
  -
  -                     generate( template );
  -             }
  -     }
  -
  +//   /**
  +//    * Evaluates the body block if current method is a ejbFind method.
  +//    *
  +//    * @param template              The body of the block tag
  +//    * @param attributes            The attributes of the template tag
  +//    * @exception XDocletException  Description of Exception
  +//    * @see                         #isHomeMethod(xjavadoc.XMethod)
  +//    * @doc:tag                     type="block"
  +//    * @doc:param                   name="superclasses" optional="true"
  +//    *      description="Traverse superclasses too. With false value used in
  +//    *      remote/local home interface templates. Default is False."
  +//    */
  +//   public void ifIsFinderMethod( String template, Properties attributes ) throws 
XDocletException
  +//   {
  +//           String superclasses_str = attributes.getProperty( "superclasses" );
  +//           boolean superclasses = TypeConversionUtil.stringToBoolean( 
superclasses_str, true );
  +//
  +//           if( isFinderMethod( getCurrentMethod() ) )
  +//           {
  +//                   if( superclasses == false && 
getCurrentMethod().containingClass() != getCurrentClass() && 
shouldTraverseSuperclassForDependentClass( getCurrentMethod().containingClass(), 
"ejb:home" ) == false )
  +//                           return;
  +//
  +//                   generate( template );
  +//           }
  +//   }
  +//
        /**
         * @param attributes            The attributes of the template tag
         * @return                      Description of the Returned Value
  
  
  
  1.24      +3 -3      xdoclet/core/src/xdoclet/ejb/tags/InterfaceTagsHandler.java
  
  Index: InterfaceTagsHandler.java
  ===================================================================
  RCS file: 
/cvsroot/xdoclet/xdoclet/core/src/xdoclet/ejb/tags/InterfaceTagsHandler.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -w -r1.23 -r1.24
  --- InterfaceTagsHandler.java 24 Mar 2002 17:44:13 -0000      1.23
  +++ InterfaceTagsHandler.java 2 Apr 2002 11:29:41 -0000       1.24
  @@ -28,7 +28,7 @@
   /**
    * @author    Ara Abrahamian ([EMAIL PROTECTED])
    * @created   Oct 15, 2001
  - * @version   $Revision: 1.23 $
  + * @version   $Revision: 1.24 $
    */
   public class InterfaceTagsHandler extends EjbTagsHandler
   {
  @@ -126,7 +126,7 @@
                return isComponentInterfaceMethod( method ) ||
                        HomeTagsHandler.isCreateMethod( method ) ||
                        HomeTagsHandler.isRemoveMethod( method ) ||
  -                     HomeTagsHandler.isFinderMethod( method ) ||
  +                     FinderTagsHandler.isFinderMethod( method ) ||
                        HomeTagsHandler.isHomeMethod( method );
        }
   
  @@ -596,7 +596,7 @@
                else if( name.equals( "ejbRemove" ) )
                        return "remove";
                else if( name.startsWith( "ejbFind" ) )
  -                     return HomeTagsHandler.toFinderMethod( name );
  +                     return FinderTagsHandler.toFinderMethod( name );
                else if( name.startsWith( "ejbHome" ) )
                        return HomeTagsHandler.toHomeMethod( name );
                else
  
  
  

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

Reply via email to