ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erik Hatcher" <jakarta-...@ehatchersolutions.com>
Subject Re: Proxy support in Ant
Date Thu, 02 May 2002 18:42:31 GMT
Have a look at the new DynamicConfigurator interface in Ant 1.5's API.  It
will likely be the answer the problem you're trying to solve - if your goal
is to support dynamic elements and attributes, that is.

    Erik


----- Original Message -----
From: "Fran├žois Wolff" <ejen@noos.fr>
To: <ant-dev@jakarta.apache.org>
Sent: Thursday, May 02, 2002 12:56 PM
Subject: Proxy support in Ant


>   Hello,
>
> I'm the developer of Ejen <http://ejen.sourceforge.net>, a Java/XSLT
> based code generation system. Next release of this system implements an
> Ant task that uses
> java.lang.reflect.Proxy/java.lang.reflect.InvocationHandler classes for
> sub-node creation.
>
> For example, there is this kind of declaration:
>
> public class Ejen extends Task (...) {
>     ...
>     public Source createSource() {
>         return
(Source)(Proxy.newProxyInstance(Source.class.getClassLoader(),
>                        new Class[] { Source.class },
>                        new NodeInvocationHandler(...)));
>     }
>     ...
> }
>
> with,
>
> public interface Source {
>     public void setUri(String uri);
> }
>
> NodeInvocationHandler implementation doesn't matter here...
>
> With this kind of build file:
>
> ...
> <taskdef name="ejen" classname="org.ejen.ant.Ejen"/>
>
> <target name="ejen-target">
>   <ejen>
>     <source badattr="..."/>
>     ...
>   </ejen>
> </target>
> ...
>
> I get the following error:
>
> ...: Class $Proxy0 doesn't support the "badattr" attribute.
>
> I would prefer of course:
>
> ...: Class Source doesn't support the "badattr" attribute.
>
> I wrote a patch for the org.apache.tools.ant.IntrospectionHelper class
> (getElementName method) with this code (for Ant 1.4.1 release):
>
> ...
> // New --------------------------------------------------------
> Class eltClass = element.getClass();
> if (java.lang.reflect.Proxy.isProxyClass(eltClass))
> {
>     Class[] interfaces = eltClass.getInterfaces();
>     if (interfaces.length == 1)
>         return "Class " + interfaces[0].getName();
>     else if (interfaces.length > 1)
>     {
>         StringBuffer sb = new StringBuffer("Classes ");
>         for (int i = 0; i < interfaces.length; i++) {
>             if (i > 0)
>                 sb.append(", ");
>             sb.append(interfaces[i].getName());
>         }
>         return sb.toString();
>     }
> }
> return "Class " + eltClass.getName();
> // -------------------------------------------------------- New
>
> /* Old --------------------------------------------------------
> return "Class " + element.getClass().getName();
> -------------------------------------------------------- Old */
> ...
>
> Error message is then correct.
>
> The patch is included as an attachment. I have written also a patch for
> the next 1.5 release of Ant (based on the org.apache.tools.ant.Project
> class, revision 1.108). I think it could be very interesting to add
> Proxy support in the next release of Ant, because use of Proxys can be
> very useful when adapting existing API to specific Ant constraints
> (create..., set...).
>
> Thanks a lot for the excellent Ant,
> F. Wolff.
>
>


----------------------------------------------------------------------------
----


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


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


Mime
View raw message