ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Reilly <peter.rei...@corvil.com>
Subject Re: DynamicConfigurator namespace problem
Date Tue, 16 Dec 2003 20:04:16 GMT
Stefan Bodewig wrote:

>On Fri, 12 Dec 2003, Christopher Lenz <cmlenz@gmx.de> wrote:
>
>  
>
>>public class DynamicConfiguratorNS {
>>    
>>
>
>looks fine to me.
>
>  
>
>>I don't think this interface should extend DynamicConfigurator.
>>    
>>
>
>Same here.
>
>I'd also like Ant to pass element and attribute names in as they are,
>i.e. without changing their case in any way.
>  
>
I have code for this, however I am uneasy about placing it
it ANT for 1.6, without a new beta release.

The interface is:

public interface DynamicConfiguratorNS {
    void setDynamicAttribute(String uri, String qualifiedName,
                             String value)
            throws BuildException;
    Object createDynamicElement(
        String uri, String localName) throws BuildException;
}


The prefix is not set. - It is possible to get it for the element
but not (without more major changes) for the attributes.

One issue with the patch is that if the namespace of
the attribute is the same as the element, the namespace URI
is replaced with a "".

For an example:

public class DTest2 extends Task implements DynamicConfiguratorNS {
    public Object createDynamicElement(
        String uri,
        String localName) {
        System.out.println("Element  {" + uri  +", " + localName + "}");
        return new DTest2();
    }
    public void setDynamicAttribute(
        String uri,
        String localName,
        String value) {
        System.out.println("Attribute {" + uri  +", " + localName + "}");
    }
}

    <dtest x="b" ant:b="b"  xmlns:ant="antlib:org.apache.tools.ant"/>
will print:
Attribute {, x}
Attribute {antlib:org.apache.tools.ant, b}

and
    <dtest x="b" ant:b="b"  xmlns:ant="antlib:org.apache.tools.ant"
           xmlns="antlib:org.apache.tools.ant"/>
will print
Attribute {, x}
Attribute {, b}

Another Namespace issue is the handling of the ant core uri by the
code. Currently the code sets this to "" at an early stage.
It however should be retained in the system (ie. whether
the namespace URI of an element  is "" or "antlib:org.apache.tools.ant").


For ant 1.6 (and beyond) we can make macrodef namespace  independent, 
without
this patch.

So for example:

    <macrodef name="example">
      <element name="element"/>
      <sequential>
        <element/>
      </sequential>
    </macrodef>

In a antlib  referred to by a namespace prefix x, the following
would work:

<x:example>
   <x:element>
      <echo>Hello world</echo>
   </x:element>
</x:example>


And the following would work:

<x:example>
   <element>
      <echo>Hello world</echo>
   </element>
</x:example>

Peter

Mime
View raw message