Hi,

I have an existing XML file format that I'm trying to mapping into beans with
Betwixt (so I can't tweak the elements and attributes).  I'm able to get one of
the collections read just fine - but the other is failing to load and just
returning empty.  In both cases, I'm relying on Betwixt to automatically
determine the collection relation with plural/singular forms.  If I attempt to
state the element mapping in the .betwixt file, it causes the whole thing to
not load.

I slimmed down my example from the my concrete case (hopefully I slimmed it down
enough).

So the XML looks like this:
===========================
<?xml version="1.0" standalone="yes" ?>

<root>
   <node id="99999">
        <name>Heliconius</name>
    <othernames>
      <othername>
        <name>Heliconius cydno pachinus</name>
      </othername>
    </othernames>
    <nodes>
        <node id="666666">
                <name>taxa 1</name>
        </node>
        <node id="777777">
                <name>taxa 2</name>
        </node>
    </nodes>
   </node>
</root>

My object model is pretty simple, XTRoot -> root, XTNode -> node, and
XTOtherName -> othername.  I attached the java source. Each class has a default,
no argument constructor.  And XTNode has a getter/setter for the collections
along with a singular add*() method, so getNodes() and addNode(XTNode) /
getOtherNames() and addOtherName(XTOtherName)

I'm just stated .betwixt files (not sure if doing a single betwixt-config would
be better)

XTNode.betwixt
==========================
<?xml version="1.0" encoding="UTF-8" ?>
<info primitiveTypes="element">
  <element name="node">
        <attribute name="id" property="id" />
        <attribute name="has-page" property="hasPage" />
<!-- add this in the file causes the whole load of the node element to fail
        <element name="othernames" property="othernames" />
  -->
    <addDefaults />
  </element>
</info>

XTOtherName.betwixt
==========================
<?xml version="1.0" encoding="UTF-8" ?>
<info primitiveTypes="element">
  <element name="othername">
    <addDefaults/>
  </element>
</info>

XTRoot.betwixt
==========================
<?xml version="1.0" encoding="UTF-8" ?>
<info primitiveTypes="element">
  <element name="root">
    <element name="node" property="node" />
    <addDefaults />
  </element>
</info>

At the moment - I'm just trying to test the success of load with a simple
class-main-method setup (nothing fancy):

try {

        InputStream xtnodes =
EntryPointX.class.getResourceAsStream("./Heliconius_othernames_simple.xml");
        System.out.println("$> xml loaded...");
        BeanReader beanReader = new BeanReader();
        beanReader.registerBeanClass("othername", XTOtherName.class);
        beanReader.registerBeanClass(XTRoot.class);
        beanReader.registerBeanClass(XTNode.class);

        XTRoot root = (XTRoot)beanReader.parse(xtnodes);
        System.out.println("$> xml parsed...");
        if (root != null) {
                XTNode node = root.getNode();
                if (node != null) {
                        System.out.println("node-id: " + node.getId());
                        System.out.println("nodes: " + node.getNodes());

                        
System.out.println("othernames(size:"+node.getOtherNames().size()+"): " +
node.getOtherNames());
                }
        }
        System.out.println("$> done...");
} catch (Exception e) {
        System.out.println("exception occurred... lame");
        e.printStackTrace();
}

When I run this - I get a collection loaded for Nodes with two elements as I'd
expect.  But OtherNames is just empty (because I'm setting it to an empty
collection in the XTNode class).

The JDK version I'm using is jdk1.5.0_14

I'm not a maven user (sorry).  But here's a listing of the jars on my classpath:

commons-beanutils-1.7.0.jar
commons-beanutils-bean-collections.jar
commons-beanutils-core.jar
commons-betwixt-0.8.jar
commons-collections-3.1.jar
commons-digester-1.8.jar
commons-io-1.1.jar
commons-lang-2.1.jar
commons-logging-1.0.4.jar
commons-pool-1.1.jar
xercesImpl-2.6.2.jar
xml-apis-2.0.2.jar

I'm rather stumped why one of the two works and the other does not.  I looked
through and saw that people had similar issues but I wasn't able to follow the
solutions (or they looked like they were having slightly different issues).  I
went through the FAQ and don't think I missed a simple solution (other than the
hypothesis that XTOtherName.class isn't being loaded or resolved properly).

This is the first question I've asked on the list - so if I'm done or said
something egregious I'll apologize in advance.

Thanks for reading - I appreciate it.

Andy


package org.foo.xml;

import java.util.ArrayList;
import java.util.List;

public class XTNode {
	private Long id; 
	private Boolean hasPage;
	private String name;
	private String rank; 
	private List<XTOtherName> otherNames;
	private List<XTNode> nodes;
	
	public XTNode() {
		otherNames = new ArrayList<XTOtherName>();
		nodes = new ArrayList<XTNode>();
	}
	
	public String toString() {
		return getName() + "(" + getId() + ")";
	}
	
	public void addNode(XTNode child) {
		nodes.add(child);
	}
	
	public void addOtherName(XTOtherName otherName) {
		otherNames.add(otherName);
	}

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the hasPage
	 */
	public Boolean getHasPage() {
		return hasPage;
	}

	/**
	 * @param hasPage the hasPage to set
	 */
	public void setHasPage(Boolean hasPage) {
		this.hasPage = hasPage;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the rank
	 */
	public String getRank() {
		return rank;
	}

	/**
	 * @param rank the rank to set
	 */
	public void setRank(String rank) {
		this.rank = rank;
	}

	/**
	 * @return the otherNames
	 */
	public List<XTOtherName> getOtherNames() {
		return otherNames;
	}

	/**
	 * @param otherNames the otherNames to set
	 */
	public void setOtherNames(List<XTOtherName> otherNames) {
		this.otherNames = otherNames;
	}

	/**
	 * @return the nodes
	 */
	public List<XTNode> getNodes() {
		return nodes;
	}

	/**
	 * @param nodes the nodes to set
	 */
	public void setNodes(List<XTNode> nodes) {
		this.nodes = nodes;
	}
}
package org.foo.xml;

public class XTOtherName {
/*
    <othernames>
      <othername is-important="true" is-preferred="false" sequence="0" date="1871" italicize-name="1">
        <name>Heliconius cydno pachinus></name>
        <authority>Salvin</authority>
        <comments>[Lamas (2004) views &lt;em&gt;pachinus&lt;/em&gt; as a subspecies of &lt;em&gt;H. cydno&lt;/em&gt;]</comments>
      </othername>
    </othernames>
 */
	// xml attributes of XTOtherName
	private Boolean isImportant;
	private Boolean isPreferred;
	private Integer sequence; 
	private String date; 
	private String italicizeName; 
	// child elements of XTOtherName
	private String name;
	private String authority;
	private String comments;
	
	public XTOtherName() {
		
	}
	
	/**
	 * @return the isImportant
	 */
	public Boolean getIsImportant() {
		return isImportant;
	}
	/**
	 * @param isImportant the isImportant to set
	 */
	public void setIsImportant(Boolean isImportant) {
		this.isImportant = isImportant;
	}
	/**
	 * @return the isPreferred
	 */
	public Boolean getIsPreferred() {
		return isPreferred;
	}
	/**
	 * @param isPreferred the isPreferred to set
	 */
	public void setIsPreferred(Boolean isPreferred) {
		this.isPreferred = isPreferred;
	}
	/**
	 * @return the sequence
	 */
	public Integer getSequence() {
		return sequence;
	}
	/**
	 * @param sequence the sequence to set
	 */
	public void setSequence(Integer sequence) {
		this.sequence = sequence;
	}
	/**
	 * @return the date
	 */
	public String getDate() {
		return date;
	}
	/**
	 * @param date the date to set
	 */
	public void setDate(String date) {
		this.date = date;
	}
	/**
	 * @return the italicizeName
	 */
	public String getItalicizeName() {
		return italicizeName;
	}
	/**
	 * @param italicizeName the italicizeName to set
	 */
	public void setItalicizeName(String italicizeName) {
		this.italicizeName = italicizeName;
	}
	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}
	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}
	/**
	 * @return the authority
	 */
	public String getAuthority() {
		return authority;
	}
	/**
	 * @param authority the authority to set
	 */
	public void setAuthority(String authority) {
		this.authority = authority;
	}
	/**
	 * @return the comments
	 */
	public String getComments() {
		return comments;
	}
	/**
	 * @param comments the comments to set
	 */
	public void setComments(String comments) {
		this.comments = comments;
	}
}
package org.foo.xml;

public class XTRoot {
	private XTNode node;

	public XTRoot() {
		
	}
	
	/**
	 * @return the node
	 */
	public XTNode getNode() {
		return node;
	}

	/**
	 * @param node the node to set
	 */
	public void setNode(XTNode node) {
		this.node = node;
	}
	
}

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to