Problem Reusing Condition API

View: New views
5 Messages — Rating Filter:   Alert me  

Problem Reusing Condition API

by Mithun Gonsalvez :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi All,

I have a small problem (hopefully):

I am trying to extend MacroDef to aggregate certain arguments depending upon
conditions.

*Ant-File:*
<?xml version="1.0" encoding="UTF-8"?>
<project name="ExtensionTester" default="default" basedir=".">

    <taskdef name="anotherTezt" classname="myownpackage.TestCheck"/>
    <anotherTezt name="Test">
        <MainArgument>
            <MySingleArgument>
                <equals arg1="MyName"  arg2="MyName"
 casesensitive="false"/>
                <equals arg1="MyName2" arg2="MyName2"
casesensitive="false"/>
            </MySingleArgument>
            <!-- More MySingleArgument's can come here -->
        </MainArgument>
        <!-- More MainArgument's can come here -->
    </anotherTezt>

    <target name="default" >
        <anotherTezt/>
    </target>
</project>


*Extension Code:*
package myownpackage;

import java.util.ArrayList;
import java.util.List;
import org.apache.tools.ant.taskdefs.MacroDef;
import org.apache.tools.ant.taskdefs.condition.Condition;

public class TestCheck extends MacroDef {

    public static class MySingleArgument {

        List<Condition> conditions = new ArrayList<Condition>();

        public void addConfiguredCondition(Condition condition) {
            this.conditions.add(condition);
        }

//        .... More code here to set other values ....
    }

    public static class MainArgument {

        private List<MySingleArgument> singularArguments = new
ArrayList<MySingleArgument>();

        public void addConfiguredMySingleArgument(MySingleArgument
singularArgument) {
            this.singularArguments.add(singularArgument);
        }

//        .... More code here to set other values ....
    }

    private List<MainArgument> allArguments = new ArrayList<MainArgument>();

    @Override
    public void execute() {
        for (MainArgument arg : allArguments) {
            for (MySingleArgument singleArg : arg.singularArguments) {
                for (Condition condition : singleArg.conditions) {
                    if (condition.eval()) {
                        // Do Something here :)
                    }
                }
            }
        }
    }

    public void addConfiguredMainArgument(MainArgument anArgument) {
        this.allArguments.add(anArgument);
    }
}


*After Running:*
BUILD FAILED
My_CustomeBuild.xml:5: MySingleArgument doesn't support the nested "equals"
element.



I wish to achieve what is being mentioned in "execute()" method [Atleast in
a logical way],
  ie. to evaluate each condition and then take an appropriate decision.
I do now wish to set any property value after evaluation of the condition,
hence <condition> tag was omitted.
Any help would be greatly appreciated, to solve this issue.

(Hope this is not a question for the "dev@...")

Thank You,
Mithun Gonsalvez

Re: Problem Reusing Condition API

by ddevienne :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Jun 23, 2009 at 7:55 AM, Mithun
Gonsalvez<mithungonsalvez@...> wrote:
> public class TestCheck extends MacroDef {

Why derive from MacroDef rather than simply Task?

>    public static class MySingleArgument {
>
>        List<Condition> conditions = new ArrayList<Condition>();
>
>        public void addConfiguredCondition(Condition condition) {
>            this.conditions.add(condition);
>        }

This adds a nested <condition> tag, while you add a <equals> one.
You need to have an add() method instead. I don't recall the exact rules though.

>  ie. to evaluate each condition and then take an appropriate decision.
> I do now wish to set any property value after evaluation of the condition,
> hence <condition> tag was omitted.

Why not simply use Ant-Contrib's <if> task? --DD

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@...
For additional commands, e-mail: user-help@...


Re: Problem Reusing Condition API

by Mithun Gonsalvez :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Dominique,

Thank You for the reply.

> Why derive from MacroDef rather than simply Task?
 I want the functionality of MacroDef 'attribute' as well as sequence.
 Thought that this might be way by which I do not have to write everything
:)

> This adds a nested <condition> tag, while you add a <equals> one.
> You need to have an add() method instead. I don't recall the exact rules
though.
 The <condition> tag when evaluated to true, will set a property [which i
want to avoid]
 Instead i would like to evaluate the conditions and take another action.
 Currently I am adding methods specific to different Condition Types, as you
have mentioned.


> Why not simply use Ant-Contrib's <if> task?
 Yes, Thank you for the pointer. I will look into Ant-Contrib as well.


Thank You,
Mithun Gonsalvez



On Tue, Jun 23, 2009 at 8:35 PM, Dominique Devienne <ddevienne@...>wrote:

> On Tue, Jun 23, 2009 at 7:55 AM, Mithun
> Gonsalvez<mithungonsalvez@...> wrote:
> > public class TestCheck extends MacroDef {
>
> Why derive from MacroDef rather than simply Task?
>
> >    public static class MySingleArgument {
> >
> >        List<Condition> conditions = new ArrayList<Condition>();
> >
> >        public void addConfiguredCondition(Condition condition) {
> >            this.conditions.add(condition);
> >        }
>
> This adds a nested <condition> tag, while you add a <equals> one.
> You need to have an add() method instead. I don't recall the exact rules
> though.
>
> >  ie. to evaluate each condition and then take an appropriate decision.
> > I do now wish to set any property value after evaluation of the
> condition,
> > hence <condition> tag was omitted.
>
> Why not simply use Ant-Contrib's <if> task? --DD
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...
>
>

Re: Problem Reusing Condition API

by ddevienne :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Jun 24, 2009 at 5:46 AM, Mithun
Gonsalvez<mithungonsalvez@...> wrote:
>> This adds a nested <condition> tag, while you add a <equals> one.
>> You need to have an add() method instead. I don't recall the exact rules though.
>  The <condition> tag when evaluated to true, will set a property [which i
> want to avoid]
>  Instead i would like to evaluate the conditions and take another action.
>  Currently I am adding methods specific to different Condition Types, as you
> have mentioned.

That's what I was trying to tell you, but terminology got in the way.
There's <condition> the task (ConditionTask), and there's Condition
the interface implemented by all conditions.

If you have a void add(Condition c) method in your task, this makes your
task accept any nested tags with 'is a' Condition automatically. That's
one of the newer introspection rule added by Peter Reilly in Ant 1.6,
which is more generic that the older addTag/addConfiguredTag rules,
which only accept a nested <tag>. --DD

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@...
For additional commands, e-mail: user-help@...


Re: Problem Reusing Condition API

by Mithun Gonsalvez :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Dominique,

Sorry for the extremely late reply...
Thanks to your inputs, I was able to pull it off :)

Thank You,
Mithun Gonsalvez

On Wed, Jun 24, 2009 at 7:38 PM, Dominique Devienne <ddevienne@...>wrote:

> On Wed, Jun 24, 2009 at 5:46 AM, Mithun
> Gonsalvez<mithungonsalvez@...> wrote:
> >> This adds a nested <condition> tag, while you add a <equals> one.
> >> You need to have an add() method instead. I don't recall the exact rules
> though.
> >  The <condition> tag when evaluated to true, will set a property [which i
> > want to avoid]
> >  Instead i would like to evaluate the conditions and take another action.
> >  Currently I am adding methods specific to different Condition Types, as
> you
> > have mentioned.
>
> That's what I was trying to tell you, but terminology got in the way.
> There's <condition> the task (ConditionTask), and there's Condition
> the interface implemented by all conditions.
>
> If you have a void add(Condition c) method in your task, this makes your
> task accept any nested tags with 'is a' Condition automatically. That's
> one of the newer introspection rule added by Peter Reilly in Ant 1.6,
> which is more generic that the older addTag/addConfiguredTag rules,
> which only accept a nested <tag>. --DD
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...
>
>