ActionScript/Flex ArrayCollection of Number 对象到 Java Collection使用 BlazeDS
我正在使用 Flex 3,并通过 RemoteObject 调用 Java 1.6 方法,并通过 SecureAMFChannel 通过 BlazeDS 和 Spring 2.5.5 集成进行公开。 ActionScript 如下(此代码是位于单独开发网络上的真实示例);
import com.adobe.cairngorm.business.ServiceLocator;
import mx.collections.ArrayCollection;
import mx.rpc.remoting.RemoteObject;
import mx.rpc.IResponder;
public class MyClass implements IResponder
{
private var service:RemoteObject = ServiceLocator.getInstance().getRemoteOjbect("mySerivce");
public MyClass()
{
[ArrayElementType("Number")]
private var myArray:ArrayCollection;
var id1:Number = 1;
var id2:Number = 2;
var id3:Number = 3;
myArray = new ArrayCollection([id1, id2, id3]);
getData(myArray);
}
public function getData(myArrayParam:ArrayCollection):void
{
var token:AsyncToken = service.getData(myArrayParam);
token.addResponder(this.responder); //Assume responder implementation method exists and works
}
}
一旦创建了通过 BlazeDS 公开的服务 Java 类,这将进行一次调用(假设该机制有效,因为它们适用于所有其他不涉及 Collection 参数的调用)。我的 Java 服务类如下所示;
public class MySerivce {
public Collection<DataObjectPOJO> getData(Collection<Long> myArrayParam) {
//The following line is never executed and throws an exception
for (Long l : myArrayParam) {
System.out.println(l);
}
}
}
抛出的异常是 ClassCastException,表明 java.lang.Integer 无法转换为 java.lang.Long。我通过使用 Object 循环遍历集合来解决这个问题,检查它是否是一个 Integer,将其转换为 1,然后对其执行 .longValue() ,然后将其添加到临时 ArraList 中。哎呀。
最大的问题是我的应用程序应该处理数据库中的数十亿条记录,而 id 将溢出整数的 21.47 亿条限制。我希望其中有 BlazeDS 或 JavaAdapter,将 ActionScript Number 转换为方法中指定的 Long。我讨厌即使我使用泛型,集合的底层元素类型也是整数。如果这是直接的 Java,它就无法编译。
任何想法表示赞赏。解决方案甚至更好! :)
I am using Flex 3 and make a call through a RemoteObject to a Java 1.6 method and exposed with BlazeDS and Spring 2.5.5 Integration over a SecureAMFChannel. The ActionScript is as follows (this code is an example of the real thing which is on a separate dev network);
import com.adobe.cairngorm.business.ServiceLocator;
import mx.collections.ArrayCollection;
import mx.rpc.remoting.RemoteObject;
import mx.rpc.IResponder;
public class MyClass implements IResponder
{
private var service:RemoteObject = ServiceLocator.getInstance().getRemoteOjbect("mySerivce");
public MyClass()
{
[ArrayElementType("Number")]
private var myArray:ArrayCollection;
var id1:Number = 1;
var id2:Number = 2;
var id3:Number = 3;
myArray = new ArrayCollection([id1, id2, id3]);
getData(myArray);
}
public function getData(myArrayParam:ArrayCollection):void
{
var token:AsyncToken = service.getData(myArrayParam);
token.addResponder(this.responder); //Assume responder implementation method exists and works
}
}
This will make a call, once created to the service Java class which is exposed through BlazeDS (assume the mechanics work because they do for all other calls not involving Collection parameters). My Java service class looks like this;
public class MySerivce {
public Collection<DataObjectPOJO> getData(Collection<Long> myArrayParam) {
//The following line is never executed and throws an exception
for (Long l : myArrayParam) {
System.out.println(l);
}
}
}
The exception that is thrown is a ClassCastException saying that a java.lang.Integer cannot be cast to a java.lang.Long. I worked around this issue by looping through the collection using Object instead, checking to see if it is an Integer, cast it to one, then do a .longValue() on it then add it to a temp ArraList. Yuk.
The big problem is my application is supposed to handle records in the billions from a DB and the id will overflow the 2.147 billion limit of an integer. I would love to have BlazeDS or the JavaAdapter in it, translate the ActionScript Number to a Long as specified in the method. I hate that even though I use the generic the underlying element type of the collection is an Integer. If this was straight Java, it wouldn't compile.
Any ideas are appreciated. Solutions are even better! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请阅读以下与您的问题相关的主题。您可以在那里找到一些解决方法。
https://bugs.adobe.com/jira/browse/BLZ-115
https://bugs.adobe.com/jira/browse/BLZ-305
Please read the following threads related to your issue. You can find there some workarounds.
https://bugs.adobe.com/jira/browse/BLZ-115
https://bugs.adobe.com/jira/browse/BLZ-305
您还可以更改 Java 端的参数以期望
Long[]
而不是Collection
。由于本机 Java 数组是强类型的,因此它可以正确反序列化。You can also change the argument on the Java side to expect a
Long[]
rather than aCollection<Long>
. Because the native Java array is strongly typed, it deserializes correctly.Flex 将
Number
的ArrayCollection
序列化为 Java 中的ArrayCollection
。由于 Adobe 的
ArrayCollection
< /a> 扩展ArrayList
,您可以通过以下函数运行Collection
。这应该会生成一个包含Long
值的List
。番石榴:)
Flex serializes an
ArrayCollection
ofNumber
s to anArrayCollection<Integer>
in Java.Since Adobe's
ArrayCollection
extendsArrayList
, you can run theCollection
through the following function. This should produce aList
ofLong
values.Guava :)