ActionScript/Flex ArrayCollection of Number 对象到 Java Collection使用 BlazeDS

发布于 2024-08-27 03:39:41 字数 1781 浏览 5 评论 0原文

我正在使用 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 技术交流群。

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

发布评论

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

评论(3

爱要勇敢去追 2024-09-03 03:39:42

请阅读以下与您的问题相关的主题。您可以在那里找到一些解决方法。

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

半世蒼涼 2024-09-03 03:39:42

您还可以更改 Java 端的参数以期望 Long[] 而不是 Collection。由于本机 Java 数组是强类型的,因此它可以正确反序列化。

You can also change the argument on the Java side to expect a Long[] rather than a Collection<Long>. Because the native Java array is strongly typed, it deserializes correctly.

旧夏天 2024-09-03 03:39:42

Flex 将 NumberArrayCollection 序列化为 Java 中的 ArrayCollection

由于 Adob​​e 的 ArrayCollection< /a> 扩展 ArrayList,您可以通过以下函数运行Collection。这应该会生成一个包含 Long 值的 List

public class TransformUtils {
  public static final <T extends Number> List<Long> toLongList(Collection<T> values) {
    List<Long> list = new ArrayList();
    for (T value : values) {
      list.add(value.longValue());
    }
    return list;
  }
}
public class MySerivce {
  public Collection<DataObjectPOJO> getData(Collection<Long> myArrayParam) {
    myArrayParam = TransformUtils.toLongList(myArrayParam);
    for (Long l : myArrayParam) {
      System.out.println(l);
    }
  }
}

番石榴:)

public static final <T extends Number> List<Long> toLongList(Collection<T> values) {
  return Lists.newArrayList(new Function<T, Long>() {
    @Override public Long apply(T value) {
      return value.longValue(); }));}

Flex serializes an ArrayCollection of Numbers to an ArrayCollection<Integer> in Java.

Since Adobe's ArrayCollection extends ArrayList, you can run the Collection through the following function. This should produce a List of Long values.

public class TransformUtils {
  public static final <T extends Number> List<Long> toLongList(Collection<T> values) {
    List<Long> list = new ArrayList();
    for (T value : values) {
      list.add(value.longValue());
    }
    return list;
  }
}
public class MySerivce {
  public Collection<DataObjectPOJO> getData(Collection<Long> myArrayParam) {
    myArrayParam = TransformUtils.toLongList(myArrayParam);
    for (Long l : myArrayParam) {
      System.out.println(l);
    }
  }
}

Guava :)

public static final <T extends Number> List<Long> toLongList(Collection<T> values) {
  return Lists.newArrayList(new Function<T, Long>() {
    @Override public Long apply(T value) {
      return value.longValue(); }));}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文