带有 JAXB 类的 GXT

发布于 2024-09-18 02:00:03 字数 9478 浏览 5 评论 0原文

我正在尝试创建一个用户界面,其中包含一个可编辑网格,其中包含 XSD 文件中的数据。我已经使用 XJC 从 XSD 文件生成了所需的类。但我无法弄清楚如何使用 JAXB 生成的类的方法将数据加载到网格中。谁能告诉我该怎么做?我已经实现了 Sencha 网站上的简单 XML 网格示例的代码 (http:// www.sencha.com/examples/pages/grid/xml.html)通过使用XSD文件的XML文档。但是,我遇到了无法从 XML 文件加载内部子节点数据的问题。谁能帮我解决这两个问题吗?谢谢。

编辑:以下是我的网格代码。

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:我还发布了 XML 文档以获得更好的想法。

<?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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月依秋水 2024-09-25 02:00:03

您将编写的 JAXB 代码将类似于:

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

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

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文