我可以从单个模型描述创建服务器端 Java 类、OR 映射和客户端 AS 类吗?

发布于 2024-07-24 20:59:40 字数 758 浏览 3 评论 0原文

我有一个 Java 服务器应用程序和一个 Flex 客户端应用程序。 对于我的数据模型,我有典型的对象,例如 User 等,它们在数据库、服务器端 Java 代码和客户端 AS 代码中基本相同。 即,我的 AS 和 Java 类的公共字段的名称相同,并且与数据库表中与这些类同名的相应字段具有相同的类型和值。

为了使 Java 类和数据库表匹配,我可以使用任何 ORM。 是否有任何工具可以从 Java 类自动生成 AS 类(以及理想情况下匹配的 Remoting 样板代码)? 我短暂浏览了 BlazeDS,但似乎没有有这样的工具,至少我找不到任何相关信息。

当然,在完美的世界中,我会描述我的数据项一次,并自动生成 DDL、Java 代码和 AS 代码。 这样的工具是否存在,是否足够可用?

哦,是的,如果源格式可以是 protobuf 文件,那就太好了...

注意: 这似乎与 这个。 那里的答案似乎表明,至少没有“每个人都使用”或享有高质量声誉的通用工具。

I have a Java server application and a Flex client application. For my data model, I have typical objects, like User etc., that are basically the same in the database, the server-side Java code and the client-side AS code. I. e., the public fields of my AS and Java classes are named identically, and have the same types and values as the respective fields in the database table which has the same name as those classes.

For the Java classes and the DB tables to match, I can use any ORM. Are there any tools to have the AS classes (and, ideally, the matching Remoting boilerplate code) autogenerated from the Java ones as well? I had a short look at BlazeDS, but it didn't seem to have tools like that, at least I couldn't find anything about it.

Of course, in a perfect world, I'd describe my data items once and have the DDL, Java code and AS code all autogenerated. Does such a tool exist, and is it usable enough?

Oh yeah, and it would be great if the source format could be protobuf files...

Note: This seems to be the same question as this one. The answers there seem to indicate that at least there's no common tool that "everybody uses" or that has a reputation for high quality.

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

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

发布评论

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

评论(2

摘星┃星的人 2024-07-31 20:59:40

据我所知,用于从服务器代码生成 AS 类的唯一工具是 Flex 构建器中内置的向导,用于从 ColdFusion CFC 自动生成 AS 远程类,以便与基于 ColdFusion 的 AMF 服务一起使用。

不过,记住一点可能有用的是,一旦 Flex 接收到序列化对象并为其创建了 mx.utils.ObjectProxy 实例(这与 flex RemoteObject< /code> 类和基于 AMF 的服务,但我想 Protocol Buffer 扩展会遵循相同的模式),将代理转换为 Actionscript 类的过程并不那么复杂。 只要您的 Actionscript 类具有名称与序列化对象的属性匹配的属性或访问器,以及与序列化对象的类型匹配的远程对象别名,那么您就可以将对象代理强制转换为远程类,而无需执行以下操作任何额外的工作。

就像我说的,我不知道有什么工具可以实现您想要的功能,但是创建一个工具来从 Java 类中读取类型和公共属性,或者从协议中提取相同的元数据并不会太困难。缓冲文件,并根据该元数据编写一些 Actionscript 代码。 如果您找不到适合您需求的解决方案,您可以考虑编写 Ant 任务或脚本或其他东西来为您完成此任务。 无论如何,这就是我会做的。

The only tools that I know of are for generating AS classes from server code are the wizards built into Flex builder for autogenerating AS remote classes from ColdFusion CFC's for use with a ColdFusion based AMF service.

What may be useful to remember though is that once the serialized object has been received by Flex and an instance of mx.utils.ObjectProxy has been created for it (this relates to the flex RemoteObject class and AMF based services, but I imagine that a Protocol Buffer extension would follow the same pattern), the process of casting the proxy to an Actionscript class isn't all that complicated. As long as your Actionscript class has properties or accessors with names that match the properties on the serialized object, and an Remote Object alias that matches the type of the serialized object, then you can cast the object proxy to the remote class without having to do any extra work.

Like I said, I'm not aware of a tool that does what you want, but It wouldn't be too difficult to create a tool to read the type and public properties from your Java classes, or extract that same metadata from your protocol buffer files, and write some Actionscript code off that Metadata. If you can't find a solution that fits your needs, you might consider writing an Ant task or a script or something to do it for you. Thats what I would do anyway.

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