Java 中的 XSD 设计问题
目前我们的软件正在通过 XML/SOAP 与远程 Web 服务交互。我们使用 XSD 来方便地创建发送到远程系统的请求。很好,而且运行良好。 XSD 非常棒。
但是,它确实会导致创建 Document 对象的代码块非常冗长。我想知道是否有人对良好的设计实践有建议,以处理这些大型代码块以创建请求和处理响应文档。
XSD Document 对象的要点是将 XML 创建与客户端分离。然而,我认为对于每项服务来说,外观类可能是一个好主意。我认为这对于创建来说非常有用,因为可以为外观类提供构建请求文档并发送请求的成分,而无需将客户端耦合到 XSD 类。我认为响应文档中出现了问题。如果存在多级响应,您最终将创建 POJO 类只是为了包装 XSD 类,这似乎有点过头了。
Currently our software is interacting with a remote web service via XML/SOAP. We're using XSDs to conveniently create the requests to be sent to the remote system. That's fine, and it's working well. XSD is pretty awesome.
However, it does lead to very lengthy code blocks for creating the Document objects. I'm wondering if anyone has suggestions for good design practices to handle these large code blocks for creation of the request and handling of the response Documents.
The point of the XSD Document object is to decouple the XML creation from the client. However, I'm thinking a facade class might be a good idea for each service. I think this would be great for creation, since the facade class could be given the ingredients to build the request document, and send the request, without coupling the client to the XSD classes. I think a problem arises in the response Documents. If there is a multi-level response, you'll end up creating POJO classes just to wrap the XSD classes, which seems like over-kill.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
注意:我是 EclipseLink JAXB (MOXy) 技术主管。
EclipseLink JAXB (MOXy)
MOXy 是一个 JAXB (JSR-222) 实现,具有基于 XPath 的映射扩展。这意味着您可以将更紧凑的对象模型映射到 XML。在下面的示例中,一个简单的 Address 对象映射到 Google 地理编码 V2< /a> 格式:
上面的类对应以下 XML:
了解更多信息
Note: I'm the EclipseLink JAXB (MOXy) tech lead.
EclipseLink JAXB (MOXy)
MOXy is a JAXB (JSR-222) implementation that has an XPath based mapping extension. This means you can map a more compact object model to your XML. In the example below a simple Address object is mapped to Google's Geocoding V2 format:
The above class corresponds to the following XML:
For More Information