commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant AntTag.java
Date Mon, 19 Aug 2002 21:41:53 GMT
jstrachan    2002/08/19 14:41:53

  Modified:    jelly/src/java/org/apache/commons/jelly/tags/ant AntTag.java
  Log:
  Added support for Ant style adder and setter methods that can be used either on a Jelly
Tag implementation or on a regular Java Bean that is bound to a dynamic tag via either <define:bean>
or <define:jellybean>
  
  So you can write a tag or bean like this
  
  public MyTag extends TagSupport {
      public void setFileset(FileSet fileSet);
  
      // or
  
      public void addFileset(FileSet fileSet);
  }
  
  which can then take nested (say) <fileset> Ant properties etc.
  
  To see this in action, try the demo:jellybean Maven target which demonstrates the use of
this technique.
  
  Revision  Changes    Path
  1.7       +22 -2     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/AntTag.java
  
  Index: AntTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/AntTag.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- AntTag.java	19 Aug 2002 20:36:23 -0000	1.6
  +++ AntTag.java	19 Aug 2002 21:41:53 -0000	1.7
  @@ -76,6 +76,7 @@
   import org.apache.commons.jelly.MapTagSupport;
   import org.apache.commons.jelly.Tag;
   import org.apache.commons.jelly.XMLOutput;
  +import org.apache.commons.jelly.impl.BeanSource;
   import org.apache.commons.jelly.impl.StaticTag;
   
   import org.apache.commons.logging.Log;
  @@ -209,7 +210,11 @@
               if ( log.isDebugEnabled() ) {                            
                   log.debug( "Creating a nested object name: " + tagName );            
               }
  -            
  +
  +            if ( parentObject == null ) {
  +                parentObject = findBeanAncestor();
  +            }
  +                        
               Object nested = createNestedObject( parentObject, tagName );
               
               if ( nested == null ) {
  @@ -332,7 +337,7 @@
                   return;
               }
               catch (Exception e) {
  -                log.error( "Caught: " + e, e );
  +                // ignore: not a valid property
               }
           }
   
  @@ -441,5 +446,20 @@
           task.setTaskName(taskName);
   
           return task;
  +    }
  +    
  +    /**
  +     * Attempts to look up in the parent hierarchy for a tag that implements the BeanSource
interface
  +     * which creates a dynamic bean, or will return the parent tag, which is also a bean.
  +     */
  +    protected Object findBeanAncestor() throws Exception {
  +        Tag tag = getParent();
  +        if (tag != null) {
  +            if (tag instanceof BeanSource) {
  +                BeanSource beanSource = (BeanSource) tag;
  +                return beanSource.getBean();
  +            }
  +        }
  +        return tag;
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message