User: vharcq  
  Date: 02/04/02 02:12:32

  Added:       core/src/xdoclet/ejb/tags FinderTagsHandler.java
  Log:
  Introduce FinderTagsHandler to handle inheritance of finder methods more easily
  
  Revision  Changes    Path
  1.1                  xdoclet/core/src/xdoclet/ejb/tags/FinderTagsHandler.java
  
  Index: FinderTagsHandler.java
  ===================================================================
  package xdoclet.ejb.tags;
  
  import xdoclet.XDocletException;
  import xdoclet.util.TypeConversionUtil;
  
  import java.util.Properties;
  import java.util.Set;
  import java.util.HashSet;
  import java.util.StringTokenizer;
  
  import xjavadoc.XTag;
  
  /**
   * Tag handler for finder methods (ejb:finder)
   *
   * @author    Vincent Harcq ([EMAIL PROTECTED])
   * @created   April 2, 2002
   * @version   $Revision: 1.1 $
   */
  public class FinderTagsHandler extends HomeTagsHandler{
  
      private String currentSignature;
  
      /**
         * Iterates over all finder methods defined in a class and super classes
         *
         * @param template              The body of the block tag
         * @param attributes            The attributes of the template tag
         * @exception XDocletException  Description of Exception
         * @doc:tag                     type="block"
         * @doc:param                   name="tagName" optional="false"
         *      description="The tag name."
         * @doc:param                   name="superclasses" values="true,false"
         *      description="If true then traverse superclasses also, otherwise look up
         *      the tag in current concrete class only."
         * @doc:param                   name="tagKey" description="A tag property that
         *      will be used as a unique key. This is used to avoid duplicate code due
         *      to similar tags in superclasses."
         */
        public void forAllFinders( String template, Properties attributes ) throws 
XDocletException
        {
          boolean superclasses = TypeConversionUtil.stringToBoolean( 
attributes.getProperty( "superclasses" ), false );
          String type = attributes.getProperty( "type" );
          if (type == null)
              throw new XDocletException("Attribute 'type' is mandatory for 
'forAllFinders'");
  
          Set already = new HashSet();
  
          // Exclude definition coming from super classes
          XTag[] superTags = getCurrentClass().superclass().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) )
              {
                  already.add(signature);
              }
          }
  
                XTag[] tags = getCurrentClass().doc().tags( "ejb:finder", superclasses 
);
          for( int i = 0; i < tags.length; i++ )
                {
              String signature = fullPackageChange(tags[i].attributeValue( "signature" 
));
              String typeMapping = tags[i].attributeValue( "result-type-mapping" );
              if (typeMapping == null || typeMapping.equalsIgnoreCase(type) )
              {
                  if ( !already.add(signature) )
                      continue;
  
                  System.out.println("key="+signature);
  
                  setCurrentTag( tags[i] );
                  setCurrentSignature(signature);
  
                  generate( template );
              }
                }
  
                setCurrentTag( null );
          setCurrentSignature(null);
  
  
      }
  
      public String currentSignature() throws XDocletException
        {
          return currentSignature;
      }
  
      protected void setCurrentSignature(String cs)
      {
          this.currentSignature = cs;
      }
  
      private String fullPackageChange(String s)
      {
          StringTokenizer st = new StringTokenizer(s," ");
          String sign = st.nextToken();
          StringBuffer ret = new StringBuffer();
          if (sign.equals("Collection")){
              ret.append("java.util.Collection");
          }
          else if (sign.equals("Enumeration")){
              ret.append("java.util.Enumeration");
          }
          else ret.append(sign);
          while (st.hasMoreTokens())
          {
              ret.append(" ").append(st.nextToken());
          }
          return ret.toString();
      }
  
  }
  
  
  

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

Reply via email to