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/swing SwingTagLibrary.java
Date Thu, 01 Aug 2002 09:53:19 GMT
jstrachan    2002/08/01 02:53:19

  Modified:    jelly/src/java/org/apache/commons/jelly/impl
                        BeanTagScript.java StaticTagScript.java
                        DynaTagScript.java TagScript.java
               jelly/src/java/org/apache/commons/jelly/parser
                        XMLParser.java
               jelly/src/java/org/apache/commons/jelly/tags/ant
                        AntTagLibrary.java FileScannerTag.java
                        FileScanner.java
               jelly/src/java/org/apache/commons/jelly/tags/define
                        DynamicTagLibrary.java DefineBeanTag.java
               jelly/src/java/org/apache/commons/jelly/tags/core
                        IncludeTag.java
               jelly/src/test/org/apache/commons/jelly/jeez example.jelly
               jelly/src/java/org/apache/commons/jelly/tags/jeez
                        TagDefTag.java JeezTagLibrary.java
               jelly    maven.xml project.xml
               jelly/src/java/org/apache/commons/jelly jelly.properties
                        TagLibrary.java
               jelly/src/java/org/apache/commons/jelly/tags/swing
                        SwingTagLibrary.java
  Added:       jelly/src/java/org/apache/commons/jelly/impl TagFactory.java
                        DefaultTagFactory.java
               jelly/src/test/org/apache/commons/jelly/jeez
                        filescanner.jelly
  Log:
  Patched the Script implementation mechanism for 2 reasons
  
  (i) to try make a single Script instance cacheable and multi-threaded so that in server side deployments, the scripts can be cached and reused across multiple threads to boost performance and lower RAM usage
  
  (ii) to introduce the TagFactory so that a tag can be bound to a Tag instance at runtime, rather than just at parse time.
  This makes many things much simpler, particularly in the area of dynamic tags.
  
  For example the Jeez library unifies the define tag library with the ant tag library, both of which can create dynamic tags, at run time.
  Until this change was done, it was not possible to return a single efficient Tag implementation at parse time. So now at parse time a TagLibrary can create a TagFactory which at runtime decides which Tag instance to use.
  This chance helps the multi-threaded nature also, so that different threads can create their own tag implemention.
  
  
  Right now the current policy is for a Script object to be reusable across threads (which needs testing), then each thread will create & cache 1 Java object per tag on the page. Each Tag is cached in ThreadLocal storage. If a Script goes out of scope then all this should be GC'd.
  So we've a neat, simple,  multi-threaded, pooled solution that should cause minimum object allocation yet allow flexible bean style coding and not require byte code generation (and all the classloading / GC issues that entails).
  
  Also for the Maven users, the <tagdef> is now working and can be used inside Maven now, which simplifies things greatly - no need to create a new tag library & new tag, just use <tagdef> and add a new tag dynamically to the maven (Jeez) tag library.
  
  Revision  Changes    Path
  1.13      +90 -70    jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/BeanTagScript.java
  
  Index: BeanTagScript.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/BeanTagScript.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- BeanTagScript.java	28 Jun 2002 12:13:27 -0000	1.12
  +++ BeanTagScript.java	1 Aug 2002 09:53:17 -0000	1.13
  @@ -99,6 +99,12 @@
       /** The Log to which logging calls will be made. */
       private static final Log log = LogFactory.getLog(BeanTagScript.class);
   
  +
  +// this state must be shared & thread safe...
  +
  +    /** The cached Tag Class information */
  +    private Class tagClass;
  +    
       /** Expressions for each attribute */
       private Expression[] expressions = {
       };
  @@ -114,24 +120,94 @@
       public BeanTagScript() {
       }
   
  -    public BeanTagScript(Tag tag) {
  -        super(tag);
  +    public BeanTagScript(TagFactory tagFactory) {
  +        super(tagFactory);
       }
   
       // Script interface
       //-------------------------------------------------------------------------                
   
  -    /** Compiles the script to a more efficient form. 
  -      * Will only be called once by the parser 
  -      */
  -    public Script compile() throws Exception {
  -        if (tag instanceof CompilableTag) {
  -            ((CompilableTag) tag).compile();
  +    /** Evaluates the body of a tag */
  +    public void run(JellyContext context, XMLOutput output) throws Exception {
  +        Tag tag = getTag();
  +        if ( tag == null ) {
  +            return;
  +        }
  +        tag.setContext(context);
  +        
  +        // initialize all the properties of the tag before its used
  +        // if there is a problem abort this tag
  +        for (int i = 0, size = expressions.length; i < size; i++) {
  +            Expression expression = expressions[i];
  +            Method method = methods[i];
  +            Class type = types[i];
  +            
  +            // some types are Expression objects so let the tag
  +            // evaluate them
  +            Object value = null;
  +            if (type.isAssignableFrom(Expression.class) && !type.isAssignableFrom(Object.class)) {
  +                value = expression;
  +            }
  +            else {
  +                value = expression.evaluate(context);
  +            }
  +            // convert value to correct type
  +            if (value != null) {
  +                value = convertType(value, type);
  +            }            
  +            Object[] arguments = { value };
  +            try {
  +                method.invoke(tag, arguments);
  +            }
  +            catch (Exception e) {
  +                String valueTypeName = (value != null ) ? value.getClass().getName() : "null";
  +                log.warn( 
  +                    "Cannot call method: " + method.getName() + " as I cannot convert: " 
  +                    + value + " of type: " + valueTypeName + " into type: " + type.getName() 
  +                );
  +                throw createJellyException( 
  +                    "Cannot call method: " + method.getName() + " on tag of type: " 
  +                    + tag.getClass().getName() + " with value: " + value + " of type: " 
  +                    + valueTypeName + ". Exception: " + e, e
  +                );
  +            }
  +        }
  +        
  +        try {
  +            tag.doTag(output);
  +        } 
  +        catch (JellyException e) {
  +            handleException(e);
  +        }
  +        catch (Exception e) {
  +            handleException(e);
  +        }
  +    }
  +    
  +    
  +    // Implementation methods
  +    //-------------------------------------------------------------------------                
  +
  +    /**
  +     * Compiles a newly created tag if required, sets its parent and body.
  +     */
  +    protected void configureTag(Tag tag) throws Exception {
  +        super.configureTag(tag);
  +        Class aClass = tag.getClass();
  +        if ( tagClass == null || ! tagClass.equals( aClass ) ) {
  +            tagClass = aClass;
  +            compileClass();
           }
  +    }
  +    
  +    
  +    /** Compiles the given tag class caching the property descriptors etc.
  +      */
  +    protected void compileClass() throws Exception {
           List typeList = new ArrayList();
           List methodList = new ArrayList();
           List expressionList = new ArrayList();
  -        BeanInfo info = Introspector.getBeanInfo(tag.getClass());
  +        BeanInfo info = Introspector.getBeanInfo(tagClass);
           PropertyDescriptor[] descriptors = info.getPropertyDescriptors();
           Set attributeSet = new HashSet();
           if (descriptors != null) {
  @@ -173,9 +249,6 @@
           methodList.toArray(methods);
           typeList.toArray(types);
           
  -        // compile body
  -        tag.setBody(tag.getBody().compile());
  -        
           // now lets check for any attributes that are not used
           for ( Iterator iter = attributes.keySet().iterator(); iter.hasNext(); ) {
               String name = (String) iter.next();
  @@ -185,59 +258,6 @@
                   );
               }
           }
  -        return this;
       }
       
  -    /** Evaluates the body of a tag */
  -    public void run(JellyContext context, XMLOutput output) throws Exception {
  -        tag.setContext(context);
  -        
  -        // initialize all the properties of the tag before its used
  -        // if there is a problem abort this tag
  -        for (int i = 0, size = expressions.length; i < size; i++) {
  -            Expression expression = expressions[i];
  -            Method method = methods[i];
  -            Class type = types[i];
  -            
  -            // some types are Expression objects so let the tag
  -            // evaluate them
  -            Object value = null;
  -            if (type.isAssignableFrom(Expression.class) && !type.isAssignableFrom(Object.class)) {
  -                value = expression;
  -            }
  -            else {
  -                value = expression.evaluate(context);
  -            }
  -            // convert value to correct type
  -            if (value != null) {
  -                value = convertType(value, type);
  -            }            
  -            Object[] arguments = { value };
  -            try {
  -                method.invoke(tag, arguments);
  -            }
  -            catch (Exception e) {
  -                String valueTypeName = (value != null ) ? value.getClass().getName() : "null";
  -                log.warn( 
  -                    "Cannot call method: " + method.getName() + " as I cannot convert: " 
  -                    + value + " of type: " + valueTypeName + " into type: " + type.getName() 
  -                );
  -                throw createJellyException( 
  -                    "Cannot call method: " + method.getName() + " on tag of type: " 
  -                    + tag.getClass().getName() + " with value: " + value + " of type: " 
  -                    + valueTypeName + ". Exception: " + e, e
  -                );
  -            }
  -        }
  -        
  -        try {
  -            tag.doTag(output);
  -        } 
  -        catch (JellyException e) {
  -            handleException(e);
  -        }
  -        catch (Exception e) {
  -            handleException(e);
  -        }
  -    }
   }
  
  
  
  1.4       +7 -3      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/StaticTagScript.java
  
  Index: StaticTagScript.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/StaticTagScript.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StaticTagScript.java	15 Jul 2002 11:22:27 -0000	1.3
  +++ StaticTagScript.java	1 Aug 2002 09:53:17 -0000	1.4
  @@ -98,8 +98,8 @@
       public StaticTagScript() {
       }
   
  -    public StaticTagScript(StaticTag tag) {
  -        super(tag);
  +    public StaticTagScript(TagFactory tagFactory) {
  +        super(tagFactory);
       }
       
   
  @@ -109,7 +109,8 @@
       public void run(JellyContext context, XMLOutput output) throws Exception {
   
           startNamespacePrefixes(output);
  -                
  +            
  +        Tag tag = getTag();                
           if ( firstRun ) {
               firstRun = false;
               
  @@ -117,6 +118,9 @@
               tag = findDynamicTag(context, (StaticTag) tag);
           }
           try {        
  +            if ( tag == null ) {
  +                return;
  +            }
               tag.setContext(context);
               
               DynaTag dynaTag = (DynaTag) tag;
  
  
  
  1.10      +38 -28    jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/DynaTagScript.java
  
  Index: DynaTagScript.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/DynaTagScript.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- DynaTagScript.java	27 Jun 2002 14:09:15 -0000	1.9
  +++ DynaTagScript.java	1 Aug 2002 09:53:17 -0000	1.10
  @@ -64,6 +64,9 @@
   import java.util.Iterator;
   import java.util.Map;
   
  +import org.apache.commons.beanutils.ConvertingWrapDynaBean;
  +import org.apache.commons.beanutils.DynaBean;
  +
   import org.apache.commons.jelly.CompilableTag;
   import org.apache.commons.jelly.JellyContext;
   import org.apache.commons.jelly.JellyException;
  @@ -90,39 +93,46 @@
       public DynaTagScript() {
       }
   
  -    public DynaTagScript(DynaTag tag) {
  -        super(tag);
  +    public DynaTagScript(TagFactory tagFactory) {
  +        super(tagFactory);
       }
   
       // Script interface
       //-------------------------------------------------------------------------                
  -    /** Compiles the script to a more efficient form. 
  -      * Will only be called once by the parser 
  -      */
  -    public Script compile() throws Exception {
  -        if (tag instanceof CompilableTag) {
  -            ((CompilableTag) tag).compile();
  -        }
  -        // compile body
  -        tag.setBody(tag.getBody().compile());
  -        return this;
  -    }
   
       /** Evaluates the body of a tag */
       public void run(JellyContext context, XMLOutput output) throws Exception {
           try {
  +            Tag tag = getTag();
  +            if ( tag == null ) {
  +                return;
  +            }
               tag.setContext(context);
  -            
  -            DynaTag dynaTag = (DynaTag) tag;
  -    
  -            // ### probably compiling this to 2 arrays might be quicker and smaller
  -            for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) {
  -                Map.Entry entry = (Map.Entry) iter.next();
  -                String name = (String) entry.getKey();
  -                Expression expression = (Expression) entry.getValue();
       
  -                Object value = expression.evaluate(context);
  -                dynaTag.setAttribute(name, value);
  +            if ( tag instanceof DynaTag ) {        
  +                DynaTag dynaTag = (DynaTag) tag;
  +        
  +                // ### probably compiling this to 2 arrays might be quicker and smaller
  +                for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) {
  +                    Map.Entry entry = (Map.Entry) iter.next();
  +                    String name = (String) entry.getKey();
  +                    Expression expression = (Expression) entry.getValue();
  +        
  +                    Object value = expression.evaluate(context);
  +                    dynaTag.setAttribute(name, value);
  +                }
  +            }
  +            else {
  +                // treat the tag as a bean
  +                DynaBean dynaBean = new ConvertingWrapDynaBean( tag );
  +                for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) {
  +                    Map.Entry entry = (Map.Entry) iter.next();
  +                    String name = (String) entry.getKey();
  +                    Expression expression = (Expression) entry.getValue();
  +        
  +                    Object value = expression.evaluate(context);
  +                    dynaBean.set(name, value);
  +                }
               }
           
               tag.doTag(output);
  
  
  
  1.17      +140 -30   jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/TagScript.java
  
  Index: TagScript.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/TagScript.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- TagScript.java	15 Jul 2002 16:18:15 -0000	1.16
  +++ TagScript.java	1 Aug 2002 09:53:17 -0000	1.17
  @@ -68,7 +68,7 @@
   import java.lang.reflect.InvocationTargetException;
   import java.io.Writer;
   import java.util.ArrayList;
  -import java.util.HashMap;
  +import java.util.Hashtable;
   import java.util.Iterator;
   import java.util.List;
   import java.util.Map;
  @@ -93,6 +93,9 @@
   /** 
    * <p><code>TagScript</code> abstract base class for a 
    * script that evaluates a custom tag.</p>
  + * 
  + * <b>Note</b> that this class should be re-entrant and used
  + * concurrently by multiple threads.
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision$
  @@ -102,11 +105,11 @@
       /** The Log to which logging calls will be made. */
       private static final Log log = LogFactory.getLog(TagScript.class);
   
  -    /** the tag to be evaluated */
  -    protected Tag tag;
  +    /** thread local storage for the tag used by the current thread */
  +    private ThreadLocal tagHolder = new ThreadLocal();
   
       /** The attribute expressions that are created */
  -    protected Map attributes = new HashMap();
  +    protected Map attributes = new Hashtable();
       
       /** the optional namespaces Map of prefix -> URI */
       private Map namespacesMap;
  @@ -123,21 +126,57 @@
       /** the column number of the tag */
       private int columnNumber = -1;
   
  +    /** the factory of Tag instances */
  +    private TagFactory tagFactory;
  +    
  +    /** the body script used for this tag */
  +    private Script tagBody;
  +    
  +    /** the parent TagScript */
  +    private TagScript parent;
  +    
  +    /** 
  +     * @return a new TagScript based on whether 
  +     * the given Tag class is a bean tag or DynaTag 
  +     */
  +    public static TagScript newInstance(Class tagClass) {
  +        TagFactory factory = new DefaultTagFactory(tagClass);
  +        
  +        if ( DynaTag.class.isAssignableFrom(tagClass) ) {
  +            return new DynaTagScript(factory);
  +        }
  +        return new BeanTagScript(factory);
  +    }
  +    
       public TagScript() {
       }
   
  -    public TagScript(Tag tag) {
  -        this.tag = tag;
  +    public TagScript(TagFactory tagFactory) {
  +        this.tagFactory = tagFactory;
       }
       
       public String toString() {
  -        return super.toString() + "[tag=" + tag + "]";
  +        return super.toString() + "[tag=" + elementName + ";at=" + lineNumber + ":" + columnNumber + "]";
       }
   
       /**
  +     * Compiles the tags body
  +     */
  +    public Script compile() throws Exception {
  +        if (tagBody != null) {
  +            tagBody = tagBody.compile();
  +        }
  +        return this;
  +    }
  +    
  +    /**
        * Sets the optional namespaces prefix -> URI map
        */
       public void setNamespacesMap(Map namespacesMap) {
  +        // lets check that this is a thread-safe map
  +        if ( ! (namespacesMap instanceof Hashtable) ) {
  +            namespacesMap = new Hashtable( namespacesMap );
  +        }
           this.namespacesMap = namespacesMap;
       }
           
  @@ -151,17 +190,6 @@
       }
   
       
  -    /** 
  -     * @return a new TagScript based on whether 
  -     * the tag is a bean tag or DynaTag 
  -     */
  -    public static TagScript newInstance(Tag tag) {
  -        if (tag instanceof DynaTag) {
  -            return new DynaTagScript((DynaTag) tag);
  -        }
  -        return new BeanTagScript(tag);
  -    }
  -    
       /** Add an initialization attribute for the tag.
        * This method must be called after the setTag() method 
        */
  @@ -174,16 +202,70 @@
       
       // Properties
       //-------------------------------------------------------------------------                
  -    /** @return the tag to be evaluated */
  -    public Tag getTag() {
  +
  +    /** 
  +     * @return the tag to be evaluated, creating it lazily if required.
  +     */
  +    public Tag getTag() throws Exception {
  +        Tag tag = (Tag) tagHolder.get();
  +        if ( tag == null ) {
  +            tag = createTag();
  +            if ( tag != null ) {
  +                configureTag(tag);
  +                tagHolder.set(tag);
  +            }
  +        }
           return tag;
       }
  -    
  -    /** Sets the tag to be evaluated */
  -    public void setTag(Tag tag) {
  -        this.tag = tag;
  +
  +    /**
  +     * Returns the Factory of Tag instances.
  +     * @return the factory
  +     */
  +    public TagFactory getTagFactory() {
  +        return tagFactory;
       }
  -    
  +
  +    /**
  +     * Sets the Factory of Tag instances.
  +     * @param tagFactory The factory to set
  +     */
  +    public void setTagFactory(TagFactory tagFactory) {
  +        this.tagFactory = tagFactory;
  +    }
  +
  +    /**
  +     * Returns the parent.
  +     * @return TagScript
  +     */
  +    public TagScript getParent() {
  +        return parent;
  +    }
  +
  +    /**
  +     * Returns the tagBody.
  +     * @return Script
  +     */
  +    public Script getTagBody() {
  +        return tagBody;
  +    }
  +
  +    /**
  +     * Sets the parent.
  +     * @param parent The parent to set
  +     */
  +    public void setParent(TagScript parent) {
  +        this.parent = parent;
  +    }
  +
  +    /**
  +     * Sets the tagBody.
  +     * @param tagBody The tagBody to set
  +     */
  +    public void setTagBody(Script tagBody) {
  +        this.tagBody = tagBody;
  +    }
  +
       /** 
        * @return the Jelly file which caused the problem 
        */
  @@ -244,6 +326,33 @@
       //-------------------------------------------------------------------------      
   
       /**
  +     * Factory method to create a new Tag instance. 
  +     * The default implementation is to delegate to the TagFactory
  +     */
  +    protected Tag createTag() throws Exception {    
  +        if ( tagFactory != null) {
  +            return tagFactory.createTag();
  +        }
  +        return null;
  +    }
  +
  +
  +    /**
  +     * Compiles a newly created tag if required, sets its parent and body.
  +     */
  +    protected void configureTag(Tag tag) throws Exception {
  +        if (tag instanceof CompilableTag) {
  +            ((CompilableTag) tag).compile();
  +        }
  +        Tag parentTag = null;
  +        if ( parent != null ) {
  +            parentTag = parent.getTag();
  +        }
  +        tag.setParent( parentTag );
  +        tag.setBody( tagBody );
  +    }
  +                
  +    /**
        * Output the new namespace prefixes used for this element
        */    
       protected void startNamespacePrefixes(XMLOutput output) throws SAXException {
  @@ -364,4 +473,5 @@
           }
           throw e;
       }
  +    
   }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/TagFactory.java
  
  Index: TagFactory.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/TagScript.java,v 1.16 2002/07/15 16:18:15 werken Exp $
   * $Revision: 1.16 $
   * $Date: 2002/07/15 16:18:15 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * $Id: TagScript.java,v 1.16 2002/07/15 16:18:15 werken Exp $
   */
  package org.apache.commons.jelly.impl;
  
  
  import org.apache.commons.jelly.Tag;
  
  /** 
   * <p><code>TagFactory</code> represents a Factory of {@link Tag} instances.</p>
   * 
   * <b>Note</b> that this class should be re-entrant and used
   * concurrently by multiple threads.
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.16 $
   */
  public interface TagFactory {
  
      public Tag createTag() throws Exception;
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/DefaultTagFactory.java
  
  Index: DefaultTagFactory.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/TagScript.java,v 1.16 2002/07/15 16:18:15 werken Exp $
   * $Revision: 1.16 $
   * $Date: 2002/07/15 16:18:15 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * $Id: TagScript.java,v 1.16 2002/07/15 16:18:15 werken Exp $
   */
  package org.apache.commons.jelly.impl;
  
  import org.apache.commons.jelly.Tag;
  
  /** 
   * <p><code>DefaultTagFactory</code> a default implementation of TagFactory
   * which creates new instances of a given class.
   * 
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.16 $
   */
  public class DefaultTagFactory implements TagFactory {
  
      private Class tagClass;
          
      public DefaultTagFactory() {
      }
  
      public DefaultTagFactory(Class tagClass) {
          this.tagClass = tagClass;
      }
  
      // TagFactory interface
      //-------------------------------------------------------------------------      
      
      public Tag createTag() throws Exception {
          return (Tag) tagClass.newInstance();
      }
  
      
      // Properties
      //-------------------------------------------------------------------------      
      
      /**
       * Returns the tagClass.
       * @return Class
       */
      public Class getTagClass() {
          return tagClass;
      }
  
      /**
       * Sets the tagClass.
       * @param tagClass The tagClass to set
       */
      public void setTagClass(Class tagClass) {
          this.tagClass = tagClass;
      }
  
  }
  
  
  
  1.27      +29 -35    jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java
  
  Index: XMLParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- XMLParser.java	15 Jul 2002 11:22:27 -0000	1.26
  +++ XMLParser.java	1 Aug 2002 09:53:18 -0000	1.27
  @@ -92,6 +92,7 @@
   import org.apache.commons.jelly.impl.DynaTagScript;
   import org.apache.commons.jelly.impl.ScriptBlock;
   import org.apache.commons.jelly.impl.StaticTagScript;
  +import org.apache.commons.jelly.impl.TagFactory;
   import org.apache.commons.jelly.impl.TagScript;
   import org.apache.commons.jelly.impl.TextScript;
   import org.apache.commons.jelly.expression.CompositeExpression;
  @@ -134,12 +135,9 @@
       /** The current script block */
       private ScriptBlock script;
   
  -    /** The current tagScript */
  +    /** The current, parent tagScript */
       private TagScript tagScript;
   
  -    /** The current parent tag */
  -    private Tag parentTag;
  -    
       /** The stack of body scripts. */
       private ArrayStack scriptStack = new ArrayStack();
   
  @@ -222,10 +220,6 @@
       private Log log = LogFactory.getLog(XMLParser.class);
   
   
  -    /** 
  -     * A stack of tags used to assign the parent tag
  -     */
  -    private List tagStack = new ArrayList();
       
       /**
        * Construct a new XMLParser with default properties.
  @@ -551,7 +545,6 @@
           script = new ScriptBlock();
           textBuffer = new StringBuffer();
           tagScript = null;
  -        parentTag = null;
           scriptStack.clear();
           tagScriptStack.clear();
       }
  @@ -593,6 +586,7 @@
               
               // if this is a tag then create a script to run it
               // otherwise pass the text to the current body
  +            TagScript parentTagScript = tagScript;
               tagScript = createTag(namespaceURI, localName, list);
               if (tagScript == null) {
                   tagScript = createStaticTag(namespaceURI, localName, qName, list);
  @@ -600,8 +594,7 @@
               tagScriptStack.add(tagScript);
               if (tagScript != null) {
                   // set parent relationship...
  -                Tag tag = tagScript.getTag();
  -                tag.setParent(parentTag);
  +                tagScript.setParent(parentTagScript);
   
                   // set the namespace Map
                   if ( elementNamespaces != null ) {
  @@ -617,12 +610,6 @@
                   tagScript.setFileName(fileName);
                   tagScript.setElementName(qName);
                   
  -                // pop another tag onto the stack
  -                if ( parentTag != null ) {
  -                    tagStack.add( parentTag );                
  -                }
  -                parentTag = tag;                
  -                
                   if (textBuffer.length() > 0) {
                       addTextScript(textBuffer.toString());
                       textBuffer.setLength(0);
  @@ -631,7 +618,7 @@
                   // start a new body
                   scriptStack.push(script);
                   script = new ScriptBlock();
  -                tag.setBody(script);
  +                tagScript.setTagBody(script);
               }
               else {
                   // XXXX: might wanna handle empty elements later...
  @@ -701,13 +688,14 @@
   	            textBuffer.append(qName);
   	            textBuffer.append(">");
   	        }
  -	        int size = tagStack.size();
  -	        if ( size <= 0 ) {
  -	            parentTag = null;
  -	        }
  -	        else {
  -	            parentTag = (Tag) tagStack.remove( size - 1 );
  -	        }
  +            
  +            // now lets set the parent tag variable
  +            if ( tagScriptStack.isEmpty() ) {
  +                tagScript = null;
  +            }
  +            else {
  +                tagScript = (TagScript) tagScriptStack.get(tagScriptStack.size() - 1);
  +            }
           }
           catch (SAXException e) {
               throw e;
  @@ -1030,14 +1018,20 @@
        * Factory method to create a static Tag that represents some static content.
        */
       protected TagScript createStaticTag(
  -        String namespaceURI,
  -        String localName,
  -        String qName,
  +        final String namespaceURI,
  +        final String localName,
  +        final String qName,
           Attributes list)
           throws SAXException {
           try {
  -            StaticTag tag = new StaticTag( namespaceURI, localName, qName);
  -            StaticTagScript script = new StaticTagScript(tag);
  +            StaticTag tag = new StaticTag( namespaceURI, localName, qName );
  +            StaticTagScript script = new StaticTagScript(
  +                new TagFactory() {
  +                    public Tag createTag() {
  +                        return new StaticTag( namespaceURI, localName, qName );   
  +                    }
  +                }
  +            );
   
               // now iterate through through the expressions
               int size = list.getLength();
  
  
  
  1.18      +37 -14    jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/AntTagLibrary.java
  
  Index: AntTagLibrary.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/AntTagLibrary.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- AntTagLibrary.java	28 Jun 2002 11:05:06 -0000	1.17
  +++ AntTagLibrary.java	1 Aug 2002 09:53:18 -0000	1.18
  @@ -73,6 +73,9 @@
   import org.apache.commons.jelly.Script;
   import org.apache.commons.jelly.Tag;
   import org.apache.commons.jelly.TagLibrary;
  +import org.apache.commons.jelly.impl.BeanTagScript;
  +import org.apache.commons.jelly.impl.DynaTagScript;
  +import org.apache.commons.jelly.impl.TagFactory;
   import org.apache.commons.jelly.impl.TagScript;
   
   import org.apache.commons.logging.Log;
  @@ -210,29 +213,49 @@
   
   
       /** Creates a new script to execute the given tag name and attributes */
  -    public TagScript createTagScript(String name, Attributes attributes) throws Exception {
  +    public TagScript createTagScript(final String name, Attributes attributes) throws Exception {
   
  -        Project project = getProject();
  -        
  +        TagScript answer = createCustomTagScript(name, attributes);
  +        if ( answer == null ) {
  +            answer = new DynaTagScript(
  +                new TagFactory() {
  +                    public Tag createTag() throws Exception {
  +                        return AntTagLibrary.this.createTag(name);
  +                    }
  +                }
  +            );
  +        }
  +        return answer;
  +    }
  +
  +    /** 
  +     * @return a new TagScript for any custom, statically defined tags, like 'fileScanner'
  +     */
  +    public TagScript createCustomTagScript(final String name, Attributes attributes) throws Exception {
           // custom Ant tags
  -        if ( name.equals("fileScanner") ) {            
  -            Tag tag = new FileScannerTag(new FileScanner(project));
  -            return TagScript.newInstance(tag);
  +        if ( name.equals("fileScanner") ) {      
  +            return new BeanTagScript(
  +                new TagFactory() {
  +                    public Tag createTag() throws Exception {
  +                        return new FileScannerTag(new FileScanner(getProject()));
  +                    }
  +                }
  +            );      
           }
  +        return null;
  +    }
   
  +    /**
  +     * A helper method which creates an AntTag instance for the given element name
  +     */
  +    public Tag createTag(String name) throws Exception {
           AntTag tag = new AntTag( getProject(), name );
           if ( name.equals( "echo" ) ) {
               tag.setTrim(false);
           }
  -        return TagScript.newInstance(tag);
  -    }
  -
  -    public TagScript createRuntimeTaskTagScript(String taskName, Attributes attributes) throws Exception {
  -        //TaskTag tag = new TaskTag( project, taskName );
  -        AntTag tag = new AntTag( project, taskName );
  -        return TagScript.newInstance( tag );
  +        return tag;
       }
  -                                                
  +    
   
       
       // Properties
  
  
  
  1.4       +3 -0      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/FileScannerTag.java
  
  Index: FileScannerTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/FileScannerTag.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FileScannerTag.java	28 Jun 2002 11:05:06 -0000	1.3
  +++ FileScannerTag.java	1 Aug 2002 09:53:18 -0000	1.4
  @@ -91,6 +91,8 @@
       // Tag interface
       //------------------------------------------------------------------------- 
       public void doTag(XMLOutput output) throws Exception {
  +        fileScanner.clear();
  +        
           // run the body first to configure the task via nested
           invokeBody(output);
   
  @@ -99,6 +101,7 @@
               throw new MissingAttributeException( "var" );
           }
           context.setVariable( var, fileScanner );        
  +        
       }
       
       // TaskSource interface
  
  
  
  1.4       +7 -0      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/FileScanner.java
  
  Index: FileScanner.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/FileScanner.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FileScanner.java	10 Jul 2002 18:53:50 -0000	1.3
  +++ FileScanner.java	1 Aug 2002 09:53:18 -0000	1.4
  @@ -95,6 +95,13 @@
           return filesets.size() > 0;
       }        
   
  +    /**
  +     * Clears any file sets that have been added to this scanner
  +     */
  +    public void clear() {
  +        filesets.clear();
  +    }
  +    
       // Properties
       //-------------------------------------------------------------------------
   
  
  
  
  1.6       +19 -24    jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DynamicTagLibrary.java
  
  Index: DynamicTagLibrary.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DynamicTagLibrary.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DynamicTagLibrary.java	25 Jun 2002 19:12:28 -0000	1.5
  +++ DynamicTagLibrary.java	1 Aug 2002 09:53:18 -0000	1.6
  @@ -69,6 +69,7 @@
   import org.apache.commons.jelly.Tag;
   import org.apache.commons.jelly.TagLibrary;
   import org.apache.commons.jelly.impl.DynaTagScript;
  +import org.apache.commons.jelly.impl.TagFactory;
   import org.apache.commons.jelly.impl.TagScript;
   
   import org.xml.sax.Attributes;
  @@ -93,23 +94,16 @@
       }
   
       /** Creates a new script to execute the given tag name and attributes */
  -    public TagScript createTagScript(String name, Attributes attributes)
  +    public TagScript createTagScript(final String name, Attributes attributes)
           throws Exception {
   
  -        Object value = templates.get(name);
  -        if ( value instanceof Script ) {            
  -            Script template = (Script) value;
  -            DynamicTag tag = new DynamicTag(template);
  -
  -            // XXXX: somehow we should find the template's 
  -            // <invokeBody> tag and associate it with this instance
  -            return new DynaTagScript(tag);
  -        }
  -        else if ( value instanceof DynaTag ) {
  -            DynaTag tag = (DynaTag) value;
  -            return new DynaTagScript(tag);
  -        }
  -        return null;
  +        return new DynaTagScript(
  +            new TagFactory() {
  +                public Tag createTag() throws Exception {
  +                    return DynamicTagLibrary.this.createTag(name);
  +                }
  +            }
  +        );
       }
   
       /** Creates a new Tag for the given tag name if it exists */
  @@ -121,8 +115,9 @@
               Script template = (Script) value;
               return new DynamicTag(template);
           }
  -        else if ( value instanceof DynaTag ) {
  -            return (DynaTag) value;
  +        else if ( value instanceof TagFactory ) {
  +            TagFactory factory = (TagFactory) value;
  +            return factory.createTag();
           }
           return null;
       }
  @@ -137,8 +132,8 @@
       /**
        * Creates a new Jelly Bean Tag with the given name 
        */
  -    public void registerBeanTag(String name, BeanTag tag) {
  -        templates.put(name, tag);
  +    public void registerBeanTag(String name, TagFactory factory) {
  +        templates.put(name, factory);
       }
   
       // Properties
  
  
  
  1.2       +12 -4     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DefineBeanTag.java
  
  Index: DefineBeanTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DefineBeanTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefineBeanTag.java	17 Jul 2002 17:37:58 -0000	1.1
  +++ DefineBeanTag.java	1 Aug 2002 09:53:18 -0000	1.2
  @@ -68,7 +68,9 @@
   
   import org.apache.commons.jelly.JellyException;
   import org.apache.commons.jelly.MissingAttributeException;
  +import org.apache.commons.jelly.Tag;
   import org.apache.commons.jelly.XMLOutput;
  +import org.apache.commons.jelly.impl.TagFactory;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -150,14 +152,20 @@
   			}
   		}
           
  -        Method invokeMethod = getInvokeMethod( theClass );
  -
           if ( attributes == null ) {
               attributes = EMPTY_MAP;        
           }
           
  -        BeanTag tag = new BeanTag(theClass, attributes, varAttribute, invokeMethod);
  -        getTagLibrary().registerBeanTag(name, tag);
  +        final Class beanClass = theClass;
  +        final Method invokeMethod = getInvokeMethod( theClass );
  +        final Map beanAttributes = attributes;
  +        
  +        TagFactory factory = new TagFactory() {
  +            public Tag createTag() {
  +                return  new BeanTag(beanClass, beanAttributes, varAttribute, invokeMethod);
  +            }
  +        };
  +        getTagLibrary().registerBeanTag(name, factory);
           
           // now lets clear the attributes for next invocation and help the GC
           attributes = null;
  
  
  
  1.7       +5 -9      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/IncludeTag.java
  
  Index: IncludeTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/IncludeTag.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- IncludeTag.java	13 Jun 2002 21:31:14 -0000	1.6
  +++ IncludeTag.java	1 Aug 2002 09:53:18 -0000	1.7
  @@ -65,13 +65,9 @@
   import java.net.URL;
   
   import org.apache.commons.jelly.JellyContext;
  -
   import org.apache.commons.jelly.MissingAttributeException;
  -
   import org.apache.commons.jelly.Script;
  -
   import org.apache.commons.jelly.TagSupport;
  -
   import org.apache.commons.jelly.XMLOutput;
   
   /** A tag which conditionally evaluates its body based on some condition
  
  
  
  1.2       +19 -9     jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/jeez/example.jelly
  
  Index: example.jelly
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/jeez/example.jelly,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- example.jelly	19 Jul 2002 23:05:21 -0000	1.1
  +++ example.jelly	1 Aug 2002 09:53:18 -0000	1.2
  @@ -1,16 +1,26 @@
   <?xml version="1.0"?>
   <j:jelly xmlns:j="jelly:core" xmlns="jelly:jeez">
   
  -    <tagdef name="foo">
  -      This is called when the foo tag is created...
  -      
  -	  <echo>Called with ${n}. The value of x is ${x} and now will increment</echo>    	
  -	  <j:set var="x" value="${x + 1}"/>
  -	</tagdef>
  +  Defining the listFiles tag...
  +
  +  <!-- this tag iterates through a directory displaying the files -->    
  +  <tagdef name="listFiles">
  +  	Scanning directory: ${dir} includes: ${includes}
  +  	
  +    <fileScanner var="scanner">
  +      <fileset dir="${dir}" includes="${includes}" excludes="${excludes}"/>
  +    </fileScanner>
  +    
  +    <j:forEach var="file" items="${scanner.iterator()}">
  +      Found ${file.absolutePath}
  +    </j:forEach>
  +  </tagdef>
   	
  -	<!-- now lets use the tag -->
  -	<foo n="a"/>
  -	<foo n="b"/>			  			  	
  +  Now lets use the new listFiles tag	
  +	
  +  <listFiles dir="src/test" includes="**/*.jelly"/>
  +  
  +  <listFiles dir="." includes="*.xml"/>
     	
   
   </j:jelly>
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/jeez/filescanner.jelly
  
  Index: filescanner.jelly
  ===================================================================
  <?xml version="1.0"?>
  <j:jelly xmlns:j="jelly:core" xmlns="jelly:jeez">
  
    <fileScanner var="scanner">
      <fileset dir="src/test" includes="**/*.jelly"/>
    </fileScanner>
      
    Iterating through build files
    
    <j:forEach var="file" items="${scanner.iterator()}">
    
      <!-- here we could parse the file or process it in some way -->
      <!-- such as by calling <ant> with the given build.xml file -->
        
      Found ${file.absolutePath}
    </j:forEach>
  </j:jelly>
  
  
  
  1.2       +3 -2      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/jeez/TagDefTag.java
  
  Index: TagDefTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/jeez/TagDefTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TagDefTag.java	19 Jul 2002 23:05:21 -0000	1.1
  +++ TagDefTag.java	1 Aug 2002 09:53:18 -0000	1.2
  @@ -79,9 +79,10 @@
    */
   public class TagDefTag extends DefineTagTag {
   
  -    protected static DynamicTagLibrary tagLibrary;
  +    private DynamicTagLibrary tagLibrary;
       
  -    public TagDefTag() {
  +    public TagDefTag(DynamicTagLibrary tagLibrary) {
  +        this.tagLibrary = tagLibrary;
       }
   
       /**
  
  
  
  1.5       +49 -64    jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/jeez/JeezTagLibrary.java
  
  Index: JeezTagLibrary.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/jeez/JeezTagLibrary.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JeezTagLibrary.java	19 Jul 2002 23:05:21 -0000	1.4
  +++ JeezTagLibrary.java	1 Aug 2002 09:53:18 -0000	1.5
  @@ -71,7 +71,11 @@
   import org.apache.commons.jelly.JellyException;
   import org.apache.commons.jelly.impl.TagScript;
   import org.apache.commons.jelly.Script;
  +import org.apache.commons.jelly.Tag;
   import org.apache.commons.jelly.TagLibrary;
  +import org.apache.commons.jelly.impl.BeanTagScript;
  +import org.apache.commons.jelly.impl.DynaTagScript;
  +import org.apache.commons.jelly.impl.TagFactory;
   import org.apache.commons.jelly.tags.ant.AntTagLibrary;
   import org.apache.commons.jelly.tags.define.DynamicTagLibrary;
   import org.apache.commons.jelly.tags.werkz.WerkzTagLibrary;
  @@ -96,23 +100,19 @@
       private Log log = LogFactory.getLog(JeezTagLibrary.class);
   
       /** jelly:core taglib. */
  -    // private TagLibrary coreTagLib;
  +    // private TagLibrary coreTagLib = new CoreTagLibrary();
   
       /** jelly:werkz taglib. */
  -    private TagLibrary werkzTagLib;
  +    private TagLibrary werkzTagLib = new WerkzTagLibrary();
   
       /** jelly:ant taglib. */
       private AntTagLibrary antTagLib;
   
  -    private Set runtimeTasks;
  -
  -    private Project project;
  -
       /**
        * Use a default ant Project
        */
       public JeezTagLibrary() {
  -        this( AntTagLibrary.createProject() );
  +        this.antTagLib    = new AntTagLibrary();
       }
   
       
  @@ -121,67 +121,52 @@
        *  @param antProject The ant Project.
        */
       public JeezTagLibrary(Project antProject) {
  -
  -        this.project      = antProject;
  -        this.runtimeTasks = new HashSet();
  -
  -        // this.coreTagLib   = new CoreTagLibrary();
           this.antTagLib    = new AntTagLibrary( antProject );
  -        this.werkzTagLib  = new WerkzTagLibrary();
  -
  -        // #### this is a bit of a hack. 
  -        // when we introduce the concept of TagFactory objects
  -        // we could do a cleaner mechanism for this...
  -        TagDefTag.tagLibrary = this;
  -        
  -        registerTag( "target",
  -                     TargetTag.class );
  -        registerTag( "tagdef",
  -                     TagDefTag.class );
       }
   
  -    public TagScript createTagScript(String name,
  -                                     Attributes attrs) throws Exception
  -    {
  -        TagScript script = super.createTagScript( name, attrs );
  -
  +    public TagScript createTagScript(
  +        final String name,
  +        Attributes attrs
  +    ) throws Exception {
  +
  +        if ( name.equals( "tagdef" ) ) {
  +            return new BeanTagScript(
  +                new TagFactory() {
  +                    public Tag createTag() {
  +                        return new TagDefTag( JeezTagLibrary.this );
  +                    }
  +                }
  +            );
  +        }
  +        if ( name.equals( "target" ) ) {
  +            return new BeanTagScript(
  +                new TagFactory() {
  +                    public Tag createTag() {
  +                        return new TargetTag();
  +                    }
  +                }
  +            );
  +        }
  +        TagScript script = this.werkzTagLib.createTagScript( name, attrs );
           if ( script == null ) {
  -
  -            // script = this.coreTagLib.createTagScript( name, attrs );
  -
  +            script = antTagLib.createCustomTagScript( name, attrs );
               if ( script == null ) {
  -                
  -                script = this.werkzTagLib.createTagScript( name, attrs );
  -                
  -                if ( script == null ) {
  -
  -                    if ( isRuntimeTask( name ) ) {
  -                        if ( ! project.getTaskDefinitions().containsKey( name ) ) {
  -                            script = this.antTagLib.createRuntimeTaskTagScript( name, attrs );
  -                        } else {
  -                            this.runtimeTasks.remove( name );
  +                return new DynaTagScript(
  +                    new TagFactory() {
  +                        public Tag createTag() throws Exception {
  +                            // lets try create a dynamic tag first
  +                            Tag tag = JeezTagLibrary.this.createTag(name);
  +                            if ( tag != null ) {
  +                                return tag;
  +                            }
  +                            else {
  +                                return antTagLib.createTag( name );
  +                            }
                           }
                       }
  -
  -                    if ( script == null ) {
  -                        script = this.antTagLib.createTagScript( name, attrs );
  -                    }
  -
  -                    if ( name.equals( "taskdef" ) ) {
  -                        addRuntimeTask( attrs.getValue( "name" ) );
  -                    } 
  -                }
  +                );                        
               }
           }
  -
           return script;
  -    }
  -
  -    protected void addRuntimeTask(String name) {
  -        this.runtimeTasks.add( name );
  -    }
  -
  -    protected boolean isRuntimeTask(String name) {
  -        return this.runtimeTasks.contains( name );
       }
   }
  
  
  
  1.26      +34 -22    jakarta-commons-sandbox/jelly/maven.xml
  
  Index: maven.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/maven.xml,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- maven.xml	31 Jul 2002 11:19:21 -0000	1.25
  +++ maven.xml	1 Aug 2002 09:53:18 -0000	1.26
  @@ -269,18 +269,28 @@
       </java>
     </goal>
   
  -  <goal name="demo:junitui" prereqs="jelly-task" 
  -	description="Runs the Swing JUnit runner on the Jelly JUnit test suite">
  -	
  -    <java classname="junit.swingui.TestRunner" fork="yes">
  +  <goal name="demo:jeez" prereqs="jelly-task" 
  +	description="A demo of the jeez taglib">
  +
  +    <java classname="org.apache.commons.jelly.Jelly" fork="yes">
         <classpath refid="test.classpath"/>
  +      <arg value="src/test/org/apache/commons/jelly/jeez/example.jelly"/> 
       </java>
  +<!--	
  +	<jelly file="src/test/org/apache/commons/jelly/jeez/example.jelly"/> 
  +-->	
     </goal>
   
  -  <goal name="demo:jeez" prereqs="jelly-task" 
  -	description="A demo of the jeez taglib">
  -	
  +  <goal name="demo:jeez2" prereqs="jelly-task" 
  +	description="A demo of the jeez taglib looks just like Ant">
  +
  +    <java classname="org.apache.commons.jelly.Jelly" fork="yes">
  +      <classpath refid="test.classpath"/>
  +      <arg value="src/test/org/apache/commons/jelly/jeez/filescanner.jelly"/> 
  +    </java>
  +<!--	
   	<jelly file="src/test/org/apache/commons/jelly/jeez/example.jelly"/> 
  +-->	
     </goal>
   
     <goal name="demo:fileset" prereqs="jelly-task" 
  @@ -289,6 +299,15 @@
   	<jelly file="src/test/org/apache/commons/jelly/ant/filescanner.jelly"/> 
     </goal>
   
  +  <goal name="demo:fileset2" prereqs="jelly-task" 
  +	description="A demo of the fileScanner tag to walk Ant fileSets">
  +	
  +    <java classname="org.apache.commons.jelly.Jelly" fork="yes">
  +      <classpath refid="test.classpath"/>
  +      <arg value="src/test/org/apache/commons/jelly/ant/filescanner.jelly"/> 
  +    </java>
  +  </goal>
  +
     <goal name="demo:file" prereqs="jelly-task" 
   	description="A demo of using the file tag to output to multiple files">
   	
  @@ -357,30 +376,23 @@
   	<jelly file="src/test/org/apache/commons/jelly/sql/example2.jelly" output="target/sqloutput2.xml"/>	
   	<jelly file="src/test/org/apache/commons/jelly/sql/testSql.jelly" output="target/sqloutput3.xml"/>		
   -->	
  -   </goal>
  -   
  -  <goal name="demo:hsql" prereqs="jelly-task"
  -    description="Runs a HSQL server, which can be useful for performing SQL tests">
  -    <delete>
  -      <fileset dir="." includes="test.*"/>
  -    </delete>	
  -    <java classname="org.hsqldb.Server" fork="yes">
  -      <classpath refid="test.classpath"/>
  -    </java>
     </goal>
  -	
  -
  +   
     <goal name="demo:tagdef" prereqs="java:compile"
       description="A demonstration of the use of tagdef inside a Maven build">
       
  +    About to define the foo tag...
  +    
       <tagdef name="foo">
   	  <echo>Called with ${name}. The value of x is ${x} and now will increment</echo>    	
   	  <j:set var="x" value="${x + 1}"/>
   	</tagdef>
   	
  -	<!-- now lets use the tag -->
  -	<foo name="a"/>
  -	<foo name="b"/>			  			  	
  +	Now about to invoke the foo tag...
  +	<foo name="a" x="0"/>
  +	<foo name="b"/>			  			  
  +	
  +	Done
     	
     </goal>
     	          
  
  
  
  1.50      +4 -4      jakarta-commons-sandbox/jelly/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/project.xml,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- project.xml	31 Jul 2002 11:46:23 -0000	1.49
  +++ project.xml	1 Aug 2002 09:53:18 -0000	1.50
  @@ -141,12 +141,12 @@
   
       <dependency>
         <id>dom4j</id>
  -      <version>1.4-dev-5</version>
  +      <version>1.4-dev-6</version>
       </dependency>
   
       <dependency>
         <id>commons-jexl</id>
  -      <version>1.0-dev</version>
  +      <version>SNAPSHOT</version>
       </dependency>
   
       <dependency>
  @@ -247,10 +247,12 @@
         <version>SNAPSHOT</version>
       </dependency>
   
  +<!--
       <dependency>
         <id>log4j</id>
         <version>1.1.3</version>
       </dependency>
  +-->
   
   	<!-- runtime dependency for validate taglib -->
       <dependency>
  @@ -269,9 +271,7 @@
   	
       <dependency>
         <id>hsqldb</id>
  -      <type>required</type>
         <version>1.7.0</version>
  -      <jar>hsqldb-1.7.0.jar</jar>
       </dependency>
     </dependencies>
     <build>
  
  
  
  1.22      +2 -1      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/jelly.properties
  
  Index: jelly.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/jelly.properties,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- jelly.properties	30 Jul 2002 17:57:19 -0000	1.21
  +++ jelly.properties	1 Aug 2002 09:53:18 -0000	1.22
  @@ -7,11 +7,12 @@
   ant         = org.apache.commons.jelly.tags.ant.AntTagLibrary
   log         = org.apache.commons.jelly.tags.log.LogTagLibrary
   werkz       = org.apache.commons.jelly.tags.werkz.WerkzTagLibrary
  +jeez		= org.apache.commons.jelly.tags.jeez.JeezTagLibrary
   util        = org.apache.commons.jelly.tags.util.UtilTagLibrary
   junit 	    = org.apache.commons.jelly.tags.junit.JUnitTagLibrary
  -swing	    = org.apache.commons.jelly.tags.swing.SwingTagLibrary
   
   # optional taglibs
  +swing	    = org.apache.commons.jelly.tags.swing.SwingTagLibrary
   html		= org.apache.commons.jelly.tags.html.HTMLTagLibrary
   betwixt		= org.apache.commons.jelly.tags.betwixt.BetwixtTagLibrary
   jms         = org.apache.commons.jelly.tags.jms.JMSTagLibrary
  
  
  
  1.12      +6 -7      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/TagLibrary.java
  
  Index: TagLibrary.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/TagLibrary.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- TagLibrary.java	7 Jun 2002 11:56:29 -0000	1.11
  +++ TagLibrary.java	1 Aug 2002 09:53:18 -0000	1.12
  @@ -93,8 +93,7 @@
   
           Class type = (Class) tags.get(name);
           if ( type != null ) {
  -            Tag tag = (Tag) type.newInstance();
  -            return TagScript.newInstance(tag);
  +            return TagScript.newInstance(type);
           }
           return null;
   
  
  
  
  1.4       +11 -3     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/swing/SwingTagLibrary.java
  
  Index: SwingTagLibrary.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/swing/SwingTagLibrary.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SwingTagLibrary.java	24 Jul 2002 17:34:43 -0000	1.3
  +++ SwingTagLibrary.java	1 Aug 2002 09:53:19 -0000	1.4
  @@ -70,8 +70,11 @@
   
   import org.apache.commons.beanutils.ConvertUtils;
   
  +import org.apache.commons.jelly.Tag;
   import org.apache.commons.jelly.TagLibrary;
   import org.apache.commons.jelly.impl.TagScript;
  +import org.apache.commons.jelly.impl.DynaTagScript;
  +import org.apache.commons.jelly.impl.TagFactory;
   import org.apache.commons.jelly.tags.swing.converters.DimensionConverter;
   import org.apache.commons.jelly.tags.swing.converters.PointConverter;
   
  @@ -111,10 +114,15 @@
       public TagScript createTagScript(String name, Attributes attributes) throws Exception {
           TagScript answer = super.createTagScript(name, attributes);
           if ( answer == null ) {
  -            Factory factory = getFactory( name );
  +            final Factory factory = getFactory( name );
               if ( factory != null ) {
  -                ComponentTag tag = new ComponentTag(factory);
  -                answer = TagScript.newInstance(tag);
  +                return new DynaTagScript(
  +                    new TagFactory() {
  +                        public Tag createTag() throws Exception {
  +                            return new ComponentTag(factory);
  +                        }
  +                    }
  +                );
               }
           }
           return answer;
  
  
  

--
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