JAXB:为unmarshaller提供更强大的功能。请评论 [英] JAXB: Take more robustness to the unmarshaller. Please comment

查看:137
本文介绍了JAXB:为unmarshaller提供更强大的功能。请评论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




在sun主页上我已经向bugparade提交了一份请求,要求对JAXB API进行
功能增强。

经过一段时间太阳打电话给我发布我的请求到新闻组

得到其他java开发者的评论。

所以请评论我的以下请求功能增强:


如果我解组了一个无效的xml文档,我得到了一个

javax.xml.bind.UnmarshalException:元素的意外结束

例外。

抛出异常是因为需要足够的元素而且

它不是在xml文件中的


当抛出异常时,解组过程中止。

目前我只能创建包含所有必需的

元素的xml文件,

因为unmarshaller无法将这样的xml文件读入java。


你对此有何看法?


谢谢

Christoph Brunner

Hi,

on the sun homepage i had submit to the bugparade a request for
feature enhancement for the JAXB API.
After a period of time sun called me to post my request to a newsgroup
an get comments from other java developers.
So please comment my following request for feature enhancement:

If i unmarshall an invalid xml document i got a
javax.xml.bind.UnmarshalException: Unexpected end of element
exception.
The exception is thrown because the adequate element is required and
it is
not in the xml file.
When an exception is throwed the unmarshalling process is aborted.
At the moment i can only create xml files with all the required
elements,
because the unmarshaller can not read such a xml file into java.

What do you mean about this?

Thanks
Christoph Brunner

推荐答案




我认为能够编组/解组不完整的文件是真的

必要。示例是


(a)用户将复杂数据输入到内部使用

JAXB类的应用程序中。要去午餐休息等,用户想要保存他的工作,即使他或她还没有完成,他们也可以保存他的工作,所以这些数据很可能无法使用

尊重架构。尽管如此,应该可以将数据暂时存储为磁盘或数据库中的XML。

来自我的项目的
(b):我们使用CORBA基于容器组件的模型,它使用

XML来传输和持久化Value Objects。该框架为客户端和服务器代码提供了Java

绑定类,并自动对其间的CORBA传输进行(un-)编组操作。由于几个Java

组件可以协作生成有效的值对象(XML),因此

容器框架永远不会强制进行模式验证,但只需要

在JAXB树和序列化XML之间进行转换。验证必须由应用程序明确执行

.


在我看来,JAXB规范对如何容忍如此宽容有点难过

实现可能会处理无效的XML,因为它似乎意味着使用JAXB的应用程序应该是单一的,总是先生成
生成有效的内存树在一个地方,然后才序列化/解析它们。


我非常希望SUN参考实现不抛出任何

异常或问题遇到丢失的子元素时出现**致命**错误。

非致命错误确实会发生,并且应用程序可以使用

来预测ValidationHandler机制。


也许我应该在我们的项目中添加它( http://www.eso.org/projects/alma/ )我们

目前正在使用Castor框架,它让我们un- / m arshal不完整

XML没有问题。出于其他原因,我们想切换到JAXB,

遗憾的是,考虑到目前在

Unmarshaller中的限制,这似乎是不可能的。


如果有人认为这是一个问题,请添加您的意见,因为他们可以使用
来克服Christ在这里采取一些行动。


欢呼,Heiko
Hi,

I think that being able to marshal/unmarshal incomplete documents is really
essential. Examples are

(a) a user enters complex data into an application that internally works with
JAXB classes. To go for lunch break etc., the user wants to save his work, even
though he or she is not yet done, so the data will likely not be valid with
respect to the schema. Nonetheless it should be possible to store the data
temporarily as XML on disk or in a database.

(b) from my project: we use a CORBA-based container-component model which uses
XML for transport and persistence of Value Objects. The framework presents Java
binding classes to both the client and the server code, and automatically takes
care of the (un-)marshalling for the CORBA transport in between. As several Java
components might collaborate to produce a valid Value Object (XML), the
container framework will never impose schema validation, but has to merely
convert between JAXB-trees and serialized XML. Validation must be performed
explicitly by the applications.

In my opinion it is a bit sad that the JAXB spec is so tolerant on how
implementations may deal with invalid XML, since it seems to imply that
applications using JAXB are supposed to be monolithic enough to always first
produce valid in-memory trees in one place, and only then serialize/parse them.

I would very much like for the SUN reference implementation to not throw any
exception or issue a **FATAL** error when it encounters a missing child element.
A non-fatal error would really do, and applications could deal with this using
the foreseen ValidationHandler mechanism.

Maybe I should add that in our project (http://www.eso.org/projects/alma/) we
are currently using the Castor framework, which lets us un-/marshal incomplete
XML without problems. For other reasons we''d like to switch to JAXB though,
which unfortunately does not seem possible given the current restriction in the
Unmarshaller.

If anyone else feels that this is an issue, please add your comments, as they
can be used by Christoph Brunner to convince SUN to take some action there.

cheers, Heiko


Heiko Sommer写道:
Heiko Sommer wrote:
(a)用户输入复杂数据进入内部使用JAXB类的应用程序。要去午餐休息等,用户希望保存他的工作,即使他或她尚未完成,因此数据可能对于模式无效。尽管如此,它应该可以将数据暂时以XML格式存储在磁盘上或数据库中。
(a) a user enters complex data into an application that internally
works with JAXB classes. To go for lunch break etc., the user wants
to save his work, even though he or she is not yet done, so the data
will likely not be valid with respect to the schema. Nonetheless it
should be possible to store the data temporarily as XML on disk or in
a database.




我能理解这样的功能如何从最终用户的角度来看是有用的,但是我不相信程序员应该合理地期望来自JAXB的任何帮助。简单地用

序列化对象以保存工作的数据有什么问题?



I can understand how such a feature is useful from an end-users point of
view, but I am not convinced that the programmer should reasonably expect
any help from JAXB. What is wrong with simply serialising the object with
the data to save the work?


嗯,你需要两种机制,Java序列化和XML编组。

作为开发人员,我会更乐意有一种通用且简单的方法来序列化我的

对象树,从那以后无论如何,这是关于XML的,额外的Java序列化

似乎很麻烦。

如果你依赖某些XML技术,比如XML数据库,那就更糟了。

任何网络服务都喜欢。它不容易接受本机序列化Java对象。

Steve Slatcher写道:
well, you''ll need two mechanisms, Java serialization and XML marshalling.
As a developer, I''d be happier to have one common and easy way to serialize my
object tree, and since this is about XML anyway, additional Java serialization
seems like a bother.
It gets worse if you depend on some XML technology, like an XML database or
anything web service like. It won''t easily accept native serialized Java objects.

Steve Slatcher wrote:
我可以理解这样的功能对最终用户有用吗
观点,但我不相信程序员应该合理地期望来自JAXB的任何帮助。简单地使用数据序列化对象以保存工作有什么问题?
I can understand how such a feature is useful from an end-users point of
view, but I am not convinced that the programmer should reasonably expect
any help from JAXB. What is wrong with simply serialising the object with
the data to save the work?






这篇关于JAXB:为unmarshaller提供更强大的功能。请评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆