dion        2003/01/13 20:01:01

  Added:       jelly/jelly-tags/bean/src/java/org/apache/commons/jelly/tags/bean
                        BeanTagLibrary.java package.html
                        BeanPropertyTag.java BeandefTag.java BeanTag.java
               jelly/jelly-tags/bean/src/test/org/apache/commons/jelly/tags/bean
                        Product.java TestJelly.java Order.java
                        Customer.java MyTagLibrary.java suite.jelly
               jelly/jelly-tags/bean .cvsignore project.properties
                        project.xml maven.xml
  Log:
  Move bean taglib out of core
  
  Revision  Changes    Path
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/bean/src/java/org/apache/commons/jelly/tags/bean/BeanTagLibrary.java
  
  Index: BeanTagLibrary.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/bean/src/java/org/apache/commons/jelly/tags/bean/BeanTagLibrary.java,v
 1.1 2003/01/14 04:01:00 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/14 04:01:00 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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 [EMAIL PROTECTED]
   *
   * 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: BeanTagLibrary.java,v 1.1 2003/01/14 04:01:00 dion Exp $
   */
  package org.apache.commons.jelly.tags.bean;
  
  import java.util.Hashtable;
  import java.util.Map;
  
  import org.apache.commons.jelly.Tag;
  import org.apache.commons.jelly.TagLibrary;
  import org.apache.commons.jelly.impl.TagFactory;
  import org.apache.commons.jelly.impl.TagScript;
  
  import org.xml.sax.Attributes;
  
  /** Describes the Taglib. This class could be generated by XDoclet
    *
    * @author Theo Niemeijer
    * @version $Revision: 1.1 $
    */
  public class BeanTagLibrary extends TagLibrary {
  
      /** Synchronized map of tag names to bean classes */
      private Map beanTypes = new Hashtable();
      
      public BeanTagLibrary() {
          registerTagFactory(
              "beandef",
              new TagFactory() {
                  public Tag createTag(String name, Attributes attributes) throws 
Exception {
                      return new BeandefTag(BeanTagLibrary.this);
                  }
              }
          );
      }
  
      /**
       * Allows tags to register new bean types
       */
      public void registerBean(String name, Class type) {
          beanTypes.put(name, type);
      }
      
      // TagLibrary interface
      //-------------------------------------------------------------------------      
              
      public TagScript createTagScript(
          final String name, final Attributes attributes
      ) throws Exception {
  
          // check for standard tags first                        
          TagScript answer = super.createTagScript(name, attributes);
          if (answer != null) {
              return answer;
          }
          
          // lets try a dynamic tag
          return new TagScript( createTagFactory(name, attributes) );
      }
  
      // Implementation methods
      //-------------------------------------------------------------------------      
              
  
      /** 
       * Factory method to create a TagFactory for a given tag attribute and attributes
       */
      protected TagFactory createTagFactory(String name, Attributes attributes) throws 
Exception {
  
          return new TagFactory() {
              public Tag createTag(String name, Attributes attributes) throws 
Exception {
                  return createBeanTag(name, attributes);
              }
          };
      }
  
      protected Tag createBeanTag(String name, Attributes attributes) throws Exception 
{
          // is the name bound to a specific class
          Class beanType = getBeanType(name, attributes);
          if (beanType != null) {
              return new BeanTag(beanType, name);
          }
          
          // its a property tag
          return new BeanPropertyTag(name);
      }
      
      protected Class getBeanType(String name, Attributes attributes) {
          return (Class) beanTypes.get(name);
      }
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/bean/src/java/org/apache/commons/jelly/tags/bean/package.html
  
  Index: package.html
  ===================================================================
  <html>
  <head>
  </head>
  <body>
  
    <p>
        A tag library for mapping tags to beans using a similar approach to Ant.
    </p>
    
  </body>
  </html>
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/bean/src/java/org/apache/commons/jelly/tags/bean/BeanPropertyTag.java
  
  Index: BeanPropertyTag.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/bean/src/java/org/apache/commons/jelly/tags/bean/BeanPropertyTag.java,v
 1.1 2003/01/14 04:01:00 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/14 04:01:00 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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 [EMAIL PROTECTED]
   *
   * 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: BeanPropertyTag.java,v 1.1 2003/01/14 04:01:00 dion Exp $
   */
  
  package org.apache.commons.jelly.tags.bean;
  
  import java.lang.reflect.Method;
  import java.util.Map;
  
  import org.apache.commons.beanutils.MethodUtils;
  
  import org.apache.commons.jelly.JellyException;
  import org.apache.commons.jelly.XMLOutput;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  
  /** 
   * Creates a nested property via calling a beans createFoo() method then
   * either calling the setFoo(value) or addFoo(value) methods in a similar way
   * to how Ant tags construct themselves.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class BeanPropertyTag extends BeanTag {
  
      /** empty arguments constant */
      private static final Object[] EMPTY_ARGS = {};
      
      /** empty argument types constant */
      private static final Class[] EMPTY_ARG_TYPES = {};
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog(BeanPropertyTag.class);
  
  
      /** the name of the create method */
      private String createMethodName;
  
      
      public BeanPropertyTag(String tagName) {
          super(Object.class, tagName);
  
          if (tagName.length() > 0) {
              createMethodName = "create" 
                  + tagName.substring(0,1).toUpperCase() 
                  + tagName.substring(1);
          }
      }
      
      /**
       * Creates a new instance by calling a create method on the parent bean
       */
      protected Object newInstance(Class theClass, Map attributes, XMLOutput output) 
throws Exception {
          Object parentObject = getParentObject();
          if (parentObject != null) {
              // now lets try call the create method...
              Class parentClass = parentObject.getClass();
              Method method = findCreateMethod(parentClass);
              if (method != null) {
                  try {
                      return method.invoke(parentObject, EMPTY_ARGS);
                  }
                  catch (Exception e) {
                      throw new JellyException( "failed to invoke method: " + method + 
" on bean: " + parentObject + " reason: " + e, e );
                  }
              }
          }
          else {
              throw new JellyException( "The " + getTagName() + " tag must be nested 
within a tag which maps to a bean property" );
          }
          return null;
      }
      
      /**
       * Finds the Method to create a new property object
       */
      protected Method findCreateMethod(Class theClass) {
          if (createMethodName == null) {
              return null;
          }
          return MethodUtils.getAccessibleMethod(
              theClass, createMethodName, EMPTY_ARG_TYPES
          );
      }    
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/bean/src/java/org/apache/commons/jelly/tags/bean/BeandefTag.java
  
  Index: BeandefTag.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/bean/src/java/org/apache/commons/jelly/tags/bean/BeandefTag.java,v
 1.1 2003/01/14 04:01:00 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/14 04:01:00 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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 [EMAIL PROTECTED]
   *
   * 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: BeandefTag.java,v 1.1 2003/01/14 04:01:00 dion Exp $
   */
  
  package org.apache.commons.jelly.tags.bean;
  
  import java.util.HashMap;
  import java.util.Map;
  
  import org.apache.commons.jelly.JellyException;
  import org.apache.commons.jelly.MissingAttributeException;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  
  /** 
   * Binds a Java bean to the given named Jelly tag so that the attributes of
   * the tag set the bean properties..
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class BeandefTag extends TagSupport {
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog(BeandefTag.class);
  
      /** An empty Map as I think Collections.EMPTY_MAP is only JDK 1.3 onwards */
      private static final Map EMPTY_MAP = new HashMap();
  
      /** the name of the tag to create */
      private String name;
      
      /** the Java class name to use for the tag */
      private String className;
  
      /** the ClassLoader used to load beans */
      private ClassLoader classLoader;
      
      /** the name of the attribute used for the variable name */
      private String varAttribute = "var";
  
      /** the library in which to define this new bean tag */    
      private BeanTagLibrary library;
      
      public BeandefTag(BeanTagLibrary library) {
          this.library = library;
      }
      
      // Tag interface
      //-------------------------------------------------------------------------      
              
      public void doTag(XMLOutput output) throws Exception {
          invokeBody(output);
          
                if (name == null) {
                        throw new MissingAttributeException("name");
                }
                if (className == null) {
                        throw new MissingAttributeException("className");
                }
          
                Class theClass = null;
                try {
                        ClassLoader classLoader = getClassLoader();
                        theClass = classLoader.loadClass(className);
                } 
                catch (ClassNotFoundException e) {
                        try {
                                theClass = 
getClass().getClassLoader().loadClass(className);
                        } 
              catch (ClassNotFoundException e2) {
                                try {
                                        theClass = Class.forName(className);
                                } 
                  catch (ClassNotFoundException e3) {
                      log.error( "Could not load class: " + className + " exception: " 
+ e, e );
                                        throw new JellyException(
                                                "Could not find class: "
                                                        + className
                                                        + " using ClassLoader: "
                                                        + classLoader);
                                }
                        }
                }
          
          // @todo should we allow the variable name to be specified?
          library.registerBean(name, theClass);
        }
  
      
      // Properties
      //-------------------------------------------------------------------------      
              
      
      /** 
       * Sets the name of the tag to create
       */
      public void setName(String name) {
          this.name = name;
      }
      
      /** 
       * Sets the Java class name to use for the tag
       */
      public void setClass(String className) {
          this.className = className;
      }
      
      /**
       * Sets the ClassLoader to use to load the class. 
       * If no value is set then the current threads context class
       * loader is used.
       */
      public void setClassLoader(ClassLoader classLoader) {
          this.classLoader = classLoader;
      }
  
      /**
       * @return the ClassLoader to use to load classes
       *  or will use the thread context loader if none is specified.
       */    
      public ClassLoader getClassLoader() {
          if ( classLoader == null ) {
              ClassLoader answer = Thread.currentThread().getContextClassLoader();
              if ( answer == null ) {
                  answer = getClass().getClassLoader();
              }
              return answer;
          }
          return classLoader;
      }
  
      /**
       * Sets the name of the attribute used to define the bean variable that this 
dynamic
       * tag will output its results as. This defaults to 'var' though this property
       * can be used to change this if it conflicts with a bean property called 'var'.
       */
      public void setVarAttribute(String varAttribute) {    
          this.varAttribute = varAttribute;
      }
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/bean/src/java/org/apache/commons/jelly/tags/bean/BeanTag.java
  
  Index: BeanTag.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/bean/src/java/org/apache/commons/jelly/tags/bean/BeanTag.java,v
 1.1 2003/01/14 04:01:00 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/14 04:01:00 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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 [EMAIL PROTECTED]
   *
   * 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: BeanTag.java,v 1.1 2003/01/14 04:01:00 dion Exp $
   */
  
  package org.apache.commons.jelly.tags.bean;
  
  import java.lang.reflect.Method;
  import java.util.Collection;
  
  import org.apache.commons.beanutils.BeanUtils;
  import org.apache.commons.beanutils.MethodUtils;
  import org.apache.commons.jelly.JellyException;
  import org.apache.commons.jelly.impl.BeanSource;
  import org.apache.commons.jelly.impl.CollectionTag;
  import org.apache.commons.jelly.tags.core.UseBeanTag;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  
  /** 
   * Creates a bean for the given tag which is then either output as a variable
   * or can be added to a parent tag.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class BeanTag extends UseBeanTag {
  
      /** empty arguments constant */
      private static final Object[] EMPTY_ARGS = {};
      
      /** empty argument types constant */
      private static final Class[] EMPTY_ARG_TYPES = {};
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog(BeanTag.class);
  
  
      /** the name of the property to create */
      private String tagName;
  
      /** the name of the adder method */
      private String addMethodName;
  
      
      public BeanTag(Class defaultClass, String tagName) {
          super(defaultClass);
          this.tagName = tagName;
          
          if (tagName.length() > 0) {
              addMethodName = "add" 
                  + tagName.substring(0,1).toUpperCase() 
                  + tagName.substring(1);
          }
      }
  
      /**
       * @return the local name of the XML tag to which this tag is bound
       */
      public String getTagName() {
          return tagName;
      }
  
      /**
       * Output the tag as a named variable. If the parent bean has an adder or setter
       * method then invoke that to register this bean with its parent.
       */
      protected void processBean(String var, Object bean) throws Exception {
          if (var != null) {
              context.setVariable(var, bean);
          }
          
          // now lets try set the parent property via calling the adder or the setter 
method
          if (bean != null) {
              Object parentObject = getParentObject();
              if (parentObject != null) {
                  if (parentObject instanceof Collection) {
                      Collection collection = (Collection) parentObject;
                      collection.add(bean);
                  }
                  else {
                      // lets see if there's a setter method...
                      Method method = findAddMethod(parentObject.getClass(), 
bean.getClass());
                      if (method != null) {
                          Object[] args = { bean };
                          try {
                              method.invoke(parentObject, args);
                          }
                          catch (Exception e) {
                              throw new JellyException( "failed to invoke method: " + 
method + " on bean: " + parentObject + " reason: " + e, e );
                          }
                      }
                      else {
                          BeanUtils.setProperty(parentObject, tagName, bean);
                      }
                  }
                  
              }
              else {
                  // lets try find a parent List to add this bean to
                  CollectionTag tag = (CollectionTag) 
findAncestorWithClass(CollectionTag.class);
                  if (tag != null) {
                      tag.addItem(bean);
                  }
                  else {
                      log.warn( "Could not add bean to parent for bean: " + bean );
                  }
              }
          }
              
      }
  
      /**
       * Finds the Method to add the new bean
       */
      protected Method findAddMethod(Class beanClass, Class valueClass) {
          if (addMethodName == null) {
              return null;
          }
          Class[] argTypes = { valueClass };
          return MethodUtils.getAccessibleMethod(
              beanClass, addMethodName, argTypes
          );
      }
          
          
      /**
       * @return the parent bean object
       */
      protected Object getParentObject() throws Exception {
          BeanSource tag = (BeanSource) findAncestorWithClass(BeanSource.class);
          if (tag != null) {
              return tag.getBean();
          }
          return null;
      }        
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/bean/src/test/org/apache/commons/jelly/tags/bean/Product.java
  
  Index: Product.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/bean/src/test/org/apache/commons/jelly/tags/bean/Product.java,v
 1.1 2003/01/14 04:01:01 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/14 04:01:01 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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 [EMAIL PROTECTED]
   *
   * 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: Product.java,v 1.1 2003/01/14 04:01:01 dion Exp $
   */
  package org.apache.commons.jelly.tags.bean;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /** 
   * A sample bean that we can construct via Jelly tags
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class Product {
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog(Product.class);
  
      private String id;
      private String name;
      
      public Product() {
      }
      
      public String toString() {
          return "Product[id=" + id + ";name=" + name + "]";
      }
  
      // Properties
      //-------------------------------------------------------------------------
      /**
       * Returns the id.
       * @return String
       */
      public String getId() {
          return id;
      }
  
      /**
       * Returns the name.
       * @return String
       */
      public String getName() {
          return name;
      }
  
      /**
       * Sets the id.
       * @param id The id to set
       */
      public void setId(String id) {
          this.id = id;
      }
  
      /**
       * Sets the name.
       * @param name The name to set
       */
      public void setName(String name) {
          this.name = name;
      }
  
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/bean/src/test/org/apache/commons/jelly/tags/bean/TestJelly.java
  
  Index: TestJelly.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/bean/src/test/org/apache/commons/jelly/tags/bean/TestJelly.java,v
 1.1 2003/01/14 04:01:01 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/14 04:01:01 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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 [EMAIL PROTECTED]
   *
   * 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: TestJelly.java,v 1.1 2003/01/14 04:01:01 dion Exp $
   */
  package org.apache.commons.jelly.tags.bean;
  
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  import org.apache.commons.jelly.tags.junit.JellyTestSuite;
  
  /** 
   * A helper class to run jelly test cases as part of Ant's JUnit tests
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class TestJelly extends JellyTestSuite {
  
      public static void main( String[] args ) throws Exception {
          TestRunner.run( suite() );
      }
      
      public static TestSuite suite() throws Exception {
          return createTestSuite(TestJelly.class, "suite.jelly");        
      }
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/bean/src/test/org/apache/commons/jelly/tags/bean/Order.java
  
  Index: Order.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/bean/src/test/org/apache/commons/jelly/tags/bean/Order.java,v
 1.1 2003/01/14 04:01:01 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/14 04:01:01 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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 [EMAIL PROTECTED]
   *
   * 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: Order.java,v 1.1 2003/01/14 04:01:01 dion Exp $
   */
  package org.apache.commons.jelly.tags.bean;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /** 
   * A sample bean that we can construct via Jelly tags
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class Order {
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog(Order.class);
  
      private Product product;
      private int amount;
      private double price;
      
      public Order() {
      }
      
      public String toString() {
          return "Order[amount=" + amount + ";price=" + price + ";product=" + product 
+ "]";
      }
      
      /** 
       * Factory method to create a new Product
       */
      public Product createProduct() {
          return new Product();
      }
          
      /**
       * Returns the amount.
       * @return int
       */
      public int getAmount() {
          return amount;
      }
  
      /**
       * Returns the price.
       * @return double
       */
      public double getPrice() {
          return price;
      }
  
      /**
       * Sets the amount.
       * @param amount The amount to set
       */
      public void setAmount(int amount) {
          this.amount = amount;
      }
  
      /**
       * Sets the price.
       * @param price The price to set
       */
      public void setPrice(double price) {
          this.price = price;
      }
  
      /**
       * Returns the product.
       * @return Product
       */
      public Product getProduct() {
          return product;
      }
  
      /**
       * Sets the product.
       * @param product The product to set
       */
      public void setProduct(Product product) {
          this.product = product;
      }
  
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/bean/src/test/org/apache/commons/jelly/tags/bean/Customer.java
  
  Index: Customer.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/bean/src/test/org/apache/commons/jelly/tags/bean/Customer.java,v
 1.1 2003/01/14 04:01:01 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/14 04:01:01 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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 [EMAIL PROTECTED]
   *
   * 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: Customer.java,v 1.1 2003/01/14 04:01:01 dion Exp $
   */
  package org.apache.commons.jelly.tags.bean;
  
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /** 
   * A sample bean that we can construct via Jelly tags
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class Customer {
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog(Customer.class);
  
      private String name;
      private String city;
      private String location;
      private List orders = new ArrayList();
      
          
      public Customer() {
      }
      
      public Customer(String name) {
          setName(name);
      }
      
      public Customer(String name, String city) {
          setName(name);
          setCity(city);
      }
      
      public Customer(String name, String city, Order anOrder) {
          setName(name);
          setCity(city);
          addOrder(anOrder);
      }
      
      public Customer(Customer cust) {
          setName(cust.getName());
          setCity(cust.getCity());
          setLocation(cust.getLocation());
          List list = cust.getOrders();
          if(null != list) {
              for(Iterator iter = list.iterator();iter.hasNext();) {
                  addOrder((Order)iter.next());
              }
          }
      }
      
      public String toString() {
          return super.toString() + "[name=" + name + ";city=" + city + "]";
      }
  
      /**
       * Creates a new Order object 
       */
      public Order createOrder() {
          return new Order();
      }    
  
      public List getOrders() {
          return orders;
      }
      
      public void addOrder(Order order) {
          orders.add(order);
      }
      
      public void removeOrder(Order order) {
          orders.remove(order);
      }    
  
      /**
       * Returns the city.
       * @return String
       */
      public String getCity() {
          return city;
      }
  
      /**
       * Returns the location.
       * @return String
       */
      public String getLocation() {
          return location;
      }
  
      /**
       * Returns the name.
       * @return String
       */
      public String getName() {
          return name;
      }
  
      /**
       * Sets the city.
       * @param city The city to set
       */
      public void setCity(String city) {
          this.city = city;
      }
  
      /**
       * Sets the location.
       * @param location The location to set
       */
      public void setLocation(String location) {
          this.location = location;
      }
  
      /**
       * Sets the name.
       * @param name The name to set
       */
      public void setName(String name) {
          this.name = name;
      }
  
  
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/bean/src/test/org/apache/commons/jelly/tags/bean/MyTagLibrary.java
  
  Index: MyTagLibrary.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/bean/src/test/org/apache/commons/jelly/tags/bean/MyTagLibrary.java,v
 1.1 2003/01/14 04:01:01 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/14 04:01:01 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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 [EMAIL PROTECTED]
   *
   * 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: MyTagLibrary.java,v 1.1 2003/01/14 04:01:01 dion Exp $
   */
  package org.apache.commons.jelly.tags.bean;
  
  import org.apache.commons.jelly.tags.bean.BeanTagLibrary;
  
  /** 
   * Describes the Taglib. 
   * This could be created via Jelly script, or could load the mapping of 
   * tag names to bean classes from properties file etc  but is implemented in Java
   * code for simplicity
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class MyTagLibrary extends BeanTagLibrary {
  
      public MyTagLibrary() {
          registerBean( "customer", Customer.class );
      }
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/bean/src/test/org/apache/commons/jelly/tags/bean/suite.jelly
  
  Index: suite.jelly
  ===================================================================
  <?xml version="1.0"?>
  
  <test:suite 
        xmlns:j="jelly:core"
        xmlns="jelly:org.apache.commons.jelly.tags.bean.MyTagLibrary" 
        xmlns:test="jelly:junit" 
        xmlns:log="jelly:log">
  
  <test:case name="testNestedBean">
  
        <customer var="c1" name="James" location="London" >
                <order amount="100" price="2.99">
                        <product id="p1" name="Beer"/>
                </order>
                <order amount="200" price="4.99">
                        <product id="p2" name="Pizza"/>
                </order>
    </customer>
    
    <log:info>Created a customer with name: ${c1.name} and location: 
${c1.location}</log:info>
    <log:info>Customer has orders ${c1.orders}</log:info>
  
        <test:assertEquals expected="James" actual="${c1.name}"/>
        <test:assertEquals expected="London" actual="${c1.location}"/>
  
        <test:assertTrue test="${size(c1.orders) == 2}"/>
  
        <test:assertTrue test="${c1.orders[0].amount == 100}"/>
        <test:assertTrue test="${c1.orders[0].price == 2.99}"/>
        
        <test:assertTrue test="${c1.orders[1].amount == 200}"/>
        <test:assertTrue test="${c1.orders[1].price == 4.99}"/>
  
        <test:assertTrue test="${c1.orders[0].product != null}"/>
        <test:assertTrue test="${c1.orders[1].product != null}"/>
        
        <test:assertEquals expected="p1" actual="${c1.orders[0].product.id}"/>
        <test:assertEquals expected="Beer" actual="${c1.orders[0].product.name}"/>
  
        <test:assertEquals expected="p2" actual="${c1.orders[1].product.id}"/>
        <test:assertEquals expected="Pizza" actual="${c1.orders[1].product.name}"/>
        
        
  </test:case>
  
  
  <test:case name="testBeanList">
  
        <j:useList var="list">
                <customer name="James" location="London">
                        <order amount="100" price="2.99">
                                <product id="p1" name="Beer"/>
                        </order>
                        <order amount="200" price="4.99">
                                <product id="p2" name="Pizza"/>
                        </order>
          </customer>
                <customer name="Bob" location="Atlanta">
                        <order amount="200" price="2.99">
                                <product id="p1" name="Beer"/>
                        </order>
          </customer>
        </j:useList>
          
        <log:info>Created a list of customers ${list}</log:info>
  
        <test:assertTrue test="${size(list) == 2}"/>
  
        <test:assertEquals expected="James" actual="${list[0].name}"/>
        <test:assertEquals expected="London" actual="${list[0].location}"/>
  
        <test:assertTrue test="${size(list[0].orders) == 2}"/>
  
        <test:assertTrue test="${list[0].orders[0].amount == 100}"/>
        <test:assertTrue test="${list[0].orders[0].price == 2.99}"/>
        
        <test:assertTrue test="${list[0].orders[1].amount == 200}"/>
        <test:assertTrue test="${list[0].orders[1].price == 4.99}"/>
  
        <test:assertTrue test="${list[0].orders[0].product != null}"/>
        <test:assertTrue test="${list[0].orders[1].product != null}"/>
        
        <test:assertEquals expected="p1" actual="${list[0].orders[0].product.id}"/>
        <test:assertEquals expected="Beer" 
actual="${list[0].orders[0].product.name}"/>
  
        <test:assertEquals expected="p2" actual="${list[0].orders[1].product.id}"/>
        <test:assertEquals expected="Pizza" 
actual="${list[0].orders[1].product.name}"/>
        
        
        <test:assertEquals expected="Bob" actual="${list[1].name}"/>
        <test:assertEquals expected="Atlanta" actual="${list[1].location}"/>
  
  </test:case>
  
  </test:suite>
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/bean/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  target
  maven.log
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/bean/project.properties
  
  Index: project.properties
  ===================================================================
  # -------------------------------------------------------------------
  # P R O J E C T  P R O P E R T I E S
  # -------------------------------------------------------------------
  
  maven.junit.fork=true
  
  maven.compile.deprecation = on
  
  # Installation dir
  maven.dist.install.dir = /usr/local/jelly
  
  maven.checkstyle.properties=../tag-checkstyle.properties
  
  
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/bean/project.xml
  
  Index: project.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE project [
    <!-- see file for description -->
    <!ENTITY commonDeps SYSTEM "file:../../commonDependencies.ent">
  ]>
  <project>
    <extend>../tag-project.xml</extend>
    <id>commons-jelly-tags-bean</id>
    <name>commons-jelly-tags-bean</name>
  
    <package>org.apache.commons.jelly.tags.bean</package>
  
    <description>
         The Jelly Bean Tag Library
    </description>
    <shortDescription>Commons Jelly Bean Tag Library</shortDescription>
    
    <url>http://jakarta.apache.org/commons/sandbox/jelly/tags/bean/</url>
  
    <siteDirectory>/www/jakarta.apache.org/commons/sandbox/jelly/bean/</siteDirectory>
    
<distributionDirectory>/www/jakarta.apache.org/builds/jakarta-commons-sandbox/jelly/tags/bean</distributionDirectory>
    <repository>
      
<connection>scm:cvs:pserver:[EMAIL PROTECTED]:/home/cvspublic:jakarta-commons-sandbox/jelly/jelly-tags/bean/</connection>
      
<url>http://cvs.apache.org/viewcvs/jakarta-commons-sandbox/jelly/jelly-tags/bean/</url>
    </repository>
    
    <dependencies>
    
      &commonDeps;
    
      <!-- START for compilation -->
    
      <dependency>
        <id>commons-jelly</id>
        <version>SNAPSHOT</version>
      </dependency>
        
      <!-- END for compilation -->
      
      <!-- below for testing, pulled in by ant taglib -->
  
      <dependency>
        <id>commons-jelly+tags-ant</id>
        <version>SNAPSHOT</version>
      </dependency>
      
      <dependency>
        <id>ant</id>
        <version>1.5.1</version>
      </dependency>
      
      <dependency>
        <id>ant+optional</id>
        <version>1.5.1</version>
      </dependency>
      
      <dependency>
        <id>commons-grant</id>
        <version>1.0-beta-4</version>
      </dependency>
  
      
    </dependencies>
    
  </project>
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/bean/maven.xml
  
  Index: maven.xml
  ===================================================================
  <project default="java:jar">
  
  </project>
  
  
  

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

Reply via email to