Greetings everyone,
I am attempting to create an XML entity loader to use with Spring. I want to 
return List<T> and make it so that you tell the bean what the root element is 
named so that the user does not have to create a container class. 

Here is my trimmed code in XmlEntityParser.parse():
public class XmlEntityParser<T> extends AbstractEntityParser<T> {
    public List<T> parse(String data) {
        try {
            Mapping mapping = new Mapping();
            mapping.loadMapping(mappingUrl);

            ClassMapping classMapping = new ClassMapping();
            classMapping.setName(RootElement.class.getName());
            
            MapTo mapTo = new MapTo();
            mapTo.setXml(rootElement);
            classMapping.setMapTo(mapTo);
            
            FieldMapping fieldMapping = new FieldMapping();
            fieldMapping.setName("entities");
            fieldMapping.setCollection(FieldMappingCollectionType.COLLECTION);
            fieldMapping.setType(type.getName());

            XMLContext context = new XMLContext();
            context.addMapping(mapping);
            
            Unmarshaller unmarshaller = context.createUnmarshaller();
            unmarshaller.setClass(type);
            unmarshaller.unmarshal(new StringReader(data));
        }
    }

    private class RootElement {

        private List<T> entities;



        public final List<T> getEntities() {

            return entities;

        }



        public final void setEntities(List<T> entities) {

            this.entities = entities;

        }

    }

}

Here's what the XML would look like (rootElement and type are properties of the 
XmlEntityParser class):
    <class name="XmlEntityParser.RootElement">
        <map-to xml="${rootElement}" />
        <field name="entities" collection="collection" type="${type}" />
    </class>

The issue I'm having is that I'm coding along defining the ClassMapping, 
FieldMapping, etc... and I get to the part where I'm expecting to be able to 
call something like classMapping.addFieldMapping(), and no such method exists. 
Am I using the right classes? I want to define the root element stuff 
programmatically. Thanks!

Brian


                                          
_________________________________________________________________
Hotmail has tools for the New Busy. Search, chat and e-mail from your inbox.
http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_1

Reply via email to