BlazeDS如何生成文件

发布于 2025-01-03 22:06:46 字数 1362 浏览 1 评论 0 原文

我一直在提供一个应用程序,该应用程序使用 Java EE 应用程序作为后端,Flash 作为前端,并使用 BlazeDS 连接两者。我从未使用过 Flash 或 BlazeDS,并且正在尝试了解 BlazeDS 的工作原理。

到目前为止,我了解到当您在 FlashBuilder 中连接到 BlazeDS 时,会扫描 remoting-config.xml 文件以确定 Java 端存在哪些服务。 FlashBuilder 会询问您想要导入哪些服务,以及您想要使用什么“服务包”和“数据类型包”。

当您选择 Java ExampleService 时,BlazeDS 将创建 _Super_ExampleService.asExampleService.as 并将它们放入您的“服务包”位置。 ExampleService.as 是空的,但扩展了 _Super_ExampleService.as(它基本上是一个 Flash 服务,您可以使用它来调用 Java 服务中的方法)。如果您需要添加额外的方法,请将它们添加到 ExampleService.as 中。 (希望这一切都是正确的,如果我错了,请纠正我)

我的问题是我无法弄清楚 BlazeDS 对值对象做了什么。

当您在 FlashBuilder 中选择 ExampleService 时(假设它是 Example 实体的服务),BlazeDS 会创建什么值对象?我希望有 Example.as_SuperExample.as。但是,_ExampleEntityMetadata.as 也会出现。

我的问题基本上是:

  1. BlazeDS 如何确定要创建哪些值对象?它是否扫描数据库、扫描项目中的 @Entity 注释、扫描一些配置文件、扫描服务以确定它使用的对象等?
  2. 这 3 个类分别有什么用途?它看起来与服务的设置相同(如果需要,更改非“_Super”设置),但现在有第三个文件。
  3. 我注意到值对象并不总是直接对应于 Java 实体(具有附加属性、缺少属性等)。这是为什么呢?
  4. 价值对象如何与服务结合使用?

我还有一些一般性问题:

  1. 当您连接到 FlashBuilder 中的服务时,您实际上在做什么?第一次,我想象 BlazeDS 提供了必要的服务和价值对象。但是,如果它们已经存在(假设您已经连接,或者您拉下代码并第一次连接)怎么办?连接是否只会使您的 FlashBuilder 副本中的服务可用?
  2. 是否保证 BlazeDS 始终以相同的方式生成服务和值对象?喜欢一行接一行吗?

I've been giving a application to work on that uses a Java EE application for the backend, Flash for the front end, and BlazeDS to connect the two. I have never used Flash or BlazeDS, and am trying to get my head around how BlazeDS works.

So far, I understand that when you connect to BlazeDS in FlashBuilder, the remoting-config.xml file is scanned to determine what services exist on the Java end. FlashBuilder asks which of these services you want to import, and what "service package" and "data type package" you want to use.

When you select your Java ExampleService, BlazeDS will create _Super_ExampleService.as and ExampleService.as and put them in your "service package" location. ExampleService.as is empty but extends _Super_ExampleService.as (which basically is a Flash service that you can use to call the methods in your Java service). If you need to add extra methods, you would add them to ExampleService.as. (Hopefully this is all correct, please correct me if I'm wrong)

My problem is I cannot figure out what BlazeDS does for value objects.

When you select ExampleService in FlashBuilder (let's assume it's a service for the Example entity), what value objects does BlazeDS create? I would expect Example.as and _SuperExample.as. However, _ExampleEntityMetadata.as also appears.

My questions are basically:

  1. How does BlazeDS determine what value objects to create? Does it scan the DB, scan the project for @Entity annotations, scan some config file, scan the service to determine what objects it works with, etc?
  2. What purpose does each of the 3 classes serve? It looks like the same setup with the service (change the non-"_Super" one if needed), but there is now that 3rd file.
  3. I noticed the value objects do not always correspond directly to the Java entities (has additional properties, missing properties, etc). Why is this?
  4. How are the value objects used in conjunction with the services?

I also had some general questions:

  1. When you connect to a service in FlashBuilder, what are you actually doing? The first time, I imagine BlazeDS makes the necessary services and value objects. But what if they're already there (say you already connected, or you pulled down code and connected for the first time)? Does connecting just make the services available in your copy of FlashBuilder?
  2. Is it guaranteed that BlazeDS will always generate the services and value objects the same way? Like line for line?

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

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

发布评论

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

评论(2

橘虞初梦 2025-01-10 22:06:46

这里很少有混淆。 Blaze 的作用如下:

  1. 实现 AMF 格式(这是用于序列化 Flash 对象的本机 Flash 格式)。这样它就知道如何写入和读取 Flash 对象。

  2. 实现了 Flex 框架所需的一些扩展功能(这实际上是一件坏事,因为它写得不好,而且你永远不需要它,但这是一个完全独立的故事)。例如,它提供了一系列类来模仿 Java 中的 Flex 类似物,在 Flex 方面,它模仿地图、树等(甚至永远不要尝试使用它们)。

  3. 创建一个特殊的处理程序,该处理程序将由您的 Web 服务器(Tomcat、JBoss 等)加载并处理来自 Flash 的传入连接。该处理程序在每个会话中实例化 - 无论这在您的上下文中意味着什么。该处理程序也称为 FlexHandler(这通常是它在配置文件中出现的方式)。

Blaze 不做什么:

  1. 它不生成源文件(不生成值对象源 - 您必须自己执行)。但是它有一些常用的类型 - 所有数字类型、字符串、布尔值、一些集合等。

  2. 它不会反映现有代码,也不会集成到 Flash Builder 中。执行此操作的程序称为 Fiber,它由 Adob​​e 提供(同一来源),但它是完全不同的东西,它是专有产品,它追求其他目标(例如,它可以为 Java 以外的语言生成代码)。

Fiber 主要是一个实验产品,它是在 Flash Builder 4 中引入的(大约一年前),目前还非常原始。基本上,它仅用作说明或概念证明,但尚未在现场进行测试(并且很难找到志愿者:)

remoting-config.xml 不是任何类型的特殊名称,但是,凭借一个很多人复制的示例,该名称可以被识别为 services-config.xml 的一部分(该名称同样没有特殊含义并且可以更改,但是,通常通过该名称来引用它)。这些文件有双重目的。当编译 Flex 应用程序时,Flex 编译器可以使用这些文件来为 RemoteObject 创建一些默认设置(您可能不想这样做,除非您对自己正在做的事情非常有信心,但即使如此,你可能不想这样做......)。另一方面,FlexHandler(上面提到的)使用这些设置来了解 Flash 客户端应该连接到哪里。后者是一个特别困难的主题,因为不可能以理智的方式调试 Blaze 代码,并且很难发现基本 URL 到底是什么等。幸运的是,您可以替换这个胡言乱语: 以及一些更有意识的内容,例如 (即无需搜索 server.nameserver.port 的值 - 它 确实很难找到,

从长远来看,Fiber 生成的类(EntityMetadata、_SuperXxx 等) 这是对 Java 代码进行反思并将一些类似逻辑灌输到 AS3 中的尝试。唉,写这些代码的人根本不知道。 AS3 是如何工作的 - 那么发生的事情纯粹是疯狂的。

在将 Java 值对象转换为 Flash 时有一些规则:

  1. 在任何一侧,您都可以添加更多另一侧不存在的属性。 Blaze 不会填充它们(显然),但这些属性将存在并且可用。缺点是 - 双方都会出现一堆 rutnime 错误(被抑制)。为了避免这种情况,在 AS3 端,您可以将不需要的属性标记为 [Transient]。但是,在这样做之前请三思——这是糟糕设计的标志。理想情况下,您不需要这个。我不知道 Java 中的 Transient 类似物是什么。

  2. 您不能拥有名称相同但类型不同的属性 - 不会抑制此类错误。

  3. 传统上,布尔类型的 Java 属性被命名为 isSomething - 对于 Blaze,您必须例外,或者如果您愿意,则将它们命名为 (get|set)IsSomething坚持...

当 Blaze 调用作为服务处理程序的 Java 函数时,Blaze 在 Java 端创建值对象。显然,它们作为处理程序的参数出现。值对象是由 Flash 播放器本身在 Flash 端创建的 - 这会产生某些问题,例如 - 无法传递枚举器 - 无论如何它都会尝试调用 AS3 类上的构造函数。不允许使用非默认构造函数参数。

当您连接到 Flash Builder 中的服务时 - 请不要这样做。没有人真正知道你到底在做什么。该代码是专有的,并且没有做出有关功能冻结等的承诺。截至今天,对于能够编程的人来说,通过鼠标单击以外的方式实际编写程序代码要容易得多,而不是通过逐步向导的方式来完成。

Blaze 仅在运行时生成值对象 - 您几乎可以肯定这一点。这是可以预见的,如果发生重大变化,您肯定会收到通知:) Blaze 不生成源代码。

There are few confusions here. What Blaze does is as follows:

  1. Implements AMF format (this is the native Flash format for serializing Flash objects). So that it knows how to write and read Flash objects.

  2. Implements some extended functionality required for Flex framework (which is actually a bad thing because it's poorly written and you never need it, but that's a whole separate story). For example it provides series of classes to mimic their Flex analogues in Java and on the Flex side it mimics maps, trees and so on (never even try to use that).

  3. Creates a special handler(s) that will be loaded by your web server (Tomcat, JBoss etc) and handle the incoming connection from Flash. This handler is instantiated per session - whatever that means in your context. This handler is also known as FlexHandler (this is how it usually appears in the configuration files).

What Blaze doesn't do:

  1. It doesn't generate source files (no value object sources are generated - you must do it on your own). However it has some commonly used types - all numeric types, strings, booleans, some collections etc.

  2. It doesn't reflect on the existing code and doesn't integrate into Flash Builder. The program that does it is called Fiber, it is provided by Adobe (same source), but it is entirely different thing, it is a proprietary product, it pursues other goals (it can generate code for languages other then Java for example).

Fiber is mostly an experimental product, it was introduced in Flash Builder 4 (that is about a year ago), and it is currently extremely raw. Basically it is only useful as an illustration, or a proof of concept, but it hasn't been tested in the field (and it's hard to find volunteers :)

remoting-config.xml is not a special name of any kind, however, by the virtue of an example that many a lot copied from, the name is recognizable as a part of services-config.xml (the name, again, has no special meaning and can be changed, however, it's commonly referred to by this name). These files have dual purpose. When Flex application is compiled, these files can be used by Flex compiler in order to create some default setups for RemoteObject (you probably don't want to do it that way, unless you are really confident about what you are doing, but even then, you wouldn't probably want to do it that way...). On the other hand, these settings are used by the FlexHandler (mentioned above) in order to know where should it expect Flash client to connect. The later is a particularly difficult subject because it's impossible to debug Blaze code in a sane way, and it's very difficult to discover what exactly the base URL is etc. Luckily for you, you can replace this abracadabra: <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" with something more conscious like <endpoint url="http://server-name/gateway" (i.e. no need to search for the values of server.name and server.port - it is really very difficult to find where they are hiding.

The classes generated by Fiber (EntityMetadata, _SuperXxx and so on) are, by the long run, harmful. It is an attempt to reflect on Java code and to instill some similar logic into AS3 code. Alas, people who wrote that had no clue as to how AS3 works - so what happens there is pure madness.

There are certain rules in how you translate Java value object into Flash:

  1. On any one side you can add more properties that don't exist on the other side. Blaze won't populate them (obviously), but the properties will exist and will be available. The drawback is - you'll get a bunch of rutnime errors (suppressed) on both sides. In order to avoid this, on AS3 side you can mark an unwanted property as [Transient]. But, think twice before you do that - this is a sign of bad design. Ideally, you shouldn't need this. I don't know what the Java analogue of Transient is.

  2. You cannot have a property with the same name, but different type - this kind of errors is not suppressed.

  3. Traditionally for Java properties of Boolean type are named isSomething - for Blaze you'll have to make an exception, or name them (get|set)IsSomething if you insist...

Value objects are created by Blaze on the side of Java, when it invokes the Java functions that are meant to be the service handlers. They, obviously, appear as arguments to the handlers. Value objects are created on Flash side by Flash player itself - this creates certain problems, such as - no way to pass enumerators - it will attempt to call constructor on AS3 class anyway. No non-default constructor arguments are allowed.

When you connect to service in Flash Builder - please don't do it. No one actually knows what exactly you are doing. The code is proprietary and no promise about feature freeze etc has been made. As of today, it is much easier for someone who can program, by means other then mouse clicking, to actually write the program code, rather then do it in a step-by-step wizard way.

Blaze only generates value objects at run time - you can be almost certain about that. It is predictable and if there will come a major change, you will be surely notified :) Blaze does not generate source code.

焚却相思 2025-01-10 22:06:46

我最终只是在亚马逊上购买了一本 Kindle 图书,并阅读了其中的一些内容章节(特别是第 26 章)。以下是我了解到的基本情况:

  • 随着时间的推移,Adobe 产品不断发展和分离,直到“生命周期数据服务”(LCDS) 建立。该技术位于服务器上并提供各种功能。
  • Adobe 发布了“BlazeDS”作为 LCDS 的免费版本(功能较少)。
  • 我使用的 BlazeDS 的功能是“远程服务”(还有“消息服务”和“代理服务”)。远程处理服务允许您从 Flash 前端调用 Java 服务方法。数据通过称为“操作消息格式”(AMF) 的二进制格式在 Flash 和 Java 之间传递。
  • 摘要 BlazeDS 位于服务器上,允许 Flash 和 Java 通过 AMF 进行通信。

为了能够在 Flash 中调用 Java 方法,请执行以下操作(注意:我假设默认命名):

  • 创建一个普通的 Java POJO(一些限制:需要默认构造函数、方法必须是公共的才可用等)。
  • remoting-config.xml 中,添加服务的目标。您会注意到有一个名为 my-amf 的频道。如果查看 services-config.xml,您将看到相应的通道定义,它使用 AMF 并指向正在运行的应用程序(使用动态表达式)。
  • 配置 Flash Builder 项目时,您需要提供 Web 应用程序的位置,以便它知道应该将请求发送到哪里。
  • 摘要 您可以通过以下方式允许 Java 通信:创建 Java 服务,在 remoting-config.xml 中配置它,并让 Flash 项目知道您的 Web 应用程序位置(以便它知道在哪里找到 Java 对象)。

此时,您可以在 MXML 或 ActionScript 中手动调用服务,如下所示(假设我们在 Java 中有一个 ExampleService 映射为 remoting-config.xml 中的 exampleService)。 xml)。

//MXML
<s:RemoteObject id="myExampleService" destination="exampleService" />
<s:Button label="Call a Method" click="myExampleService.myMethod()" />

//ActionScript
var myExampleService:RemoteObject = new RemoteObject("exampleService");
myExampelService.myMethod();

*注意:关于上述内容(以及类似的事情)还有很多东西需要学习,比如处理结果等。但我不会深入讨论。

现在,要在 Flash 和 Java 之间连接并传递数据,它会被序列化。从 Flash 类型到 Java 类型的转换并不完美。例如,Flash Array 会变成 Java List/Map。 Java List/Map 会变成 Flash ArrayCollection/Object。因此,您可以使用“值对象”设计模式。基本上,您创建一个 Flash 对象来镜像您的服务处理的 Java 对象。因此,如果您有一个 Example Java 类,您可能会创建一个 ExampleVO Flash 类。您需要使用 [RemoveClass(alias="my.package.Example")] 等注释 Flash 类。

不过,为了使工作更轻松,您可以自动生成这些文件。 BlazeDS 通过“远程开发服务”(RDS) 协议与 Flash Builder 进行通信。在 web.xml 文件中,您可以启用 RDSDispatchServlet。启用 RDS 后,您可以在 Flash Builder 中建立数据连接(数据 > 连接到 BlazeDS)。

并且,作为问题的答案,本书指出:

默认情况下,如果 Java 类的公共方法返回强类型的实例,
类型化值对象类,连接向导创建匹配的 ActionScript
值对象类。将服务器端数据转换为 ActionScript 值
对象在运行时发生并由生成的代码管理。

I ended up just buying a Kindle book on Amazon and reading through some of the chapters (specifically, chapter 26). Here is basically what I learned:

  • Over the course of time, Adobe products evolved and separated until "LifeCycle Data Services" (LCDS) was established. This technology sits on the server and provides various features.
  • Adobe released "BlazeDS" as a free version of LCDS (with fewer features).
  • The feature that I am using of BlazeDS is the "Remoting Service" (there is also the "Message Service" and "Proxy Service"). The remoting service allows you to call Java service methods from your Flash front end. Data is passed between Flash and Java via a binary format called "Action Message Format" (AMF).
  • SUMMARY BlazeDS sits on the server and allows Flash and Java to communicate via AMF.

In order to be able to call the Java methods in Flash, do the following (note: I assumed default naming):

  • Create a normal Java POJO (some restrictions: need a default constructor, methods must be public to be available, etc).
  • In remoting-config.xml, add a destination for the service. You'll notice there is a channel called my-amf. If you look in services-config.xml, you'll see the corresponding channel definition and that it uses AMF and points to your running application (using dynamic expressions).
  • When configuring the Flash Builder project, you provide the location of your web application so it knows where it's suppose to send requests to.
  • SUMMARY You allow Java communications by creating your Java service, configuring it in remoting-config.xml, and letting your Flash project know your webapp location (so it can know where to find the Java objects).

At this point, you can call your services manually in MXML or ActionScript, like below (assume we have an ExampleService in Java mapped as exampleService in remoting-config.xml).

//MXML
<s:RemoteObject id="myExampleService" destination="exampleService" />
<s:Button label="Call a Method" click="myExampleService.myMethod()" />

//ActionScript
var myExampleService:RemoteObject = new RemoteObject("exampleService");
myExampelService.myMethod();

*Note: There is much more to learn about the above (and similar things), like handling results, etc. But I won't get into that.

Now, to connect to pass data between Flash and Java, it becomes serialized. The conversion from Flash types to Java types is not perfect. For example, a Flash Array turns into a Java List/Map. And a Java List/Map turns into a Flash ArrayCollection/Object. Because of this, you can use a "value object" design pattern. Basically, you create a Flash object that mirrors a Java object that your services deal with. So if you had an Example Java class, you would create maybe a ExampleVO Flash class. You'd need to annotate the Flash class with [RemoveClass(alias="my.package.Example")], etc.

To make life easier however, you can automatically generate these files. BlazeDS communicates with Flash Builder via "Remote Development Service" (RDS) protocol. In your web.xml file, you can enable a RDSDispatchServlet. Once RDS is enabled, you can make data connections in Flash Builder (Data > Connect to BlazeDS).

And, as an answer to the question, the book states:

By default, if a Java class's public method returns an instance of a strongly
typed value object class, the connection wizard creates a matching ActionScript
value object class. The conversion of the server-side data to ActionScript value
object happens at runtime and is managed by the generated code.

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