commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dmitriy Kuznetsov <heaven-se...@yandex.ru>
Subject Commons betwixt 0.8 - reading Map from XML
Date Mon, 01 Sep 2008 14:43:28 GMT

Hi. I am trying to load a map of <String, Object> from XML back to java using
betwixt - with no success. 
I've exported a Hashtable of <String, Object> to XML using Betwixt 0.8. The
XML i've got is:

<?xml version="1.0" encoding="UTF-8" ?>
<metadata>
  <map>
    <empty>true</empty>
    <entry>
      <key>gabbaGabbaHey</key>
      <value>md-id-2</value>
    </entry>
    <entry>
      <key>Entry1</key>
      <value>123</value>
    </entry>
    <entry>
      <key>halooppoRoste</key>
      <value>-3.76</value>
    </entry>
  </map>
</metadata>

After that, i am trying to load the XML back by the following code:

		BeanReader beanReader = new BeanReader();

	
beanReader.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(false);
		beanReader.getBindingConfiguration().setMapIDs(false);
		
		try {
			beanReader.registerBeanClass("map", Hashtable.class);
			beanReader.registerBeanClass("entry/value", String.class);

			Object tmp;

			File srcFile = new File("metadata.xml"); 
			tmp = instance.beanReader.parse(srcFile);

		} catch (Exception ex) {
			logger.log(Level.SEVERE, "Failed to read metadata.", ex);
			return null;
		}

I played with beanReader.registerBeanClass - tried to set "metadata/map" and
"metadata/map/entry/value" as first parameter, disable registerBeanClass
commands, remove <metadata> tags from XML, but the only results i've got are
null in tmp variable, or EmptyStackException

Sep 1, 2008 5:39:52 PM org.apache.commons.digester.Digester endElement
SEVERE: End event threw exception
java.util.EmptyStackException
	at org.apache.commons.collections.ArrayStack.peek(ArrayStack.java:94)
	at
org.apache.commons.betwixt.io.read.ReadContext.getBean(ReadContext.java:351)
	at
org.apache.commons.betwixt.expression.CollectionUpdater.update(CollectionUpdater.java:47)
	at
org.apache.commons.betwixt.io.read.BeanBindAction.update(BeanBindAction.java:171)
	at
org.apache.commons.betwixt.io.read.BeanBindAction.end(BeanBindAction.java:158)
	at
org.apache.commons.betwixt.io.BeanRuleSet$ActionMappingRule.end(BeanRuleSet.java:316)
	at org.apache.commons.digester.Digester.endElement(Digester.java:1222)
	at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown
Source)
	at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown
Source)
	at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown
Source)
	at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown
Source)
	at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
	at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
Source)
	at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
Source)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown
Source)
	at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown
Source)
	at
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown
Source)
	at org.apache.commons.digester.Digester.parse(Digester.java:1728)
	at
com.aleri.lms.ui.beans.XMLMetadataProvider.loadMetadata(XMLMetadataProvider.java:83)
	at
com.aleri.lms.ui.beans.XMLMetadataProvider.main(XMLMetadataProvider.java:74)
java.util.EmptyStackException
	at
org.apache.commons.digester.Digester.createSAXException(Digester.java:3181)
	at
org.apache.commons.digester.Digester.createSAXException(Digester.java:3207)
	at org.apache.commons.digester.Digester.endElement(Digester.java:1225)
	at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown
Source)
	at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown
Source)
	at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown
Source)
	at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown
Source)
	at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
	at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
Source)
	at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
Source)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown
Source)
	at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown
Source)
	at
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown
Source)
	at org.apache.commons.digester.Digester.parse(Digester.java:1728)
	at
com.aleri.lms.ui.beans.XMLMetadataProvider.loadMetadata(XMLMetadataProvider.java:83)
	at
com.aleri.lms.ui.beans.XMLMetadataProvider.main(XMLMetadataProvider.java:74)

Well, at the end of all i need an instance of Map<String, Object>. If i have
to anjust my XML file to accomplish this, it's ok. If there is a solution,
that allows to keep information about order of entries in XML file, i would
better implement it, instead of plain map. 
Could you please explain me, how to do it? At least, how to load Map from
XML?

I understand, that my question may be lame. But i am trying variants,
tracing code and looking for answer for about three days, and found nothing
that could help. I believe it would be perfect to have a sample or entry in
FAQ with working code that loads Map from XML.
-- 
View this message in context: http://www.nabble.com/Commons-betwixt-0.8---reading-Map-from-XML-tp19255879p19255879.html
Sent from the Commons - User mailing list archive at Nabble.com.


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


Mime
View raw message