You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by js...@apache.org on 2002/08/09 19:26:41 UTC

cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/jeez JeezTagLibrary.java TagDefTag.java

jstrachan    2002/08/09 10:26:41

  Modified:    jelly/src/java/org/apache/commons/jelly/tags/define
                        DefineBeanTag.java InvokeBodyTag.java
                        AttributeTag.java DefineTagSupport.java
                        DefineTagLibTag.java
               jelly/src/java/org/apache/commons/jelly/impl
                        StaticTagScript.java
               jelly/src/java/org/apache/commons/jelly/tags/jeez
                        JeezTagLibrary.java TagDefTag.java
  Added:       jelly/src/java/org/apache/commons/jelly/impl BeanTag.java
                        Attribute.java DynamicTagLibrary.java
                        DynamicTag.java
  Removed:     jelly/src/java/org/apache/commons/jelly/tags/define
                        Attribute.java DynamicTag.java
                        DynamicTagLibrary.java BeanTag.java
  Log:
  slight reorganisation of the implementation classes for dynamic tags, out of the define tag library and into the core jelly.impl package where they belong. Now the define package only contains the define tag library, which makes things less confusing. Also the define tag classes are going to be renamed so that the auto-generated documentation comes out neater.
  
  Revision  Changes    Path
  1.3       +2 -0      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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefineBeanTag.java	1 Aug 2002 09:53:18 -0000	1.2
  +++ DefineBeanTag.java	9 Aug 2002 17:26:40 -0000	1.3
  @@ -70,6 +70,8 @@
   import org.apache.commons.jelly.MissingAttributeException;
   import org.apache.commons.jelly.Tag;
   import org.apache.commons.jelly.XMLOutput;
  +import org.apache.commons.jelly.impl.Attribute;
  +import org.apache.commons.jelly.impl.BeanTag;
   import org.apache.commons.jelly.impl.TagFactory;
   
   import org.apache.commons.logging.Log;
  
  
  
  1.10      +6 -5      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/InvokeBodyTag.java
  
  Index: InvokeBodyTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/InvokeBodyTag.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- InvokeBodyTag.java	9 Aug 2002 15:48:48 -0000	1.9
  +++ InvokeBodyTag.java	9 Aug 2002 17:26:40 -0000	1.10
  @@ -67,6 +67,7 @@
   import org.apache.commons.jelly.Tag;
   import org.apache.commons.jelly.TagSupport;
   import org.apache.commons.jelly.XMLOutput;
  +import org.apache.commons.jelly.impl.DynamicTag;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  
  
  
  1.2       +1 -0      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/AttributeTag.java
  
  Index: AttributeTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/AttributeTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AttributeTag.java	17 Jul 2002 17:37:58 -0000	1.1
  +++ AttributeTag.java	9 Aug 2002 17:26:40 -0000	1.2
  @@ -65,6 +65,7 @@
   import org.apache.commons.jelly.TagSupport;
   import org.apache.commons.jelly.XMLOutput;
   import org.apache.commons.jelly.expression.Expression;
  +import org.apache.commons.jelly.impl.Attribute;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  
  
  
  1.2       +1 -0      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DefineTagSupport.java
  
  Index: DefineTagSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DefineTagSupport.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefineTagSupport.java	25 Jun 2002 19:12:28 -0000	1.1
  +++ DefineTagSupport.java	9 Aug 2002 17:26:40 -0000	1.2
  @@ -64,6 +64,7 @@
   
   import org.apache.commons.jelly.JellyException;
   import org.apache.commons.jelly.TagSupport;
  +import org.apache.commons.jelly.impl.DynamicTagLibrary;
   
   /** 
    * An abstract base class useful for implementation inheritence.
  
  
  
  1.8       +6 -5      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DefineTagLibTag.java
  
  Index: DefineTagLibTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DefineTagLibTag.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DefineTagLibTag.java	9 Aug 2002 15:48:48 -0000	1.7
  +++ DefineTagLibTag.java	9 Aug 2002 17:26:40 -0000	1.8
  @@ -66,6 +66,7 @@
   import org.apache.commons.jelly.TagLibrary;
   import org.apache.commons.jelly.TagSupport;
   import org.apache.commons.jelly.XMLOutput;
  +import org.apache.commons.jelly.impl.DynamicTagLibrary;
   
   import org.xml.sax.Attributes;
   import org.xml.sax.helpers.AttributesImpl;
  
  
  
  1.5       +0 -1      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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- StaticTagScript.java	1 Aug 2002 09:53:17 -0000	1.4
  +++ StaticTagScript.java	9 Aug 2002 17:26:40 -0000	1.5
  @@ -74,7 +74,6 @@
   import org.apache.commons.jelly.TagLibrary;
   import org.apache.commons.jelly.XMLOutput;
   import org.apache.commons.jelly.expression.Expression;
  -import org.apache.commons.jelly.tags.define.DynamicTagLibrary;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/BeanTag.java
  
  Index: BeanTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DynamicTag.java,v 1.7 2002/05/17 15:18:12 jstrachan Exp $
   * $Revision: 1.7 $
   * $Date: 2002/05/17 15:18:12 $
   *
   * ====================================================================
   *
   * 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: DynamicTag.java,v 1.7 2002/05/17 15:18:12 jstrachan Exp $
   */
  package org.apache.commons.jelly.impl;
  
  import java.lang.reflect.Method;
  import java.lang.reflect.InvocationTargetException;
  import java.util.Iterator;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Map;
  import java.util.Set;
  
  import org.apache.commons.beanutils.ConvertingWrapDynaBean;
  
  import org.apache.commons.collections.BeanMap;
  
  import org.apache.commons.jelly.DynaBeanTagSupport;
  import org.apache.commons.jelly.JellyContext;
  import org.apache.commons.jelly.JellyException;
  import org.apache.commons.jelly.MissingAttributeException;
  import org.apache.commons.jelly.Script;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.commons.jelly.expression.Expression;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /** 
   * This tag is bound onto a Java Bean class. When the tag is invoked a bean will be created
   * using the tags attributes. 
   * The bean may also have an invoke method called invoke(), run(), execute() or some such method
   * which will be invoked after the bean has been configured.</p>
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
   * @version $Revision: 1.7 $
   */
  public class BeanTag extends DynaBeanTagSupport {
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog(BeanTag.class);
  
      /** Empty arguments for Method.invoke() */
      private static final Object[] emptyArgs = {};
      
      /** the bean class */
      private Class beanClass;
      
      /** the current bean instance */
      private Object bean;
      
      /** the method to invoke on the bean */
      private Method method;    
  
      /** 
       * the tag attribute name that is used to declare the name 
       * of the variable to export after running this tag
       */
      private String variableNameAttribute;
  
      /** the current variable name that the bean should be exported as */
      private String var;
  
      /** the set of attribute names we've already set */
      private Set setAttributesSet = new HashSet();
  
      /** the attribute definitions */
      private Map attributes;    
          
      public BeanTag(Class beanClass, Map attributes, String variableNameAttribute, Method method) {
          this.beanClass = beanClass;
          this.method = method;
          this.attributes = attributes;
          this.variableNameAttribute = variableNameAttribute;
      }
  
      public void beforeSetAttributes() throws Exception {
          // create a new dynabean before the attributes are set
          bean = beanClass.newInstance();
          setDynaBean( new ConvertingWrapDynaBean( bean ) );
  
          setAttributesSet.clear();                    
      }
  
      public void setAttribute(String name, Object value) throws Exception {        
          boolean isVariableName = false;
          if (variableNameAttribute != null ) {
              if ( variableNameAttribute.equals( name ) ) {
                  if (value == null) {
                      var = null;
                  }
                  else {
                      var = value.toString();
                  }
                  isVariableName = true;
              }
          }
          if (! isVariableName) {
              
              // #### strictly speaking we could
              // know what attributes are specified at compile time
              // so this dynamic set is unnecessary            
              setAttributesSet.add(name);
              
              // we could maybe implement attribute specific validation here
              
              super.setAttribute(name, value);
          }
      }
  
      // Tag interface
      //-------------------------------------------------------------------------                    
      public void doTag(XMLOutput output) throws Exception {
  
          // lets find any attributes that are not set and 
          for ( Iterator iter = attributes.values().iterator(); iter.hasNext(); ) {
              Attribute attribute = (Attribute) iter.next();
              String name = attribute.getName();
              if ( ! setAttributesSet.contains( name ) ) {
                  if ( attribute.isRequired() ) {
                      throw new MissingAttributeException(name);
                  }
                  // lets get the default value
                  Object value = null;
                  Expression expression = attribute.getDefaultValue();
                  if ( expression != null ) {
                      value = expression.evaluate(context);
                  }
                  
                  // only set non-null values?
                  if ( value != null ) {
                      super.setAttribute(name, value);
                  }
              }
          }
          
          invokeBody(output);
  
          // export the bean if required
          if ( var != null ) {
              context.setVariable(var, bean);
          }
          
          // now, I may invoke the 'execute' method if I have one
          if ( method != null ) {
              try {
                  method.invoke( bean, emptyArgs );
              }
              catch (IllegalAccessException e) {
                  methodInvocationError(bean, method, e);
              }
              catch (IllegalArgumentException e) {
                  methodInvocationError(bean, method, e);
              }
              catch (InvocationTargetException e) {
                  // methodInvocationError(bean, method, e);
  
                  Throwable inner = e.getTargetException();
  
                  if ( inner instanceof Exception )
                  {
                      throw (Exception) inner;
                  }
                  else
                  {
                      throw new JellyException( inner );
                  }
              }
          }
      }
      
      /**
       * Report the state of the bean when method invocation fails
       * so that the user can determine any problems that might
       * be occuring while using dynamic jelly beans.
       *
       * @param bean Bean on which <code>method</code was invoked
       * @param method Method that was invoked
       * @param e Exception throw when <code>method</code> was invoked
       */
      private void methodInvocationError(Object bean, Method method, Exception e) throws Exception {
          log.error("Could not invoke " + method, e);
          BeanMap beanMap = new BeanMap(bean);
          
          log.error("Bean properties:");
          for (Iterator i = beanMap.keySet().iterator(); i.hasNext();) {
              String property = (String) i.next();
              Object value = beanMap.get(property);
              log.error(property + " -> " + value);
          }
          
          log.error(beanMap);
          throw e;
      }
      
      // Properties
      //-------------------------------------------------------------------------                    
      /**
       * @return the bean that has just been created 
       */
      public Object getBean() {
          return bean;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/Attribute.java
  
  Index: Attribute.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DynamicTag.java,v 1.7 2002/05/17 15:18:12 jstrachan Exp $
   * $Revision: 1.7 $
   * $Date: 2002/05/17 15:18:12 $
   *
   * ====================================================================
   *
   * 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: DynamicTag.java,v 1.7 2002/05/17 15:18:12 jstrachan Exp $
   */
  package org.apache.commons.jelly.impl;
  
  import org.apache.commons.jelly.expression.Expression;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /** 
   * Represents the attribute definition used by dynamic tags, such as whether the attribute is required
   * or any default values etc.
   * 
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.7 $
   */
  public class Attribute {
  
      /** the name of the attribute */
      private String name;
      
      /** the default value expression */
      private Expression defaultValue;
      
      /** whether this attribute is required */
      private boolean required;
      
      public Attribute() {
      }
  
      // Properties
      //-------------------------------------------------------------------------   
                       
      /**
       * Returns whether this attribute is required.
       * @return boolean
       */
      public boolean isRequired() {
          return required;
      }
  
      /**
       * Sets whether this attribute is required.
       * @param required is true if this attribute is a mandatory attribute
       */
      public void setRequired(boolean required) {
          this.required = required;
      }
  
      /**
       * Returns the name.
       * @return String
       */
      public String getName() {
          return name;
      }
  
      /**
       * Sets the name.
       * @param name The name to set
       */
      public void setName(String name) {
          this.name = name;
      }
  
      /**
       * Returns the defaultValue.
       * @return Expression
       */
      public Expression getDefaultValue() {
          return defaultValue;
      }
  
      /**
       * Sets the defaultValue.
       * @param defaultValue The defaultValue to set
       */
      public void setDefaultValue(Expression defaultValue) {
          this.defaultValue = defaultValue;
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/DynamicTagLibrary.java
  
  Index: DynamicTagLibrary.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DynamicTagLibrary.java,v 1.6 2002/08/01 09:53:18 jstrachan Exp $
   * $Revision: 1.6 $
   * $Date: 2002/08/01 09:53:18 $
   *
   * ====================================================================
   *
   * 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: DynamicTagLibrary.java,v 1.6 2002/08/01 09:53:18 jstrachan Exp $
   */
  package org.apache.commons.jelly.impl;
  
  import java.util.HashMap;
  import java.util.Map;
  
  import org.apache.commons.jelly.DynaTag;
  import org.apache.commons.jelly.Script;
  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;
  
  /** 
   * <p><code>DynamicTagLibrary</code> represents a TagLibrary which
   * gets created by running a Jelly script.</p>
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.6 $
   */
  public class DynamicTagLibrary extends TagLibrary {
  
      private String uri;
      private Map templates = new HashMap();
  
      public DynamicTagLibrary() {
      }
  
      public DynamicTagLibrary(String uri) {
          this.uri = uri;
      }
  
      /** Creates a new script to execute the given tag name and attributes */
      public TagScript createTagScript(final String name, Attributes attributes)
          throws Exception {
  
          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 */
      public Tag createTag(String name)
          throws Exception {
  
          Object value = templates.get(name);
          if ( value instanceof Script ) {            
              Script template = (Script) value;
              return new DynamicTag(template);
          }
          else if ( value instanceof TagFactory ) {
              TagFactory factory = (TagFactory) value;
              return factory.createTag();
          }
          return null;
      }
  
      /**
       * Creates a new tag with the given name and template 
       */
      public void registerDynamicTag(String name, Script template) {
          templates.put(name, template);
      }
  
      /**
       * Creates a new Jelly Bean Tag with the given name 
       */
      public void registerBeanTag(String name, TagFactory factory) {
          templates.put(name, factory);
      }
  
      // Properties
      //-------------------------------------------------------------------------     
      public String getUri() {
          return uri;
      }
  
      public void setUri(String uri) {
          this.uri = uri;
      }
  
      // Implementation methods
      //-------------------------------------------------------------------------     
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/DynamicTag.java
  
  Index: DynamicTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DynamicTag.java,v 1.10 2002/07/10 21:46:18 jvanzyl Exp $
   * $Revision: 1.10 $
   * $Date: 2002/07/10 21:46:18 $
   *
   * ====================================================================
   *
   * 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: DynamicTag.java,v 1.10 2002/07/10 21:46:18 jvanzyl Exp $
   */
  package org.apache.commons.jelly.impl;
  
  import java.util.HashMap;
  import java.util.Map;
  
  import org.apache.commons.jelly.JellyContext;
  import org.apache.commons.jelly.DynaTag;
  import org.apache.commons.jelly.Script;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /** 
   * <p><code>DynamicTag</code> is a tag that is created from
   * inside a Jelly script as a Jelly template and will invoke a 
   * given script, passing in its instantiation attributes 
   * as variables and will allow the template to invoke its instance body.</p>
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.10 $
   */
  public class DynamicTag extends TagSupport implements DynaTag {
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog(DynamicTag.class);
  
      /** The template script */
      private Script template;
  
      /** The instance attributes */
      private Map attributes = new HashMap();
  
      public DynamicTag() {
      }
  
      public DynamicTag(Script template) {
          this.template = template;
      }
  
  
      // Tag interface
      //-------------------------------------------------------------------------                    
      public void doTag(XMLOutput output) throws Exception {
          if ( log.isDebugEnabled() ) {
              log.debug("Invoking dynamic tag with attributes: " + attributes);
          }
          attributes.put("org.apache.commons.jelly.body", getBody());
          
          // create new context based on current attributes
          JellyContext newJellyContext = context.newJellyContext(attributes);
          getTemplate().run(newJellyContext, output);
      }
  
      // DynaTag interface
      //-------------------------------------------------------------------------                    
      public void setAttribute(String name, Object value) {
          attributes.put(name, value);
      }
  
      // Properties
      //-------------------------------------------------------------------------                    
      /** The template to be executed by this tag which may well 
       * invoke this instances body from inside the template
       */
      public Script getTemplate() {
          return template;
      }
  
      public void setTemplate(Script template) {
          this.template = template;
      }
  }
  
  
  
  1.6       +6 -6      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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- JeezTagLibrary.java	1 Aug 2002 09:53:18 -0000	1.5
  +++ JeezTagLibrary.java	9 Aug 2002 17:26:41 -0000	1.6
  @@ -74,10 +74,10 @@
   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.DynamicTagLibrary;
   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;
   // import org.apache.commons.jelly.tags.core.CoreTagLibrary;
   
  
  
  
  1.3       +1 -1      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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TagDefTag.java	1 Aug 2002 09:53:18 -0000	1.2
  +++ TagDefTag.java	9 Aug 2002 17:26:41 -0000	1.3
  @@ -63,8 +63,8 @@
   package org.apache.commons.jelly.tags.jeez;
   
   import org.apache.commons.jelly.JellyException;
  +import org.apache.commons.jelly.impl.DynamicTagLibrary;
   import org.apache.commons.jelly.tags.define.DefineTagTag;
  -import org.apache.commons.jelly.tags.define.DynamicTagLibrary;
   
   /** 
    * This tag defines a dynamic tag in Jelly script. When the tag is invoked
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>