commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wer...@apache.org
Subject cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant AntTagLibrary.java AntTagSupport.java IntrospectionHelper.java OtherAntTag.java TaskTag.java
Date Tue, 25 Jun 2002 20:43:31 GMT
werken      2002/06/25 13:43:31

  Modified:    jelly/src/java/org/apache/commons/jelly/tags/ant
                        AntTagLibrary.java AntTagSupport.java
                        IntrospectionHelper.java OtherAntTag.java
                        TaskTag.java
  Log:
  Partial migration of all ant datatypes to OtherAntTag.
  
  Revision  Changes    Path
  1.14      +2 -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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- AntTagLibrary.java	19 Jun 2002 17:14:01 -0000	1.13
  +++ AntTagLibrary.java	25 Jun 2002 20:43:30 -0000	1.14
  @@ -229,6 +229,7 @@
               return TagScript.newInstance(tag);
           }
           
  +        /*
           // an Ant DataType?
           DataType dataType = null;
           type = (Class) project.getDataTypeDefinitions().get(name);
  @@ -266,6 +267,7 @@
               tag.getDynaBean().set( "project", project );
               return TagScript.newInstance(tag);
           }
  +        */
           
           // Since ant resolves so many dynamically loaded/created
           // things at run-time, we can make virtually no assumptions
  
  
  
  1.4       +57 -12    jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/AntTagSupport.java
  
  Index: AntTagSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/AntTagSupport.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AntTagSupport.java	25 Jun 2002 18:00:09 -0000	1.3
  +++ AntTagSupport.java	25 Jun 2002 20:43:30 -0000	1.4
  @@ -93,17 +93,63 @@
   
       public Object createNestedObject(String name) throws Exception {
   
  +        Object dataType = null;
  +            
           Object object = getObject();
   
  -        IntrospectionHelper ih = IntrospectionHelper.getHelper( object.getClass() );
  +        if ( object != null )
  +        {
  +            IntrospectionHelper ih = IntrospectionHelper.getHelper( object.getClass() );
  +            
  +            if ( ih != null ) {
  +                try {
  +                    dataType = ih.createElement( getAntProject(), object, name );
  +                } catch (Exception e) {
  +                    dataType = null;
  +                    e.printStackTrace();
  +                }
  +            }
  +        }
  +
  +        if ( dataType == null ) {
  +            dataType = createDataType( name );
  +        }
  +
  +        return dataType;
  +    }
   
  +    public Object createDataType(String name) throws Exception {
  +        
           Object dataType = null;
   
  -        try {
  -            dataType = ih.createElement( getAntProject(), object, name );
  -        } catch (Exception e) {
  -            dataType = null;
  -            e.printStackTrace();
  +        Class type = (Class) getAntProject().getDataTypeDefinitions().get(name);
  +
  +        if ( type != null ) {            
  +            
  +            try {
  +                java.lang.reflect.Constructor ctor = null;
  +                boolean noArg = false;
  +                // DataType can have a "no arg" constructor or take a single 
  +                // Project argument.
  +                try {
  +                    ctor = type.getConstructor(new Class[0]);
  +                    noArg = true;
  +                } catch (NoSuchMethodException nse) {
  +                    ctor = type.getConstructor(new Class[] { Project.class });
  +                    noArg = false;
  +                }
  +                
  +                if (noArg) {
  +                    dataType = (DataType) ctor.newInstance(new Object[0]);
  +                } else {
  +                    dataType = (DataType) ctor.newInstance(new Object[] {project});
  +                }
  +                ((DataType)dataType).setProject( project );
  +                
  +            } catch (Throwable t) {
  +                t.printStackTrace();
  +                // ignore 
  +            }
           }
   
           return dataType;
  @@ -158,14 +204,13 @@
                   ih.setAttribute( getAntProject(), obj, name.toLowerCase(), (String) value
);
                   return;
               } catch (Exception e) {
  -                // e.printStackTrace();
  +                e.printStackTrace();
               }
           }
   
           try {
               ih.storeElement( getAntProject(), obj, value, name );
           } catch (Exception e) {
  -            // e.printStackTrace();
   
               // let any exceptions bubble up from here
               
  
  
  
  1.2       +1 -1      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/IntrospectionHelper.java
  
  Index: IntrospectionHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/IntrospectionHelper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- IntrospectionHelper.java	18 Jun 2002 18:36:43 -0000	1.1
  +++ IntrospectionHelper.java	25 Jun 2002 20:43:30 -0000	1.2
  @@ -322,7 +322,7 @@
           NestedCreator nc = (NestedCreator) nestedCreators.get(elementName);
           if (nc == null) {
   	    String msg = getElementName(project, element) +
  -            //String msg = "Class " + element.getClass().getName() +
  +            // String msg = "Class " + element.getClass().getName() +
                   " doesn't support the nested \"" + elementName + "\" element.";
               throw new BuildException(msg);
           }
  
  
  
  1.3       +58 -17    jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/OtherAntTag.java
  
  Index: OtherAntTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/OtherAntTag.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- OtherAntTag.java	25 Jun 2002 16:21:54 -0000	1.2
  +++ OtherAntTag.java	25 Jun 2002 20:43:30 -0000	1.3
  @@ -13,6 +13,7 @@
   import org.apache.tools.ant.Task;
   import org.apache.tools.ant.TaskAdapter;
   import org.apache.tools.ant.types.DataType;
  +import org.apache.tools.ant.types.Reference;
   
   import java.lang.reflect.Method;
   
  @@ -71,21 +72,29 @@
               this.task.perform(); 
           } else {
               getBody().run( context, output );
  -            AntTagSupport parent = (AntTagSupport) findAncestorWithClass(AntTagSupport.class);
  -            
  -            Object parentObj =  parent.getObject();
  -            
  -            IntrospectionHelper ih = IntrospectionHelper.getHelper( parentObj.getClass()
);
   
  -            try
  -            {
  -                ih.storeElement( getAntProject(),
  -                                 parentObj,
  -                                 getObject(),
  -                                 getTagName() );
  -            }
  -            catch (Exception e) {
  +            AntTagSupport parent = (AntTagSupport) findAncestorWithClass(AntTagSupport.class);
   
  +            if ( parent != null ) {
  +                // otherwise it -must- be a top-level, non-parented datatype.
  +                
  +                Object parentObj =  parent.getObject();
  +                
  +                if ( parentObj != null )
  +                {
  +                    IntrospectionHelper ih = IntrospectionHelper.getHelper( parentObj.getClass()
);
  +                    
  +                    try
  +                    {
  +                        ih.storeElement( getAntProject(),
  +                                         parentObj,
  +                                         getObject(),
  +                                         getTagName() );
  +                    }
  +                    catch (Exception e) {
  +                        
  +                    }
  +                }
               }
           }
       }
  @@ -128,14 +137,20 @@
               return;
               
           } else {
  +            // must be a datatype.
  +
               AntTagSupport ancestor = (AntTagSupport) findAncestorWithClass( AntTagSupport.class
);
  +
  +            Object nested = null;
               
  -            if ( ancestor == null ) {
  -                return;
  +            if ( ancestor != null ) {
  +                nested = ancestor.createNestedObject( getTagName() );
               }
               
  -            Object nested = ancestor.createNestedObject( getTagName() );
  -            
  +            if ( nested == null ) {
  +                nested = createDataType( getTagName() );
  +            }
  +
               if ( nested != null ) {
                   setObject( nested );
   
  @@ -149,6 +164,32 @@
               } 
           }
       }
  +
  +    public void setAttribute(String name, Object value) throws Exception {
  +
  +        if ( "id".equals( name ) ) {
  +            try
  +            {
  +                Object obj = getObject();
  +
  +                getAntProject().addReference( (String) value, getObject() );
  +            }
  +            catch (Exception e)
  +            {
  +                e.printStackTrace();
  +                // ignore?
  +            }
  +            return;
  +        }
  +        
  +        super.setAttribute( name, value );
  +    }
  +
  +    public String toString()
  +    {
  +        return "[OtherAntTag: name=" + getTagName() + "]";
  +    }
  +    
   }
   
       
  
  
  
  1.12      +0 -12     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/TaskTag.java
  
  Index: TaskTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/TaskTag.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- TaskTag.java	18 Jun 2002 18:36:43 -0000	1.11
  +++ TaskTag.java	25 Jun 2002 20:43:30 -0000	1.12
  @@ -160,18 +160,6 @@
           task.perform();   
       }
   
  -    // DataTypeCreator interface
  -    //------------------------------------------------------------------------- 
  -
  -    public DataType createDataType(String name) throws Exception {
  -
  -        IntrospectionHelper helper = IntrospectionHelper.getHelper( getTask().getClass()
);
  -
  -        return (DataType) helper.createElement( getAntProject(),
  -                                                getTask(),
  -                                                name );
  -    }
  -
       
       // TaskSource interface
       //------------------------------------------------------------------------- 
  
  
  

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