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/06/05 09:12:58 UTC

cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant TaskPropertyTag.java AntTagLibrary.java DataTypeTag.java

jstrachan    2002/06/05 00:12:58

  Modified:    jelly/src/java/org/apache/commons/jelly/tags/ant
                        TaskPropertyTag.java AntTagLibrary.java
                        DataTypeTag.java
  Log:
  Added the registration of some beanutils Converters for standard Ant type coercions, like File and Reference, and removed the temporary hacks in the setAttribute() methods.
  So now coercions should work cleanly in Ant tasks. This should certainly fix bob's coercion problem he found when using <ant:property file="foo.properties"/>
  
  Revision  Changes    Path
  1.4       +0 -12     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/TaskPropertyTag.java
  
  Index: TaskPropertyTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/TaskPropertyTag.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TaskPropertyTag.java	4 Jun 2002 18:57:01 -0000	1.3
  +++ TaskPropertyTag.java	5 Jun 2002 07:12:58 -0000	1.4
  @@ -78,7 +78,6 @@
   import org.apache.tools.ant.Project;
   import org.apache.tools.ant.Task;
   import org.apache.tools.ant.types.DataType;
  -import org.apache.tools.ant.types.Reference;
   
   /** 
    * A tag which configures a property bean of a Task, 
  @@ -100,17 +99,6 @@
   
       public TaskPropertyTag(String name) {
           setName(name);
  -    }
  -
  -    // DynaTag interface
  -    //------------------------------------------------------------------------- 
  -    public void setAttribute(String name, Object value) {
  -        if ( name.equals( "refid" ) ) {
  -            if ( value instanceof String ) {
  -                value = new Reference( (String) value );
  -            }
  -        }
  -        super.setAttribute(name, value);
       }
   
       // CompilableTag interface
  
  
  
  1.4       +41 -0     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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AntTagLibrary.java	2 Jun 2002 17:29:02 -0000	1.3
  +++ AntTagLibrary.java	5 Jun 2002 07:12:58 -0000	1.4
  @@ -61,9 +61,13 @@
    */
   package org.apache.commons.jelly.tags.ant;
   
  +import java.io.File;
   import java.util.Iterator;
   import java.util.List;
   
  +import org.apache.commons.beanutils.Converter;
  +import org.apache.commons.beanutils.ConvertUtils;
  +
   import org.apache.commons.jelly.JellyContext;
   import org.apache.commons.jelly.JellyException;
   import org.apache.commons.jelly.Script;
  @@ -77,6 +81,7 @@
   import org.apache.tools.ant.Project;
   import org.apache.tools.ant.Task;
   import org.apache.tools.ant.types.DataType;
  +import org.apache.tools.ant.types.Reference;
   
   import org.xml.sax.Attributes;
   
  @@ -93,7 +98,43 @@
       
       /** the Ant Project for this tag library */
       private Project project;
  +
  +    static {
  +
  +        // register standard converters for Ant types
  +               
  +        ConvertUtils.register(
  +            new Converter() {
  +                public Object convert(Class type, Object value) {
  +                    if ( value instanceof File ) {
  +                        return (File) value;
  +                    }
  +                    else if ( value != null ) {
  +                        String text = value.toString();
  +                        return new File( text );
  +                    }
  +                    return null;
  +                }
  +            },
  +            File.class
  +        );
           
  +        ConvertUtils.register(
  +            new Converter() {
  +                public Object convert(Class type, Object value) {
  +                    if ( value instanceof Reference ) {
  +                        return (Reference) value;
  +                    }
  +                    else if ( value != null ) {
  +                        String text = value.toString();
  +                        return new Reference( text );
  +                    }
  +                    return null;
  +                }
  +            },
  +            Reference.class
  +        );
  +    }        
           
       public AntTagLibrary() {
       }
  
  
  
  1.5       +0 -15     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/DataTypeTag.java
  
  Index: DataTypeTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/DataTypeTag.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DataTypeTag.java	2 Jun 2002 17:29:02 -0000	1.4
  +++ DataTypeTag.java	5 Jun 2002 07:12:58 -0000	1.5
  @@ -61,7 +61,6 @@
    */
   package org.apache.commons.jelly.tags.ant;
   
  -import java.io.File;
   import java.lang.reflect.Method;
   
   import org.apache.commons.beanutils.ConvertingWrapDynaBean;
  @@ -99,20 +98,6 @@
           this.dataType = dataType;
           setDynaBean( new ConvertingWrapDynaBean(dataType) );
       }
  -    
  -    // DynaTag interface
  -    //------------------------------------------------------------------------- 
  -    public void setAttribute(String name, Object value) {
  -        if ( name.equals( "dir" ) ) {
  -            // ### this is a hack - we should install some standard converters
  -            // ### for Reference and File types
  -            if ( value instanceof String ) {
  -                value = new File( (String) value );
  -            }
  -        }
  -        super.setAttribute(name, value);
  -    }
  -
   
       // Tag interface
       //------------------------------------------------------------------------- 
  
  
  

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