kinman      2002/08/21 15:05:34

  Modified:    jsr152/src/share/javax/servlet/jsp/tagext TagAdapter.java
  Log:
  - Fixed 11884: getParent in a SimpleTag implementation returns a Tag.
    Submitted by Mark Roth
  
  Revision  Changes    Path
  1.3       +21 -5     
jakarta-servletapi-5/jsr152/src/share/javax/servlet/jsp/tagext/TagAdapter.java
  
  Index: TagAdapter.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-servletapi-5/jsr152/src/share/javax/servlet/jsp/tagext/TagAdapter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TagAdapter.java   19 Aug 2002 16:29:51 -0000      1.2
  +++ TagAdapter.java   21 Aug 2002 22:05:34 -0000      1.3
  @@ -77,15 +77,22 @@
   {
       /** The simple tag that's being adapted */
       private SimpleTag simpleTagAdaptee;
  +
  +    /** The parent, of this tag, converted (if necessary) to be of type Tag */
  +    private Tag cachedParent;
       
       /**
  -     * Creates a new TagAdapter that wraps the given SimeplTag and 
  +     * Creates a new TagAdapter that wraps the given SimpleTag and 
        * returns the parent tag when getParent() is called.
        *
        * @param adaptee The SimpleTag being adapted as a Tag.
        */
       public TagAdapter( SimpleTag adaptee ) {
  -        this.simpleTagAdaptee = simpleTagAdaptee;
  +        if( adaptee == null ) {
  +         // Cannot wrap a null adaptee.
  +         throw new IllegalArgumentException();
  +        }
  +        this.simpleTagAdaptee = adaptee;
       }
       
       /**
  @@ -122,9 +129,18 @@
        * @return The parent of the tag being adapted.
        */
       public Tag getParent() {
  -     // Note the parent tag must be an instance of Tag (either a 
  -     // direct instance or a wrapped instance).
  -     return (Tag)simpleTagAdaptee.getParent();
  +     if( this.cachedParent == null ) {
  +         JspTag parent = simpleTagAdaptee.getParent();
  +         if( parent instanceof Tag ) {
  +             this.cachedParent = (Tag)parent;
  +         }
  +         else {
  +                // Must be SimpleTag - no other types defined.
  +             this.cachedParent = new TagAdapter( (SimpleTag)parent );
  +         }
  +     }
  +
  +     return this.cachedParent;
       }
       
       /**
  
  
  

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

Reply via email to