commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lena...@email.arizona.edu
Subject [Betwixt] Unable to get XML into Collection - always empty
Date Thu, 31 Jan 2008 00:49:15 GMT
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



Mime
View raw message