Many thanks to all the people who offered suggestions. Those helped a lot to straighten out configuration problems. Funny thing - code truly started working only after I split single betwixt-config file into individual dotbetwixt files. Weird. I am not even sure I can formulate problem correctly to post it on developers list. Something to do with preloaded and cached configuration.
Thanks again. Igor -----Original Message----- From: Mornak [mailto:[EMAIL PROTECTED] Sent: Wednesday, February 08, 2006 8:46 AM To: Jakarta Commons Users List Subject: Re: [betwixt] unable to read XML into collection. Please help Try this <?xml version="1.0" encoding="UTF-8"?> <betwixt-config> <class name='com.my.CollectionWrapper' > <element name='elements'> <element property='elements' updater='addElement'/> </element> </class> notice that i changed 2 things: - the name of the property is elementS (plural), not element - I added an updater to specify the method that betwixt should invoke (it may be not necesary) I hope to be helpfull PS: Excuse my terrible english. I am not an english native speaker On 2/7/06, Igor Marakov <[EMAIL PROTECTED]> wrote: > Hi, > > I have a simple (or so it seems) problem. > There is a piece of XML that represents a list of items. > I need to convert this XML to the List of beans. > I must be doing something very wrong but for couple days now I am not able > to come up with combination of code and configuration that would work. I can > see beans being created but assignment into List never happens. At the same > time running single beans does work. > Obviously I'm missing something big time here; > Any help will be greatly appreciated. > Relevant code pieces and configuration is below. > > Thanks, > Igor > > **** SETUP ( done once in translator life cycle ) > > // insert my bean factory, verified - works, beans created ok. > beanCreationChain = BeanCreationList.createStandardChain(); > beanCreationChain.insertBeanCreator(1, new BeanCreator() ); > > // load betwixt-config, save XMLIntrospector for future use > BeanWriter writer = new BeanWriter(); > introspector = writer.getXMLIntrospector(); > InputSource is = new > InputSource(TranslatorImpl.class.getResourceAsStream(translatorConfig)); > > introspector.register(is); > introspector.getConfiguration().setWrapCollectionsInElement(true); > writer.getBindingConfiguration().setMapIDs(false); > > // save Configuration for future use > configuration = writer.getBindingConfiguration(); > > > > **** BETWIXT CONFIG ( loaded by above code ) > > <?xml version="1.0" encoding="UTF-8"?> > <betwixt-config> > <class name='com.my.CollectionWrapper' > > <element name='elements'> > <element property='element' /> > </element> > </class> > > <class name='com.my.Application'> > <element name='application'> > <attribute name='id' property='id'/> > <attribute name='name' property='name' /> > <element name='description' property='description' /> > <addDefaults add-properties='false'/> > </element> > </class> > </betwixt-config> > > > **** XML IN ( to be loaded into collection ) > > <?xml version='1.0' ?> > <elements> > <application id="2" name="bean2"> > <description>Application Bean 2</description> > </application> > <application id="3" name="bean3"> > <description>Application Bean 3</description> > </application> > <application id="1" name="bean1"> > <description> Application Bean 1</description> > </application> > </elements> > > > **** READING ( actual translation step ) > > Object result = null; > StringReader xmlReader = new StringReader(buffer); // XML IN > > BeanReader reader = new BeanReader(); > > // using configuration saved earlier > reader.setXMLIntrospector(introspector); > reader.setBindingConfiguration(configuration); > reader.getReadConfiguration().setBeanCreationChain(beanCreationChain); > > reader.registerBeanClass("elements", > Class.forName("com.my.CollectionWrapper")); > > reader.registerBeanClass("application", > Class.forName("com.my.Application")); > > result = reader.parse(xmlReader); > > // RESULT Contains empty collection. > // Adding to collection in CollectionWrapper never happens > > > **** COLLECTION WRAPPER > > public class CollectionWrapper > { > private static Logger log = Logger.getLogger(CollectionWrapper.class); > private Collection elements = null; > public CollectionWrapper() > { > log.debug("********* CONSTRUCTOR ******************"); > elements = new java.util.ArrayList(); > } > > public void addElement(Object element) > { > log.debug("********** ADD *************** " + element.toString()); > elements.add(element); > } > > public Collection getElementCollection() { return elements; } > > public Iterator getElements() { return elements.iterator(); } > > public void setElements(Collection elements) { this.elements = elements; } > > > > // this did not work either > > // public Collection getApplications(Application element) { > addElement(element); } > > // public void addApplication(Application element) { addElement(element); } > > > // public void setApplication(Application element) { addElement(element); } > > > > > } > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- To Iterate is Human, to Recurse, Divine - James O. Coplien, Bell Labs ------------------------------------- <EPI/> - Deploying ideas ------------------------------------- Ing. Diego H. Mornacco Desarrollador Epidata Consulting MaipĂș 521 1er piso Of. A Ofi: 5031 0060 / 61 Cel: 15-5884-0040 www.epidataconsulting.com --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
