commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml ParamTag.java TransformTag.java
Date Thu, 03 Oct 2002 18:14:44 GMT
jstrachan    2002/10/03 11:14:44

  Modified:    jelly/src/java/org/apache/commons/jelly/tags/swing
                        ConstraintTag.java SwingTagLibrary.java
               jelly/src/java/org/apache/commons/jelly/parser
                        XMLParser.java
               jelly/src/java/org/apache/commons/jelly/impl TagScript.java
                        StaticTagScript.java DynamicTagLibrary.java
               jelly/src/java/org/apache/commons/jelly/tags/jeez
                        JeezTagLibrary.java
               jelly/src/java/org/apache/commons/jelly/tags/ant
                        AntTagLibrary.java
               jelly/src/java/org/apache/commons/jelly/tags/xml
                        ParamTag.java TransformTag.java
  Removed:     jelly/src/java/org/apache/commons/jelly/impl
                        BeanTagScript.java DynaTagScript.java
  Log:
  Applied patches to merge TagScript, BeanTagScript and DynaTagScript together into a single
class.
  
  This makes the implementation much simpler, it allows tags to dynamically be created by
a TagLibrary that may be a bean Tag or a DyanTag.
  It also simplifies the job of keeping the Script implementations all thread safe.
  BeanTagScript was prematurely optimised which wasn't thread safe.
  
  Revision  Changes    Path
  1.2       +0 -1      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/swing/ConstraintTag.java
  
  Index: ConstraintTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/swing/ConstraintTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConstraintTag.java	25 Sep 2002 16:26:15 -0000	1.1
  +++ ConstraintTag.java	3 Oct 2002 18:14:43 -0000	1.2
  @@ -13,7 +13,6 @@
   import org.apache.commons.jelly.TagSupport;
   import org.apache.commons.jelly.TagLibrary;
   import org.apache.commons.jelly.impl.TagScript;
  -import org.apache.commons.jelly.impl.DynaTagScript;
   import org.apache.commons.jelly.impl.TagFactory;
   import org.apache.commons.jelly.tags.swing.converters.DimensionConverter;
   import org.apache.commons.jelly.tags.swing.converters.PointConverter;
  
  
  
  1.12      +1 -2      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/swing/SwingTagLibrary.java
  
  Index: SwingTagLibrary.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/swing/SwingTagLibrary.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- SwingTagLibrary.java	30 Sep 2002 17:52:27 -0000	1.11
  +++ SwingTagLibrary.java	3 Oct 2002 18:14:43 -0000	1.12
  @@ -73,7 +73,6 @@
   import org.apache.commons.jelly.Tag;
   import org.apache.commons.jelly.TagLibrary;
   import org.apache.commons.jelly.impl.TagScript;
  -import org.apache.commons.jelly.impl.DynaTagScript;
   import org.apache.commons.jelly.impl.TagFactory;
   import org.apache.commons.jelly.tags.swing.converters.DimensionConverter;
   import org.apache.commons.jelly.tags.swing.converters.PointConverter;
  @@ -146,7 +145,7 @@
           if ( answer == null ) {
               final Factory factory = getFactory( name );
               if ( factory != null ) {
  -                return new DynaTagScript(
  +                return new TagScript(
                       new TagFactory() {
                           public Tag createTag() throws Exception {
   							if ( factory instanceof TagFactory ) {
  
  
  
  1.30      +5 -6      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java
  
  Index: XMLParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- XMLParser.java	10 Sep 2002 18:20:51 -0000	1.29
  +++ XMLParser.java	3 Oct 2002 18:14:43 -0000	1.30
  @@ -89,7 +89,6 @@
   import org.apache.commons.jelly.impl.CompositeTextScriptBlock;
   import org.apache.commons.jelly.impl.ExpressionScript;
   import org.apache.commons.jelly.impl.StaticTag;
  -import org.apache.commons.jelly.impl.DynaTagScript;
   import org.apache.commons.jelly.impl.ScriptBlock;
   import org.apache.commons.jelly.impl.StaticTagScript;
   import org.apache.commons.jelly.impl.TagFactory;
  
  
  
  1.20      +86 -20    jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/TagScript.java
  
  Index: TagScript.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/TagScript.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- TagScript.java	19 Aug 2002 21:38:09 -0000	1.19
  +++ TagScript.java	3 Oct 2002 18:14:43 -0000	1.20
  @@ -73,7 +73,10 @@
   import java.util.List;
   import java.util.Map;
   
  +import org.apache.commons.beanutils.ConvertingWrapDynaBean;
   import org.apache.commons.beanutils.ConvertUtils;
  +import org.apache.commons.beanutils.DynaBean;
  +import org.apache.commons.beanutils.DynaProperty;
   
   import org.apache.commons.jelly.CompilableTag;
   import org.apache.commons.jelly.JellyContext;
  @@ -91,8 +94,7 @@
   import org.xml.sax.SAXException;
   
   /** 
  - * <p><code>TagScript</code> abstract base class for a 
  - * script that evaluates a custom tag.</p>
  + * <p><code>TagScript</code> is a Script that evaluates a custom tag.</p>
    * 
    * <b>Note</b> that this class should be re-entrant and used
    * concurrently by multiple threads.
  @@ -100,7 +102,7 @@
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision$
    */
  -public abstract class TagScript implements Script {
  +public class TagScript implements Script {
   
       /** The Log to which logging calls will be made. */
       private static final Log log = LogFactory.getLog(TagScript.class);
  @@ -148,11 +150,7 @@
        */
       public static TagScript newInstance(Class tagClass) {
           TagFactory factory = new DefaultTagFactory(tagClass);
  -        
  -        if ( DynaTag.class.isAssignableFrom(tagClass) ) {
  -            return new DynaTagScript(factory);
  -        }
  -        return new BeanTagScript(factory);
  +        return new TagScript(factory);
       }
       
       public TagScript() {
  @@ -207,6 +205,77 @@
           attributes.put(name, expression);
       }
       
  +    // Script interface
  +    //-------------------------------------------------------------------------       
        
  +
  +    /** Evaluates the body of a tag */
  +    public void run(JellyContext context, XMLOutput output) throws Exception {
  +        if ( ! context.isCacheTags() ) {
  +            clearTag();
  +        }
  +        try {
  +            Tag tag = getTag();
  +            if ( tag == null ) {
  +                return;
  +            }
  +            tag.setContext(context);
  +    
  +            if ( tag instanceof DynaTag ) {        
  +                DynaTag dynaTag = (DynaTag) tag;
  +        
  +                // ### probably compiling this to 2 arrays might be quicker and smaller
  +                for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();)
{
  +                    Map.Entry entry = (Map.Entry) iter.next();
  +                    String name = (String) entry.getKey();
  +                    Expression expression = (Expression) entry.getValue();
  +
  +                    Class type = dynaTag.getAttributeType(name);
  +                    Object value = null;        
  +                    if (type != null && type.isAssignableFrom(Expression.class)
&& !type.isAssignableFrom(Object.class)) {
  +                        value = expression;
  +                    }
  +                    else {
  +                        value = expression.evaluate(context);
  +                    }
  +                    dynaTag.setAttribute(name, value);
  +                }
  +            }
  +            else {
  +                // treat the tag as a bean
  +                DynaBean dynaBean = new ConvertingWrapDynaBean( tag );
  +                for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();)
{
  +                    Map.Entry entry = (Map.Entry) iter.next();
  +                    String name = (String) entry.getKey();
  +                    Expression expression = (Expression) entry.getValue();
  +
  +                    DynaProperty property = dynaBean.getDynaClass().getDynaProperty(name);
  +                    if (property == null) {
  +                        throw new JellyException("This tag does not understand the '" +
name + "' attribute" );
  +                    }
  +                    Class type = property.getType();
  +
  +                    Object value = null;        
  +                    if (type.isAssignableFrom(Expression.class) && !type.isAssignableFrom(Object.class))
{
  +                        value = expression;
  +                    }
  +                    else {
  +                        value = expression.evaluate(context);
  +                    }
  +                    dynaBean.set(name, value);
  +                }
  +            }
  +        
  +            tag.doTag(output);
  +        } 
  +        catch (JellyException e) {
  +            handleException(e);
  +        }
  +        catch (Exception e) {
  +            handleException(e);
  +        }
  +    }
  +    
  +    
       // Properties
       //-------------------------------------------------------------------------       
        
   
  @@ -456,22 +525,19 @@
        * Creates a new Jelly exception, adorning it with location information
        */
       protected JellyException createJellyException(String reason, Exception cause) {
  -        if ( cause instanceof JellyException )
  -        {
  +        if (cause instanceof JellyException) {
               return (JellyException) cause;
           }
   
  -        if ( cause instanceof InvocationTargetException)
  -        {
  -            return new JellyException( 
  +        if (cause instanceof InvocationTargetException) {
  +            return new JellyException(
                   reason,
  -                ((InvocationTargetException)cause).getTargetException(),
  +                ((InvocationTargetException) cause).getTargetException(),
                   fileName,
                   elementName,
                   columnNumber,
                   lineNumber);
           }
  -
           return new JellyException( 
               reason, cause, fileName, elementName, columnNumber, lineNumber
           );
  
  
  
  1.9       +1 -2      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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- StaticTagScript.java	13 Sep 2002 00:16:53 -0000	1.8
  +++ StaticTagScript.java	3 Oct 2002 18:14:43 -0000	1.9
  @@ -87,7 +87,7 @@
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision$
    */
  -public class StaticTagScript extends DynaTagScript {
  +public class StaticTagScript extends TagScript {
   
       /** The Log to which logging calls will be made. */
       private static final Log log = LogFactory.getLog(StaticTagScript.class);
  @@ -102,7 +102,6 @@
   
       // Script interface
       //-------------------------------------------------------------------------       
        
  -    /** Evaluates the body of a tag */
       public void run(JellyContext context, XMLOutput output) throws Exception {
   
           startNamespacePrefixes(output);
  
  
  
  1.4       +1 -4      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/DynamicTagLibrary.java
  
  Index: DynamicTagLibrary.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/DynamicTagLibrary.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DynamicTagLibrary.java	5 Sep 2002 16:43:29 -0000	1.3
  +++ DynamicTagLibrary.java	3 Oct 2002 18:14:43 -0000	1.4
  @@ -68,9 +68,6 @@
   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;
   
  @@ -98,7 +95,7 @@
       public TagScript createTagScript(final String name, final Attributes attributes)
           throws Exception {
   
  -        return new DynaTagScript(
  +        return new TagScript(
               new TagFactory() {
                   public Tag createTag() throws Exception {
                       Tag answer = DynamicTagLibrary.this.createTag(name);
  
  
  
  1.8       +8 -10     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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- JeezTagLibrary.java	27 Aug 2002 14:04:29 -0000	1.7
  +++ JeezTagLibrary.java	3 Oct 2002 18:14:43 -0000	1.8
  @@ -73,9 +73,7 @@
   import org.apache.commons.jelly.Script;
   import org.apache.commons.jelly.Tag;
   import org.apache.commons.jelly.TagLibrary;
  -import org.apache.commons.jelly.impl.BeanTagScript;
   import org.apache.commons.jelly.impl.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.werkz.WerkzTagLibrary;
  @@ -114,7 +112,7 @@
       ) throws Exception {
   
           if ( name.equals( "tagdef" ) ) {
  -            return new BeanTagScript(
  +            return new TagScript(
                   new TagFactory() {
                       public Tag createTag() {
                           return new TagDefTag( JeezTagLibrary.this );
  @@ -123,7 +121,7 @@
               );
           }
           if ( name.equals( "target" ) ) {
  -            return new BeanTagScript(
  +            return new TagScript(
                   new TagFactory() {
                       public Tag createTag() {
                           return new TargetTag();
  @@ -135,7 +133,7 @@
           if ( script == null ) {
               script = antTagLib.createCustomTagScript( name, attrs );
               if ( script == null ) {
  -                return new DynaTagScript(
  +                return new TagScript(
                       new TagFactory() {
                           public Tag createTag() throws Exception {
                               // lets try create a dynamic tag first
  
  
  
  1.23      +3 -5      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/AntTagLibrary.java
  
  Index: AntTagLibrary.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/AntTagLibrary.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- AntTagLibrary.java	24 Sep 2002 16:49:40 -0000	1.22
  +++ AntTagLibrary.java	3 Oct 2002 18:14:44 -0000	1.23
  @@ -67,8 +67,6 @@
   import org.apache.commons.jelly.JellyContext;
   import org.apache.commons.jelly.Tag;
   import org.apache.commons.jelly.TagLibrary;
  -import org.apache.commons.jelly.impl.BeanTagScript;
  -import org.apache.commons.jelly.impl.DynaTagScript;
   import org.apache.commons.jelly.impl.TagFactory;
   import org.apache.commons.jelly.impl.TagScript;
   import org.apache.commons.logging.Log;
  @@ -189,7 +187,7 @@
   
           TagScript answer = createCustomTagScript(name, attributes);
           if ( answer == null ) {
  -            answer = new DynaTagScript(
  +            answer = new TagScript(
                   new TagFactory() {
                       public Tag createTag() throws Exception {
                           return AntTagLibrary.this.createTag(name);
  @@ -206,7 +204,7 @@
       public TagScript createCustomTagScript(final String name, Attributes attributes) throws
Exception {
           // custom Ant tags
           if ( name.equals("fileScanner") ) {      
  -            return new BeanTagScript(
  +            return new TagScript(
                   new TagFactory() {
                       public Tag createTag() throws Exception {
                           return new FileScannerTag(new FileScanner());
  @@ -215,7 +213,7 @@
               );      
           }
           if ( name.equals("setProperty") ) {      
  -            return new BeanTagScript(
  +            return new TagScript(
                   new TagFactory() {
                       public Tag createTag() throws Exception {
                           return new SetPropertyTag();
  
  
  
  1.2       +5 -2      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/ParamTag.java
  
  Index: ParamTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/ParamTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ParamTag.java	30 Sep 2002 08:05:45 -0000	1.1
  +++ ParamTag.java	3 Oct 2002 18:14:44 -0000	1.2
  @@ -91,8 +91,11 @@
               throw new JellyException( "<param> tag must be enclosed inside a <transform>
tag" );
           }
           Object value = this.getValue();
  -        tag.setParameterValue( this.getName(),
  -                               (null == value ? this.getBodyText(): value));
  +        if (value == null) { 
  +            value = getBodyText();
  +        }
  +
  +        tag.setParameterValue( getName(), value );
       }
   
       // Properties
  
  
  
  1.4       +3 -3      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/TransformTag.java
  
  Index: TransformTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/TransformTag.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TransformTag.java	30 Sep 2002 08:05:45 -0000	1.3
  +++ TransformTag.java	3 Oct 2002 18:14:44 -0000	1.4
  @@ -86,7 +86,7 @@
   import org.apache.commons.jelly.XMLOutput;
   import org.apache.commons.jelly.impl.ScriptBlock;
   import org.apache.commons.jelly.impl.StaticTagScript;
  -import org.apache.commons.jelly.impl.BeanTagScript;
  +import org.apache.commons.jelly.impl.TagScript;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.dom4j.Document;
  @@ -379,8 +379,8 @@
               List scriptList = scriptBlock.getScriptList();
               for (Iterator iter = scriptList.iterator(); iter.hasNext(); ) {
                   Script script = (Script) iter.next();
  -                if (script instanceof BeanTagScript) {
  -                    Tag tag = ((BeanTagScript) script).getTag();
  +                if (script instanceof TagScript) {
  +                    Tag tag = ((TagScript) script).getTag();
                       if (tag instanceof ParamTag) {
                           script.run(context, output);
                       }
  
  
  

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


Mime
View raw message