tags:

views:

23

answers:

1

I am trying to create a user interface which contains an Editable grid which contains data from XSD file. I have generated the required classes from the XSD file using XJC. But I cant figure out how to load the data into the grid using methods of the JAXB generated classes. Can anyone please tell me how to go about doing this? I have implemented the code of Simple XML grid example from Sencha website (http://www.sencha.com/examples/pages/grid/xml.html) by using the XML document of the XSD file. But, I am having a problem of not being able to load the inner child node data from the XML file. Can anyone please help me with both the problems?? Thank you.

Edit: The following is my code for the grid.

public class XMLToGridex extends LayoutContainer
{

//@Override
protected void onRender(Element parent, int index)
{
    super.onRender(parent, index);
    setLayout(new FlowLayout(10));

    List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
    columns.add(new ColumnConfig("name", "Name", 100));
    columns.add(new ColumnConfig("frameworkFrequencyMultiplier", "FrameWorkFrequencyMultiplier", 300));
    columns.add(new ColumnConfig("additional", "Additional", 100));

    // create the column model  
    ColumnModel cm = new ColumnModel(columns);  

    // defines the xml structure  
    ModelType type = new ModelType();  
    type.setRoot("module");  
    type.setRecordName("emsElement");  
    type.addField("name");  
    type.addField("frameworkFrequencyMultiplier"); 
  // type.addField("convertItem");
   // type.setRoot("convertItem");
   // type.setRecordName("source");
    //type.addField("additional");
    //type.addField("converter");
    //type.addField("converter");
    //type.setRecordName(")
   // type.addField("convertItem");

    // use a http proxy to get the data  
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,  
        GWT.getHostPageBaseURL() + "module.xml");  
    HttpProxy<String> proxy = new HttpProxy<String>(builder);

    // need a loader, proxy, and reader  
    XmlLoadResultReader<ListLoadResult<ModelData>> reader = new XmlLoadResultReader<ListLoadResult<ModelData>>(  
        type);  

    final BaseListLoader<ListLoadResult<ModelData>> loader = new BaseListLoader<ListLoadResult<ModelData>>(  
            proxy, reader);  

    ListStore<ModelData> store = new ListStore<ModelData>(loader);  
    final Grid<ModelData> grid = new Grid<ModelData>(store, cm);  
    grid.setBorders(true);  
    grid.setLoadMask(true);  
    grid.getView().setEmptyText("Please hit the load button.");  
    //grid.setAutoExpandColumn("Name");
  //  grid.setAutoExpandColumn("");
    //grid.setAutoExpandColumn("ConvertItem");

    ContentPanel panel = new ContentPanel();  
    panel.setFrame(true);  
    panel.setCollapsible(true);  
    panel.setAnimCollapse(false);  
    panel.setButtonAlign(HorizontalAlignment.CENTER);  
    //panel.setIcon(Resources.ICONS.table());  
    panel.setHeading("XML Table Demo");  
    panel.setLayout(new FitLayout());  
    panel.add(grid);  
    panel.setSize(575, 350);  

    // add buttons  
    Button load = new Button("Load XML", new SelectionListener<ButtonEvent>() {  
     public void componentSelected(ButtonEvent ce) {  
        loader.load();  
      }  
    });  

    panel.addButton(load);  

    add(panel);  
    }
}

Edit2: I am also posting the XML document to get a better idea.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<module>
<emsElement>
    <name>c1</name>
    <frameworkFrequencyMultiplier>1</frameworkFrequencyMultiplier>
    <convertItem>
        <source user="test" url="https://192.168.103.153:8443/mi/xmlInterfaceRequest.do" passwd="837103af8990d948">
            <additional>method=post</additional>
            <useEncryptPasswd>true</useEncryptPasswd>
            <trustStoreLocation>${NH_HOME}/custom/imframework/config/trustkeystore</trustStoreLocation>
            <trustStorePassword>changeit</trustStorePassword>
        </source>
        <processor deltaed="true" name="camiant" additional="requestName=All">
            <serverName>192.168.103.130</serverName>
        </processor>
        <converter name="dump">
            <additional>timestamp=true</additional>
            <location url="${NH_HOME}/modules/imframework/fileStagingArea/dump"/>
        </converter>
        <converter name="element">
            <location url="${NH_HOME}/modules/imframework/fileStagingArea/elementData"/>
        </converter>
    </convertItem>
</emsElement>
<emsElement>
    <name>n-nj</name>
    <frameworkFrequencyMultiplier>1</frameworkFrequencyMultiplier>
    <convertItem>
        <source user="ubuntu" url="sftp://192.168.150.133/home/ubuntu/NSN/NJ" passwd="d5ee45fa2386d5f8">
            <additional>strictHostKeyChecking=no</additional>
            <namePatterm>**/*</namePatterm>
            <recureMode>true</recureMode>
            <useEncryptPasswd>true</useEncryptPasswd>
        </source>
        <processor deltaed="true" name="nsn">
            <serverName>192.168.150.133</serverName>
            <config>configA=${NH_HOME}/custom/imframework/config/NSN-SimulatorConfigA.xml</config>
        </processor>
        <converter name="dump">
            <location url="${NH_HOME}/modules/imframework/fileStagingArea/dump"/>
        </converter>
        <converter name="element">
            <location url="${NH_HOME}/modules/imframework/fileStagingArea/elementData"/>
        </converter>
    </convertItem>
</emsElement>
<emsElement>
    <name>n-tx</name>
    <frameworkFrequencyMultiplier>1</frameworkFrequencyMultiplier>
    <convertItem>
        <source user="ubuntu" url="sftp://192.168.150.133/home/ubuntu/NSN/TX" passwd="d5ee45fa2386d5f8">
            <additional>strictHostKeyChecking=no</additional>
            <namePatterm>**/*</namePatterm>
            <recureMode>true</recureMode>
            <useEncryptPasswd>true</useEncryptPasswd>
        </source>
        <processor deltaed="true" name="nsn">
            <serverName>192.168.150.133</serverName>
            <config>configA=${NH_HOME}/custom/imframework/config/NSN-SimulatorConfigA.xml</config>
        </processor>
        <converter name="dump">
            <location url="${NH_HOME}/modules/imframework/fileStagingArea/dump"/>
        </converter>
        <converter name="element">
            <location url="${NH_HOME}/modules/imframework/fileStagingArea/elementData"/>
        </converter>
        <converter name="csv">
            <additional>perDayperDirectory=true,PDSN=starent</additional>
        </converter>
    </convertItem>
</emsElement>
<emsElement>
    <name>k1</name>
    <frameworkFrequencyMultiplier>1</frameworkFrequencyMultiplier>
    <convertItem>
        <source user="ubuntu" url="sftp://192.168.150.128/home/ubuntu/fileStagingArea" passwd="d5ee45fa2386d5f8">
            <additional>strictHostKeyChecking=no</additional>
            <namePatterm>**/*</namePatterm>
            <recureMode>true</recureMode>
            <useEncryptPasswd>true</useEncryptPasswd>
        </source>
        <processor deltaed="true" name="kodiak" additional="processBy=KodiakFileDate">
            <serverName>192.168</serverName>
            <config>${NH_HOME}/custom/imframework/config/KODIAK-SimulatorConfig.xml</config>
        </processor>
        <converter name="dump">
            <location url="${NH_HOME}/modules/imframework/fileStagingArea/dump"/>
        </converter>
        <converter name="element">
            <location url="${NH_HOME}/modules/imframework/fileStagingArea/elementData"/>
        </converter>
    </convertItem>
</emsElement>
<emsElement>
    <name>a1</name>
    <frameworkFrequencyMultiplier>1</frameworkFrequencyMultiplier>
    <convertItem>
        <source user="ubuntu" url="sftp://192.168.150.133/home/ubuntu/ALU/NJALUSample" passwd="d5ee45fa2386d5f8">
            <additional>strictHostKeyChecking=no</additional>
            <namePatterm>**/*</namePatterm>
            <recureMode>true</recureMode>
            <useEncryptPasswd>true</useEncryptPasswd>
        </source>
        <processor deltaed="true" name="alu">
            <serverName>192.168.150.133</serverName>
            <config>configA=${NH_HOME}/custom/imframework/config/ALU-SimulatorConfigA.xml,configB=${NH_HOME}/custom/imframework/config/ALU-SimulatorConfigB.xml,configC=${NH_HOME}/custom/imframework/config/ALU-SimulatorConfigC.xml</config>
        </processor>
        <converter name="dump">
            <location url="${NH_HOME}/modules/imframework/fileStagingArea/dump"/>
        </converter>
        <converter name="element">
            <location url="${NH_HOME}/modules/imframework/fileStagingArea/elementData"/>
        </converter>
    </convertItem>
</emsElement></module>
+1  A: 

The JAXB code you will write will look something like:

JAXBContext jc = JAXBContext.newInstance("your.model.package");

Unmarshaller unmarshaller = jc.createUnmarshaller();
Module module = (Module) unmarshaller.unmarshal(xml);
Blaise Doughan