You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Matt Kendall <ma...@iname.com> on 2007/05/22 21:43:01 UTC
[betwixt] Nested Mixed Content Lists
OK, so I have a really stupid question, but I've been banging my head
against it all day, so it's time to ask for some help. I have two
mixed content lists, one is a list of Matcher objects and each Matcher
list contains a list of Selector objects. Both Matcher and Selector
are abstract types. Matchers are contained in a Transform object. The
whole thing would look something like this:
public class Transform {
private List<Matcher> matchers = new ArrayList<Matcher>();
public void addMatcher(Matcher matcher) {
matchers.add(matcher);
}
public List<Matcher> getMatchers() {
return matchers;
}
}
public abstract class Matcher {
private List<Selector> selectors = new ArrayList<Selector>();
protected abstract Set<Long> doSomething();
public void addSelector(Selector selector) {
selectors.add(selector);
}
public List<Selector> getSelectors() {
return selectors;
}
}
public abstract class Selector {
public abstract void doSomething();
}
Now, reading the documentation, I found this little gem:
Transformer.betwixt
<info>
<element name="transform">
<element name="matchers">
<element property="matchers" adder="addMatcher"/>
</element>
<addDefaults add-adders="false"/>
</element>
</info>
And, naively, I also created:
AnInstanceOfMatcher.betwixt
<info>
<element name="matcher">
<element name="selectors">
<element property="selectors" adder="addSelector"/>
</element>
<addDefaults add-adders="false"/>
</element>
</info>
Using the latest betwixt 0.8 release this does not, sadly, give me
what I want. Just guessing, it looks like the name="matcher" attribute
from my AnInstanceOfMatcher.betwixt overrides the Transform.betwixt's
naming instructions. Here's my output:
<transform id="3">
<matchers>
<matcher id="4">
<selectors>
<PathFieldSelector id="5">
<path>table.*</path>
</PathFieldSelector>
<NamedFieldSelector id="6">
<name>table</name>
</NamedFieldSelector>
</selectors>
<clazzName>java.util.HashMap</clazzName>
</matcher>
</matchers>
<name>default</name>
</transform>
As you can see, the Selectors are named properly, but the type of the
Matcher remains a mystery. What is the proper way to map this?
Please note that I would prefer a strategy that doesn't require a lot
of extra attributes and elements. Once I get the actual mapping
working, I'll be toning down the complexity of the file so that it can
be easily edited by hand.
Thanks!
Matt
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [betwixt] Nested Mixed Content Lists
Posted by Matt Kendall <ma...@iname.com>.
As usual, a new day, a new Mt. Dew, and a re-read of the documentation
fixed my problem. What I actually needed was a betwixt-config file as
described in the derived beans mixed collection example.
Matt
On 5/22/07, Matt Kendall <ma...@iname.com> wrote:
> OK, so I have a really stupid question, but I've been banging my head
> against it all day, so it's time to ask for some help. I have two
> mixed content lists, one is a list of Matcher objects and each Matcher
> list contains a list of Selector objects. Both Matcher and Selector
> are abstract types. Matchers are contained in a Transform object. The
> whole thing would look something like this:
>
> public class Transform {
> private List<Matcher> matchers = new ArrayList<Matcher>();
> public void addMatcher(Matcher matcher) {
> matchers.add(matcher);
> }
> public List<Matcher> getMatchers() {
> return matchers;
> }
> }
>
> public abstract class Matcher {
> private List<Selector> selectors = new ArrayList<Selector>();
>
> protected abstract Set<Long> doSomething();
>
> public void addSelector(Selector selector) {
> selectors.add(selector);
> }
>
> public List<Selector> getSelectors() {
> return selectors;
> }
> }
>
> public abstract class Selector {
> public abstract void doSomething();
> }
>
> Now, reading the documentation, I found this little gem:
>
> Transformer.betwixt
> <info>
> <element name="transform">
> <element name="matchers">
> <element property="matchers" adder="addMatcher"/>
> </element>
> <addDefaults add-adders="false"/>
> </element>
> </info>
>
> And, naively, I also created:
>
> AnInstanceOfMatcher.betwixt
> <info>
> <element name="matcher">
> <element name="selectors">
> <element property="selectors" adder="addSelector"/>
> </element>
> <addDefaults add-adders="false"/>
> </element>
> </info>
>
> Using the latest betwixt 0.8 release this does not, sadly, give me
> what I want. Just guessing, it looks like the name="matcher" attribute
> from my AnInstanceOfMatcher.betwixt overrides the Transform.betwixt's
> naming instructions. Here's my output:
>
> <transform id="3">
> <matchers>
> <matcher id="4">
> <selectors>
> <PathFieldSelector id="5">
> <path>table.*</path>
> </PathFieldSelector>
> <NamedFieldSelector id="6">
> <name>table</name>
> </NamedFieldSelector>
> </selectors>
> <clazzName>java.util.HashMap</clazzName>
> </matcher>
> </matchers>
> <name>default</name>
> </transform>
>
> As you can see, the Selectors are named properly, but the type of the
> Matcher remains a mystery. What is the proper way to map this?
>
> Please note that I would prefer a strategy that doesn't require a lot
> of extra attributes and elements. Once I get the actual mapping
> working, I'll be toning down the complexity of the file so that it can
> be easily edited by hand.
>
> Thanks!
> Matt
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org