ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant IntrospectionHelper.java ProjectHelper.java RuntimeConfigurable.java Task.java
Date Wed, 01 Aug 2001 11:41:15 GMT
conor       01/08/01 04:41:15

  Modified:    src/main/org/apache/tools/ant IntrospectionHelper.java
                        ProjectHelper.java RuntimeConfigurable.java
                        Task.java
  Log:
  New Introspection capability. Methods which have the signature
  addConfiguredXXX will be called for nested elements named XXX
  but will be called only once the XXX object has been configured
  
  Revision  Changes    Path
  1.19      +75 -1     jakarta-ant/src/main/org/apache/tools/ant/IntrospectionHelper.java
  
  Index: IntrospectionHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/IntrospectionHelper.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- IntrospectionHelper.java	2001/07/26 07:51:28	1.18
  +++ IntrospectionHelper.java	2001/08/01 11:41:15	1.19
  @@ -91,6 +91,11 @@
       private Hashtable nestedCreators;
   
       /**
  +     * Holds methods to store configured nested elements.
  +     */
  +    private Hashtable nestedStorers;
  +
  +    /**
        * The method to add PCDATA stuff.
        */
       private Method addText = null;
  @@ -110,6 +115,8 @@
           attributeSetters = new Hashtable();
           nestedTypes = new Hashtable();
           nestedCreators = new Hashtable();
  +        nestedStorers = new Hashtable();
  +        
           this.bean = bean;
   
           Method[] methods = bean.getMethods();
  @@ -177,6 +184,39 @@
   
                       });
                   
  +            } else if (name.startsWith("addConfigured")
  +                       && java.lang.Void.TYPE.equals(returnType)
  +                       && args.length == 1
  +                       && !java.lang.String.class.equals(args[0])
  +                       && !args[0].isArray()
  +                       && !args[0].isPrimitive()) {
  +                 
  +                try {
  +                    final Constructor c = 
  +                        args[0].getConstructor(new Class[] {});
  +                    String propName = getPropertyName(name, "addConfigured");
  +                    nestedTypes.put(propName, args[0]);
  +                    nestedCreators.put(propName, new NestedCreator() {
  +
  +                            public Object create(Object parent) 
  +                                throws InvocationTargetException, IllegalAccessException,
InstantiationException {
  +                                
  +                                Object o = c.newInstance(new Object[] {});
  +                                return o;
  +                            }
  +
  +                        });
  +                    nestedStorers.put(propName, new NestedStorer() {
  +
  +                            public void store(Object parent, Object child) 
  +                                throws InvocationTargetException, IllegalAccessException,
InstantiationException {
  +                                
  +                                m.invoke(parent, new Object[] {child});
  +                            }
  +
  +                        });
  +                } catch (NoSuchMethodException nse) {
  +                }
               } else if (name.startsWith("add")
                          && java.lang.Void.TYPE.equals(returnType)
                          && args.length == 1
  @@ -202,7 +242,6 @@
                           });
                   } catch (NoSuchMethodException nse) {
                   }
  -                    
               }
           }
       }
  @@ -300,6 +339,35 @@
       }
   
       /**
  +     * Creates a named nested element.
  +     */
  +    public void storeElement(Project project, Object element, Object child, String elementName)

  +        throws BuildException {
  +        if (elementName == null) {
  +            return;
  +        }
  +        NestedStorer ns = (NestedStorer)nestedStorers.get(elementName);
  +        if (ns == null) {
  +            return;
  +        }
  +        try {
  +            ns.store(element, child);
  +        } catch (IllegalAccessException ie) {
  +            // impossible as getMethods should only return public methods
  +            throw new BuildException(ie);
  +        } catch (InstantiationException ine) {
  +            // impossible as getMethods should only return public methods
  +            throw new BuildException(ine);
  +        } catch (InvocationTargetException ite) {
  +            Throwable t = ite.getTargetException();
  +            if (t instanceof BuildException) {
  +                throw (BuildException) t;
  +            }
  +            throw new BuildException(t);
  +        }
  +    }
  +
  +    /**
        * returns the type of a named nested element.
        */
       public Class getElementType(String elementName) 
  @@ -555,6 +623,12 @@
           public Object create(Object parent) 
               throws InvocationTargetException, IllegalAccessException, InstantiationException;
       }
  +    
  +    private interface NestedStorer {
  +        public void store(Object parent, Object child) 
  +            throws InvocationTargetException, IllegalAccessException, InstantiationException;
  +    }
  +    
       private interface AttributeSetter {
           public void set(Project p, Object parent, String value)
               throws InvocationTargetException, IllegalAccessException, 
  
  
  
  1.58      +11 -3     jakarta-ant/src/main/org/apache/tools/ant/ProjectHelper.java
  
  Index: ProjectHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/ProjectHelper.java,v
  retrieving revision 1.57
  retrieving revision 1.58
  diff -u -r1.57 -r1.58
  --- ProjectHelper.java	2001/07/23 16:31:56	1.57
  +++ ProjectHelper.java	2001/08/01 11:41:15	1.58
  @@ -552,11 +552,12 @@
                   configureId(child, attrs);
   
                   if (parentWrapper != null) {
  -                    childWrapper = new RuntimeConfigurable(child);
  +                    childWrapper = new RuntimeConfigurable(child, propType);
                       childWrapper.setAttributes(attrs);
                       parentWrapper.addChild(childWrapper);
                   } else {
                       configure(child, attrs, project);
  +                    ih.storeElement(project, parent, child, propType.toLowerCase());
                   }
               } catch (BuildException exc) {
                   throw new SAXParseException(exc.getMessage(), locator, exc);
  @@ -612,7 +613,7 @@
                   }
                   
                   if (target != null) {
  -                    wrapper = new RuntimeConfigurable(element);
  +                    wrapper = new RuntimeConfigurable(element, propType);
                       wrapper.setAttributes(attrs);
                       target.addDataType(wrapper);
                   } else {
  @@ -688,7 +689,14 @@
           IntrospectionHelper.getHelper(target.getClass()).addText(project, target, text);
       }
   
  -
  +    /**
  +     * Stores a configured child element into its parent object 
  +     */
  +    public static void storeChild(Project project, Object parent, Object child, String
tag) {
  +        IntrospectionHelper ih = IntrospectionHelper.getHelper(parent.getClass());
  +        ih.storeElement(project, parent, child, tag);
  +    }
  +    
       /**
        * Replace ${} style constructions in the given value with the string value of
        * the corresponding data types.
  
  
  
  1.8       +9 -1      jakarta-ant/src/main/org/apache/tools/ant/RuntimeConfigurable.java
  
  Index: RuntimeConfigurable.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/RuntimeConfigurable.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- RuntimeConfigurable.java	2001/07/23 03:56:12	1.7
  +++ RuntimeConfigurable.java	2001/08/01 11:41:15	1.8
  @@ -68,6 +68,7 @@
    */
   public class RuntimeConfigurable {
   
  +    private String elementTag = null;
       private Vector children = new Vector();
       private Object wrappedObject = null;
       private AttributeList attributes;
  @@ -76,8 +77,9 @@
       /**
        * @param proxy The element to wrap.
        */
  -    public RuntimeConfigurable(Object proxy) {
  +    public RuntimeConfigurable(Object proxy, String elementTag) {
           wrappedObject = proxy;
  +        this.elementTag = elementTag;
       }
   
       void setProxy(Object proxy) {
  @@ -126,6 +128,11 @@
           addText(new String(buf, start, end));
       }
   
  +    public String getElementTag() {
  +        return elementTag;
  +    }
  +    
  +    
       /**
        * Configure the wrapped element and all children.
        */
  @@ -145,6 +152,7 @@
           while (enum.hasMoreElements()) {
               RuntimeConfigurable child = (RuntimeConfigurable) enum.nextElement();
               child.maybeConfigure(p);
  +            ProjectHelper.storeChild(p, wrappedObject, child.wrappedObject, child.getElementTag().toLowerCase());
           }
   
           if (id != null) {
  
  
  
  1.20      +1 -1      jakarta-ant/src/main/org/apache/tools/ant/Task.java
  
  Index: Task.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Task.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- Task.java	2001/07/22 13:12:28	1.19
  +++ Task.java	2001/08/01 11:41:15	1.20
  @@ -203,7 +203,7 @@
        */
       public RuntimeConfigurable getRuntimeConfigurableWrapper() {
           if (wrapper == null) {
  -            wrapper = new RuntimeConfigurable(this);
  +            wrapper = new RuntimeConfigurable(this, getTaskName());
           }
           return wrapper;
       }
  
  
  

Mime
View raw message