使用JAXB接口实现EJB - XML [英] Intefacing EJB - XML using JAXB interface

查看:118
本文介绍了使用JAXB接口实现EJB - XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将XML模式添加到现有的EJB项目中。 JAXB用于将XML模式绑定到Java类。当我们打算使用搜索引擎在EJB进行会话时抓取DTO。

I was trying to add the XML schema to an existing EJB project. JAXB is used to bind the XML-Schema to a Java class. As we are going to use the search engine to crawl through DTO when EJB is in session.

我找不到任何直接方法来将实体类文件映射到XML-架构。

I could not find any direct approach as to map entity class file to XML-Schema.

到目前为止,我们唯一可以实现的方法是创建Web服务,生成生成xml-schema(XSD)的WSDL,然后通过JAXB解析XSD文件xjc命令)来创建java类文件。现在使用mapping-binding.xml文件,我们可以映射XML和Java类文件。

The only way we could achieve so far is to create the Web Services, generate the WSDL which generates xml-schema (XSD) and then parsing the XSD file thru JAXB (xjc command) to create java class files. Now using mapping-binding.xml file we can map both XML and Java class file.

但现在再次问题是如何将这个映射到实体类。

But now again the issue is to how map this to entity class.

这是我们想要实现的:


  • XML数据对象与XML模式(这已经存在于JAXB规范中)。

  • 实体Bean然后扩展或具有此JAXB对象的接口。

  • 所有Persistence函数都由Entity Bean管理...

  • 然后,Entity Bean将包含JAXB中的XML编组和UnMarshalling功能。

  • 可以从实体Bean对象以二进制或XML格式检索Value对象。

  • JSP可以轻松地从Value对象中提取XML模式和XML数据,并对其执行操作,如XSL转换。

  • XML Data Object with XML Schema, (This is already present in the JAXB specification).
  • Entity Bean then Extends or has an interface to this JAXB object.
  • All Persistence functions are managed by the Entity Bean...
  • The Entity Bean would then contain the XML Marshalling and UnMarshalling features found in JAXB..
  • A Value Object could be retrieved in binary or XML form from the Entity Bean Object.
  • A JSP could easily extract the XML Schema and XML Data from the Value Object and perform operations on it such as XSL transformations.

我的观点是实体Bean没有标准的方式来连接到JAXB对象。

My argument is that the Entity Beans have no standard way for interfacing to JAXB objects.

Castor可能是解决方案,但是再次,我们必须实现Web服务或使用castor JDO。

Castor may be the solution, but then again we have to implement web services or using castor JDO’s.

我发现XStream在使用时非常有用一个转换器类,您可以在其中调用实体bean类对象并生成一个xml文件。但是我不喜欢使用另一个类,而是在现有的bean类中包含这些功能。

I found XStream to be pretty useful as it uses a converter class in which you can call the entity bean class objects and generate a xml file. But I was not preferring to use another class but incorporate the functions in existing bean class.

你可以在这方面帮助我吗?

Can you help me in this regard?

我会告诉你我实际想要实现的目标。我正在创建一个搜索引擎,在EJB会话期间将被引用,并通过DTO使用抓取工具,并以XML格式获取快照。搜索将是不同的标准。

I will tell you what I am actually trying to achieve. I'm creating a search engine which will be evoked during the EJB in session and will use crawler thru the DTO's and get the snapshot in XML format. Search will be on different criteria.

Lucene是搜索引擎工具之一,但它使用自己的属性和文件(将更像独立的行为)

Lucene is one of the search engine tools but then it uses its own properties and files (will act more like standalone)

我已经有DTO被网络服务用于PHP和Java应用程序(EJB层)。我想重新使用jaxb中的DTO作为一个爬行器,从XML中获取输出,我不能做,因为JAXB通过xml-schema使用自己生成的类。就像你说我还没有找到一种方法来指示JAXB的bean类。

I already have DTO's which are used by webservices to communicate between PHP & Java application (EJB-layer). I wanted to re-use those DTO's in jaxb as a crawler to get the output from tables in XML which I am not able to do as JAXB uses its own generated classes thru xml-schema. Like you said I have yet not found a way to instruct JAXB to bean classes.

推荐答案

紧密耦合你的数据模型)到您的XML界面可能不是世界上最好的主意;它阻止你改变一个,而不改变另一个。

Tightly coupling your data model (entity beans) to your XML interface might not be the best idea in the world; it prevents you from changing one without changing the other.

我不是100%肯定我明白你想要做什么,但我认为有一种方法指示JAXB扩展类而不是创建新类。您可以正常创建您的实体Bean,并将您的JAXB生成的bean扩展到具有额外信息的bean。

I'm not 100% sure I understand what you are trying to do, but I think there is a way to instruct JAXB to extend classes rather than create new ones. You could create your Entity Beans as normal, and have your JAXB-generated beans extend those with the extra information.

我可以说,从某个地方获取Entity beans实例>其他比您的持久层(例如从XML反序列化)将成为您的巨大的问题。

I can say that getting Entity beans instances from somewhere other than your persistence layer (such as deserializing them from XML) is going to be a huge problem for you.

还要注意,使用XML在Java应用程序(例如JSP / Servlet和EJB层之间)之间进行通信是一个坏主意; XML的编组和添加冗长度很少购买;通过RMI(这是EJB将为您做什么)来串行化对象将更容易实施,测试和维护。

Also note that using XML to communicate between Java applications (such as between a JSP/Servlet and EJB layer) is a bad idea; the marshaling and added verbosity of the XML buys you very little; serializing objects via RMI (which is what EJB will do for you) would be much easier to implement, test and maintain.

这篇关于使用JAXB接口实现EJB - XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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