java - 如何将两个不同的对象映射在一起

标签 java xml web-services proxy

在我当前的项目中,我有 2 个模块 ModuleA 和 ModuleB,在 ModuleA 和 ModuleB 中,我有一个名为“Student”的类(相同的类名,相同的属性,但出于某种目的,ModuleA 必须调用 ModuleB 来执行实际任务) 。他们通过 Web 服务相互通信。现在我希望 ModuleA Web 服务调用 ModuleB 代理来执行实际任务。

在我的 ModuleA Web 服务中,我有一个创建记录的方法:

public void createStudent(ModuleA.Student student){
    // Here will call ModuleB proxy to do the actual task which is create.

    *moduleBFacade().createStudent(   );*
}

在我的 ModuleB 代理中:

public void createStudent(ModuleB.Student student){}

所以现在的问题是,我无法将 moduleA 对象传递到 createStudent 方法中,因为它只接受 moduleB 对象作为参数。

知道如何解决这个问题吗?请给我一些建议。

最佳答案

当您使用 WS 调用时,您可以将 moduleA.Student 转换为 xml,然后更改 xml 的命名空间,然后从 xml 实例化 moduleB.Student 对象。

类似于:

String xmlA = moduleA.Student.toXml();
//Change namespace. Also, Compare the genrated xml of ModuleA and ModuleB.

ModuleB.BStudent studentB= StudentDocument.Factory.parse(xmlA, ..);//second argument can be diff namespace

*moduleBFacade().createStudent(studentB);

关于java - 如何将两个不同的对象映射在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1943743/

相关文章:

java - 如何使用 ImageView 将现有 sqlite 数据库中的数据填充到 ListView

xml - 如何使用 XSLT 将顶级元素添加到 XML?

javascript - 使用 XSLT 如何确保表头仅打印一次

java - Google 翻译 v2 api 返回非 UTF-8 字符

java - 如何捕获Android应用程序关闭

java - TextWatcher 在 EditText 中输入返回键时运行多次

android - 如何在键盘上的xml中为功能键设置不同的背景?

iphone - 我的主视图 Controller 如何知道 Web 服务调用何时结束

web-services - 为第 3 方 WS 生成 stub 类

web-services - 如何在 Tomcat 中查看所有有效的 URL?