You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2010/11/26 16:35:34 UTC

svn commit: r1039419 - in /pivot/trunk: core/src/org/apache/pivot/json/ core/src/org/apache/pivot/util/ core/test/org/apache/pivot/json/test/ tests/src/org/apache/pivot/tests/

Author: gbrown
Date: Fri Nov 26 15:35:33 2010
New Revision: 1039419

URL: http://svn.apache.org/viewvc?rev=1039419&view=rev
Log:
Make typed sequence and dictionary serialization more robust in JSONSerializer; fix minor issue in alert/prompt test code.

Added:
    pivot/trunk/core/test/org/apache/pivot/json/test/TestBean2Dictionary.java
    pivot/trunk/core/test/org/apache/pivot/json/test/TestBean2List.java
    pivot/trunk/core/test/org/apache/pivot/json/test/TestBean2Map.java
    pivot/trunk/core/test/org/apache/pivot/json/test/TestBean2Sequence.java
Modified:
    pivot/trunk/core/src/org/apache/pivot/json/JSONSerializer.java
    pivot/trunk/core/src/org/apache/pivot/util/TypeLiteral.java
    pivot/trunk/core/test/org/apache/pivot/json/test/BindTest.java
    pivot/trunk/tests/src/org/apache/pivot/tests/alert_prompt_test.bxml

Modified: pivot/trunk/core/src/org/apache/pivot/json/JSONSerializer.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/json/JSONSerializer.java?rev=1039419&r1=1039418&r2=1039419&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/json/JSONSerializer.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/json/JSONSerializer.java Fri Nov 26 15:35:33 2010
@@ -30,6 +30,7 @@ import java.io.StringWriter;
 import java.io.Writer;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
 import java.nio.charset.Charset;
 
 import org.apache.pivot.beans.BeanAdapter;
@@ -485,8 +486,6 @@ public class JSONSerializer implements S
         }
 
         if (integer) {
-            // TODO 5/28/2008 Remove 32-bit optimization when 64-bit processors
-            // are more prevalent
             long value = Long.parseLong(stringBuilder.toString()) * (negative ? -1 : 1);
 
             if (value > Integer.MAX_VALUE
@@ -544,47 +543,78 @@ public class JSONSerializer implements S
     @SuppressWarnings("unchecked")
     private Object readListValue(Reader reader, Type type)
         throws IOException, SerializationException {
-        Sequence<Object> sequence;
-        Type itemType;
+        Sequence<Object> sequence = null;
+        Type itemType = null;
 
-        if (type instanceof ParameterizedType) {
-            ParameterizedType parameterizedType = (ParameterizedType)type;
-            Class<?> rawType = (Class<?>)parameterizedType.getRawType();
-            if (!Sequence.class.isAssignableFrom(rawType)) {
-                throw new IllegalArgumentException("Cannot convert array to "
-                    + rawType.getName() + ".");
+        if (type == Object.class) {
+            // Return the default sequence and item types
+            sequence = new ArrayList<Object>();
+            itemType = Object.class;
+        } else {
+            // Determine the item type from generic parameters
+            Type parentType = type;
+            while (parentType != null) {
+                if (parentType instanceof ParameterizedType) {
+                    ParameterizedType parameterizedType = (ParameterizedType)parentType;
+                    Class<?> rawType = (Class<?>)parameterizedType.getRawType();
+
+                    if (Sequence.class.isAssignableFrom(rawType)) {
+                        itemType = parameterizedType.getActualTypeArguments()[0];
+                        break;
+                    }
+
+                    parentType = rawType.getGenericSuperclass();
+                } else {
+                    Class<?> classType = (Class<?>)parentType;
+                    Type[] genericInterfaces = classType.getGenericInterfaces();
+
+                    for (int i = 0; i < genericInterfaces.length; i++) {
+                        Type genericInterface = genericInterfaces[i];
+
+                        if (genericInterface instanceof ParameterizedType) {
+                            ParameterizedType parameterizedType = (ParameterizedType)genericInterface;
+                            Class<?> interfaceType = (Class<?>)parameterizedType.getRawType();
+
+                            if (Sequence.class.isAssignableFrom(interfaceType)) {
+                                itemType = parameterizedType.getActualTypeArguments()[0];
+
+                                if (itemType instanceof TypeVariable<?>) {
+                                    itemType = Object.class;
+                                }
+
+                                break;
+                            }
+                        }
+                    }
+
+                    if (itemType != null) {
+                        break;
+                    }
+
+                    parentType = classType.getGenericSuperclass();
+                }
+            }
+
+            if (itemType == null) {
+                throw new SerializationException("Could not determine sequence item type.");
+            }
+
+            // Instantiate the sequence type
+            Class<?> sequenceType;
+            if (type instanceof ParameterizedType) {
+                ParameterizedType parameterizedType = (ParameterizedType)type;
+                sequenceType = (Class<?>)parameterizedType.getRawType();
+            } else {
+                sequenceType = (Class<?>)type;
             }
 
             try {
-                sequence = (Sequence<Object>)rawType.newInstance();
+                sequence = (Sequence<Object>)sequenceType.newInstance();
             } catch (InstantiationException exception) {
                 throw new RuntimeException(exception);
             } catch (IllegalAccessException exception) {
                 throw new RuntimeException(exception);
             }
-
-            // Get the target item type
-            Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
-            itemType = actualTypeArguments[0];
-        } else {
-            Class<?> classType = (Class<?>)type;
-
-            if (Sequence.class.isAssignableFrom(classType)) {
-                try {
-                    sequence = (Sequence<Object>)classType.newInstance();
-                } catch (InstantiationException exception) {
-                    throw new IllegalArgumentException(exception);
-                } catch (IllegalAccessException exception) {
-                    throw new IllegalArgumentException(exception);
-                }
-
-                itemType = Object.class;
-            } else if (type == Object.class) {
-                sequence = new ArrayList<Object>();
-                itemType = Object.class;
-            } else {
-                throw new IllegalArgumentException("Cannot convert array to " + type + ".");
-            }
         }
 
         // Notify the listeners
@@ -626,55 +656,85 @@ public class JSONSerializer implements S
     @SuppressWarnings("unchecked")
     private Object readMapValue(Reader reader, Type type)
         throws IOException, SerializationException {
-        Dictionary<String, Object> dictionary;
-        Type valueType;
+        Dictionary<String, Object> dictionary = null;
+        Type valueType = null;
 
-        if (type instanceof ParameterizedType) {
-            // Instantiate the target dictionary
-            ParameterizedType parameterizedType = (ParameterizedType)type;
-            Class<?> rawType = (Class<?>)parameterizedType.getRawType();
-            if (!Dictionary.class.isAssignableFrom(rawType)) {
-                throw new IllegalArgumentException("Cannot convert object to "
-                    + rawType.getName() + ".");
-            }
+        if (type == Object.class) {
+            // Return the default dictionary and value types
+            dictionary = new HashMap<String, Object>();
+            valueType = Object.class;
+        } else {
+            // Determine the value type from generic parameters
+            Type parentType = type;
+            while (parentType != null) {
+                if (parentType instanceof ParameterizedType) {
+                    ParameterizedType parameterizedType = (ParameterizedType)parentType;
+                    Class<?> rawType = (Class<?>)parameterizedType.getRawType();
 
-            try {
-                dictionary = (Dictionary<String, Object>)rawType.newInstance();
-            } catch (InstantiationException exception) {
-                throw new RuntimeException(exception);
-            } catch (IllegalAccessException exception) {
-                throw new RuntimeException(exception);
+                    if (Dictionary.class.isAssignableFrom(rawType)) {
+                        valueType = parameterizedType.getActualTypeArguments()[1];
+                        break;
+                    }
+
+                    parentType = rawType.getGenericSuperclass();
+                } else {
+                    Class<?> classType = (Class<?>)parentType;
+                    Type[] genericInterfaces = classType.getGenericInterfaces();
+
+                    for (int i = 0; i < genericInterfaces.length; i++) {
+                        Type genericInterface = genericInterfaces[i];
+
+                        if (genericInterface instanceof ParameterizedType) {
+                            ParameterizedType parameterizedType = (ParameterizedType)genericInterface;
+                            Class<?> interfaceType = (Class<?>)parameterizedType.getRawType();
+
+                            if (Dictionary.class.isAssignableFrom(interfaceType)) {
+                                valueType = parameterizedType.getActualTypeArguments()[1];
+
+                                if (valueType instanceof TypeVariable<?>) {
+                                    valueType = Object.class;
+                                }
+
+                                break;
+                            }
+                        }
+                    }
+
+                    if (valueType != null) {
+                        break;
+                    }
+
+                    parentType = classType.getGenericSuperclass();
+                }
             }
 
-            // Get the target value type
-            Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
-            valueType = actualTypeArguments[1];
-        } else {
-            Class<?> classType = (Class<?>)type;
-            if (Dictionary.class.isAssignableFrom(classType)) {
+            // Instantiate the dictionary or bean type
+            if (valueType == null) {
+                Class<?> beanType = (Class<?>)type;
+
                 try {
-                    dictionary = (Dictionary<String, Object>)classType.newInstance();
+                    dictionary = new BeanAdapter(beanType.newInstance());
                 } catch (InstantiationException exception) {
-                    throw new IllegalArgumentException(exception);
+                    throw new RuntimeException(exception);
                 } catch (IllegalAccessException exception) {
-                    throw new IllegalArgumentException(exception);
+                    throw new RuntimeException(exception);
                 }
-
-                valueType = Object.class;
-            } else if (type == Object.class){
-                dictionary = new HashMap<String, Object>();
-                valueType = Object.class;
             } else {
-                Class<?> beanType = (Class<?>)type;
+                Class<?> dictionaryType;
+                if (type instanceof ParameterizedType) {
+                    ParameterizedType parameterizedType = (ParameterizedType)type;
+                    dictionaryType = (Class<?>)parameterizedType.getRawType();
+                } else {
+                    dictionaryType = (Class<?>)type;
+                }
+
                 try {
-                    dictionary = new BeanAdapter(beanType.newInstance());
+                    dictionary = (Dictionary<String, Object>)dictionaryType.newInstance();
                 } catch (InstantiationException exception) {
                     throw new RuntimeException(exception);
                 } catch (IllegalAccessException exception) {
                     throw new RuntimeException(exception);
                 }
-
-                valueType = null;
             }
         }
 

Modified: pivot/trunk/core/src/org/apache/pivot/util/TypeLiteral.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/util/TypeLiteral.java?rev=1039419&r1=1039418&r2=1039419&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/util/TypeLiteral.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/util/TypeLiteral.java Fri Nov 26 15:35:33 2010
@@ -34,7 +34,7 @@ import java.lang.reflect.Type;
  * {@code TypeLiteral} class, written by Bob Lee and Jesse Wilson.
  */
 public class TypeLiteral<T> {
-    final Type type;
+    private final Type type;
 
     /**
      * Constructs a new type literal. Derives represented class from type
@@ -45,12 +45,12 @@ public class TypeLiteral<T> {
      * at runtime despite erasure.
      */
     protected TypeLiteral() {
-        Type superclass = getClass().getGenericSuperclass();
-        if (superclass instanceof Class<?>) {
+        Type genericSuperclass = getClass().getGenericSuperclass();
+        if (!(genericSuperclass instanceof ParameterizedType)) {
             throw new RuntimeException("Missing type parameter.");
         }
 
-        ParameterizedType parameterizedType = (ParameterizedType)superclass;
+        ParameterizedType parameterizedType = (ParameterizedType)genericSuperclass;
         this.type = parameterizedType.getActualTypeArguments()[0];
     }
 

Modified: pivot/trunk/core/test/org/apache/pivot/json/test/BindTest.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/test/org/apache/pivot/json/test/BindTest.java?rev=1039419&r1=1039418&r2=1039419&view=diff
==============================================================================
--- pivot/trunk/core/test/org/apache/pivot/json/test/BindTest.java (original)
+++ pivot/trunk/core/test/org/apache/pivot/json/test/BindTest.java Fri Nov 26 15:35:33 2010
@@ -32,6 +32,12 @@ import org.apache.pivot.util.TypeLiteral
 import org.junit.Test;
 
 public class BindTest {
+    /**
+     * Tests returning an untyped list.
+     *
+     * @throws IOException
+     * @throws SerializationException
+     */
     @Test
     public void testUntypedList() throws IOException, SerializationException {
         JSONSerializer listSerializer = new JSONSerializer(ArrayList.class);
@@ -39,6 +45,12 @@ public class BindTest {
         assertEquals(list.get(0), 1);
     }
 
+    /**
+     * Tests returning a typed list using {@code org.apache.pivot.util.TypeLiteral}.
+     *
+     * @throws IOException
+     * @throws SerializationException
+     */
     @Test
     @SuppressWarnings("unchecked")
     public void testTypedList() throws IOException, SerializationException {
@@ -56,24 +68,133 @@ public class BindTest {
         assertEquals(typedList.get(0).getA(), JSON.get(list, "[0].a"));
     }
 
+    /**
+     * Tests returning a subclass of a generic {@code org.apache.pivot.collections.List}.
+     *
+     * @throws IOException
+     * @throws SerializationException
+     */
+    @Test
+    @SuppressWarnings("unchecked")
+    public void testListSubclass() throws IOException, SerializationException {
+        JSONSerializer listSerializer = new JSONSerializer();
+        List<Object> list =
+            (List<Object>)listSerializer.readObject(getClass().getResourceAsStream("list.json"));
+
+        JSONSerializer typedListSerializer = new JSONSerializer(TestBean2List.class);
+        TestBean2List typedList =
+            (TestBean2List)typedListSerializer.readObject(getClass().getResourceAsStream("list.json"));
+
+        Object item0 = typedList.get(0);
+        assertTrue(item0 instanceof TestBean2);
+        assertEquals(typedList.get(0).getA(), JSON.get(list, "[0].a"));
+    }
+
+    /**
+     * Tests returning a class that implements {@code org.apache.pivot.collections.Sequence}.
+     *
+     * @throws IOException
+     * @throws SerializationException
+     */
+    @Test
+    @SuppressWarnings("unchecked")
+    public void testSequence() throws IOException, SerializationException {
+        JSONSerializer listSerializer = new JSONSerializer();
+        List<Object> list =
+            (List<Object>)listSerializer.readObject(getClass().getResourceAsStream("list.json"));
+
+        JSONSerializer sequenceSerializer = new JSONSerializer(TestBean2Sequence.class);
+        TestBean2Sequence sequence =
+            (TestBean2Sequence)sequenceSerializer.readObject(getClass().getResourceAsStream("list.json"));
+
+        Object item0 = sequence.get(0);
+        assertTrue(item0 instanceof TestBean2);
+        assertEquals(sequence.get(0).getA(), JSON.get(list, "[0].a"));
+    }
+
+    /**
+     * Tests returning an untyped map.
+     *
+     * @throws IOException
+     * @throws SerializationException
+     */
     @Test
     @SuppressWarnings("unchecked")
     public void testUntypedMap() throws IOException, SerializationException {
         JSONSerializer mapSerializer = new JSONSerializer(HashMap.class);
-        HashMap<String, ?> map = (HashMap<String, ?>)mapSerializer.readObject(new StringReader("{a:1, b:2, c:3}"));
+        HashMap<String, ?> map = (HashMap<String, ?>)mapSerializer.readObject(new StringReader("{a:1, b:2, c:'3'}"));
         assertEquals(map.get("a"), 1);
     }
 
+    /**
+     * Tests returning a typed map using {@code org.apache.pivot.util.TypeLiteral}.
+     *
+     * @throws IOException
+     * @throws SerializationException
+     */
     @Test
     @SuppressWarnings("unchecked")
     public void testTypedMap() throws IOException, SerializationException {
+        JSONSerializer typedMapSerializer =
+            new JSONSerializer((new TypeLiteral<HashMap<String, TestBean2>>() {}).getType());
+
+        HashMap<String, TestBean2> map =
+            (HashMap<String, TestBean2>)typedMapSerializer.readObject(new StringReader("{foo: {a:1, b:2, c:'3'}}"));
+
+        assertTrue(JSON.get(map, "foo") instanceof TestBean2);
+        assertEquals(JSON.get(map, "foo.c"), "3");
+    }
+
+    /**
+     * Tests returning a subclass of a generic {@code org.apache.pivot.collections.Map}.
+     *
+     * @throws IOException
+     * @throws SerializationException
+     */
+    @Test
+    public void testMapSubclass() throws IOException, SerializationException {
+        JSONSerializer typedMapSerializer = new JSONSerializer(TestBean2Map.class);
+
+        TestBean2Map map =
+            (TestBean2Map)typedMapSerializer.readObject(new StringReader("{foo: {a:1, b:2, c:'3'}}"));
+
+        assertTrue(JSON.get(map, "foo") instanceof TestBean2);
+        assertEquals(JSON.get(map, "foo.c"), "3");
+    }
+
+    /**
+     * Tests returning a class that implements {@code org.apache.pivot.collections.Dictionary}.
+     *
+     * @throws IOException
+     * @throws SerializationException
+     */
+    @Test
+    public void testDictionary() throws IOException, SerializationException {
+        JSONSerializer dictionarySerializer = new JSONSerializer(TestBean2Dictionary.class);
+
+        TestBean2Dictionary dictionary =
+            (TestBean2Dictionary)dictionarySerializer.readObject(new StringReader("{foo: {a:1, b:2, c:'3'}}"));
+
+        assertTrue(JSON.get(dictionary, "foo") instanceof TestBean2);
+        assertEquals(JSON.get(dictionary, "foo.c"), "3");
+    }
+
+    /**
+     * Tests returning a Java bean value.
+     *
+     * @throws IOException
+     * @throws SerializationException
+     */
+    @Test
+    @SuppressWarnings("unchecked")
+    public void testBean() throws IOException, SerializationException {
         JSONSerializer mapSerializer = new JSONSerializer();
         Map<String, Object> map =
             (Map<String, Object>)mapSerializer.readObject(getClass().getResourceAsStream("map.json"));
 
-        JSONSerializer typedMapSerializer = new JSONSerializer(TestBean1.class);
+        JSONSerializer beanSerializer = new JSONSerializer(TestBean1.class);
         TestBean1 typedMap =
-            (TestBean1)typedMapSerializer.readObject(getClass().getResourceAsStream("map.json"));
+            (TestBean1)beanSerializer.readObject(getClass().getResourceAsStream("map.json"));
 
         assertEquals(typedMap.getA(), JSON.get(map, "a"));
         assertEquals(typedMap.getB(), JSON.get(map, "b"));

Added: pivot/trunk/core/test/org/apache/pivot/json/test/TestBean2Dictionary.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/test/org/apache/pivot/json/test/TestBean2Dictionary.java?rev=1039419&view=auto
==============================================================================
--- pivot/trunk/core/test/org/apache/pivot/json/test/TestBean2Dictionary.java (added)
+++ pivot/trunk/core/test/org/apache/pivot/json/test/TestBean2Dictionary.java Fri Nov 26 15:35:33 2010
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.json.test;
+
+import org.apache.pivot.collections.Dictionary;
+import org.apache.pivot.collections.HashMap;
+
+public class TestBean2Dictionary implements Dictionary<String, TestBean2> {
+    private HashMap<String, TestBean2> values = new HashMap<String, TestBean2>();
+
+    @Override
+    public TestBean2 get(String key) {
+        return values.get(key);
+    }
+
+    @Override
+    public TestBean2 put(String key, TestBean2 value) {
+        return values.put(key, value);
+    }
+
+    @Override
+    public TestBean2 remove(String key) {
+        return values.remove(key);
+    }
+
+    @Override
+    public boolean containsKey(String key) {
+        return values.containsKey(key);
+    }
+}

Added: pivot/trunk/core/test/org/apache/pivot/json/test/TestBean2List.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/test/org/apache/pivot/json/test/TestBean2List.java?rev=1039419&view=auto
==============================================================================
--- pivot/trunk/core/test/org/apache/pivot/json/test/TestBean2List.java (added)
+++ pivot/trunk/core/test/org/apache/pivot/json/test/TestBean2List.java Fri Nov 26 15:35:33 2010
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.json.test;
+
+import org.apache.pivot.collections.ArrayList;
+
+public class TestBean2List extends ArrayList<TestBean2> {
+    private static final long serialVersionUID = 0;
+}

Added: pivot/trunk/core/test/org/apache/pivot/json/test/TestBean2Map.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/test/org/apache/pivot/json/test/TestBean2Map.java?rev=1039419&view=auto
==============================================================================
--- pivot/trunk/core/test/org/apache/pivot/json/test/TestBean2Map.java (added)
+++ pivot/trunk/core/test/org/apache/pivot/json/test/TestBean2Map.java Fri Nov 26 15:35:33 2010
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.json.test;
+
+import org.apache.pivot.collections.HashMap;
+
+public class TestBean2Map extends HashMap<String, TestBean2> {
+    private static final long serialVersionUID = 0;
+}

Added: pivot/trunk/core/test/org/apache/pivot/json/test/TestBean2Sequence.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/test/org/apache/pivot/json/test/TestBean2Sequence.java?rev=1039419&view=auto
==============================================================================
--- pivot/trunk/core/test/org/apache/pivot/json/test/TestBean2Sequence.java (added)
+++ pivot/trunk/core/test/org/apache/pivot/json/test/TestBean2Sequence.java Fri Nov 26 15:35:33 2010
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.json.test;
+
+import org.apache.pivot.collections.ArrayList;
+import org.apache.pivot.collections.Sequence;
+
+public class TestBean2Sequence implements Sequence<TestBean2> {
+    private ArrayList<TestBean2> items = new ArrayList<TestBean2>();
+
+    @Override
+    public int add(TestBean2 item) {
+        return items.add(item);
+    }
+
+    @Override
+    public void insert(TestBean2 item, int index) {
+        items.insert(item, index);
+    }
+
+    @Override
+    public TestBean2 update(int index, TestBean2 item) {
+        return items.update(index, item);
+    }
+
+    @Override
+    public int remove(TestBean2 item) {
+        return items.remove(item);
+    }
+
+    @Override
+    public Sequence<TestBean2> remove(int index, int count) {
+        return items.remove(index, count);
+    }
+
+    @Override
+    public TestBean2 get(int index) {
+        return items.get(index);
+    }
+
+    @Override
+    public int indexOf(TestBean2 item) {
+        return items.indexOf(item);
+    }
+
+    @Override
+    public int getLength() {
+        return items.getLength();
+    }
+}

Modified: pivot/trunk/tests/src/org/apache/pivot/tests/alert_prompt_test.bxml
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/alert_prompt_test.bxml?rev=1039419&r1=1039418&r2=1039419&view=diff
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/alert_prompt_test.bxml (original)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/alert_prompt_test.bxml Fri Nov 26 15:35:33 2010
@@ -18,14 +18,17 @@ limitations under the License.
 
 <Window bxml:id="window" title="Alert/Prompt Test" maximized="true"
     xmlns:bxml="http://pivot.apache.org/bxml"
+    xmlns:collections="org.apache.pivot.collections"
     xmlns:content="org.apache.pivot.wtk.content"
     xmlns="org.apache.pivot.wtk">
     <bxml:define>
         <Alert bxml:id="alert" title="My Alert" message="Hello World!">
             <options>
-                <content:ButtonData icon="@bell.png" text="Bell"/>
-                <content:ButtonData icon="@clock.png" text="Clock"/>
-                <content:ButtonData icon="@cup.png" text="Cup"/>
+                <collections:ArrayList>
+                    <content:ButtonData icon="@bell.png" text="Bell"/>
+                    <content:ButtonData icon="@clock.png" text="Clock"/>
+                    <content:ButtonData icon="@cup.png" text="Cup"/>
+                </collections:ArrayList>
             </options>
 
             <TextArea text="This is a text area." editable="false"/>