You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Thomas Dudziak <to...@gmail.com> on 2005/04/06 22:32:56 UTC

[betwixt] Why is the name attribute in betwixt's element tag required when used for references to other mapped classes ?

Say, I have a class SomeClass that holds an object of a subclass of
the interface SomeInterface:

public class SomeClass
{
  private SomeInterface obj;
  public SomeInterface getObj()
  {
    return obj;
  }
  public void setObj(SomeInterface obj)
  {
    this.obj = obj;
  }
}

public interface SomeInterface
{}

public class SomeOtherClassA implements SomeInterface
{}

public class SomeOtherClassB implements SomeInterface
{}

then in the multi-mapping (using betwixt from SVN):

<?xml version="1.0"?>
<betwixt-config>
    <class name="SomeClass">
        <element name="some-class">
            <element name="whatever" property="obj"/>
            <addDefaults/>
        </element>
    </class>
    <class name="SomeOtherClassA">
        <element name="other-a"/>
    </class>
    <class name="SomeOtherClassB">
        <element name="other-b"/>
    </class>
</betwixt-config>

I have to specify the name for the property SomeClass#obj even though
there are mappings for the two sub classes. This leads to the problem
that I cannot get other-a or other-b to appear in the generated XML
since the name 'whatever' is harcoded in the mapping.

Now I did a little test and simply commented out the check for the
name attribute in org.apache.commons.betwixt.digester.ElementRule,
lines 113-116. After this I can omit the name attribute and get
other-a or other-b depending on which type the object has.

My question now is, would it be possible to completely remove the
check for the name attribute in ElementRule ? IMO if it is not given
for fields whose type is not explicitly mapped, the name of the field
could be used when writing the XML attribute for the field. And for
references to other mapped classes, it might be useful to be able to
specify the name, i.e. for forcing the name of the XML sub element,
but most of the time you wouldn't want it there.

regards,
Tom

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org