4864117: RFE: Make XMLDecoder API more reusable
Reviewed-by: peterz, loneid
diff --git a/test/java/beans/XMLDecoder/Test4864117.java b/test/java/beans/XMLDecoder/Test4864117.java
new file mode 100644
index 0000000..a3459f9
--- /dev/null
+++ b/test/java/beans/XMLDecoder/Test4864117.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4864117
+ * @summary Tests XMLDecoder within another DefaultHandler for SAX parser
+ * @author Sergey Malenkov
+ */
+
+import java.beans.XMLDecoder;
+import java.beans.ExceptionListener;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.IOException;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+public final class Test4864117 extends DefaultHandler implements ExceptionListener {
+    private static final String TEST = "test";
+    private static final String DATA
+            = "<test>\n"
+            + " <void property=\"message\">\n"
+            + "  <string>Hello, world!</string>\n"
+            + " </void>\n"
+            + "</test>";
+
+    public static void main(String[] args) {
+        Test4864117 test = new Test4864117();
+        InputStream input = new ByteArrayInputStream(DATA.getBytes());
+        Exception error = null;
+        try {
+            SAXParserFactory.newInstance().newSAXParser().parse(input, test);
+        }
+        catch (ParserConfigurationException exception) {
+            error = exception;
+        }
+        catch (SAXException exception) {
+            error = exception.getException();
+            if (error == null) {
+                error = exception;
+            }
+        }
+        catch (IOException exception) {
+            error = exception;
+        }
+        if (error != null) {
+            throw new Error("unexpected error", error);
+        }
+        test.print('?', test.getMessage());
+    }
+
+    private String message;
+
+    public String getMessage() {
+        if (this.message == null) {
+            throw new Error("owner's method is not called");
+        }
+        return this.message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+        print(':', this.message);
+    }
+
+    // DefaultHandler implementation
+
+    private DefaultHandler handler;
+    private int depth;
+
+    @Override
+    public void startDocument() throws SAXException {
+        this.handler = XMLDecoder.createHandler(this, this, null);
+        this.handler.startDocument();
+    }
+
+    @Override
+    public void endDocument() {
+        this.handler = null;
+    }
+
+    @Override
+    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+        print('>', qName);
+        if (this.depth > 0) {
+            this.handler.startElement(uri, localName, qName, attributes);
+        } else if (!TEST.equals(qName)) {
+            throw new SAXException("unexpected element name: " + qName);
+        }
+        this.depth++;
+    }
+
+    @Override
+    public void endElement(String uri, String localName, String qName) throws SAXException {
+        this.depth--;
+        print('<', qName);
+        if (this.depth > 0) {
+            this.handler.endElement(uri, localName, qName);
+        } else if (!TEST.equals(qName)) {
+            throw new SAXException("unexpected element name: " + qName);
+        }
+    }
+
+    @Override
+    public void characters(char[] ch, int start, int length) throws SAXException {
+        this.handler.characters(ch, start, length);
+    }
+
+    public void exceptionThrown(Exception exception) {
+        throw new Error("unexpected exception", exception);
+    }
+
+    private void print(char ch, String name) {
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < this.depth; i++) sb.append(' ');
+        sb.append(ch).append(' ').append(name);
+        System.out.println(sb.toString());
+    }
+}
diff --git a/test/java/beans/XMLDecoder/Test6341798.java b/test/java/beans/XMLDecoder/Test6341798.java
index 2bc43e8..677ff84 100644
--- a/test/java/beans/XMLDecoder/Test6341798.java
+++ b/test/java/beans/XMLDecoder/Test6341798.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2007 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2005-2008 Sun Microsystems, Inc.  All Rights Reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -39,7 +39,7 @@
 
     private static final String DATA
             = "<java>\n"
-            + " <object class=\"TestTurkishLocale$DataBean\">\n"
+            + " <object class=\"Test6341798$DataBean\">\n"
             + "  <void property=\"illegal\">\n"
             + "   <boolean>true</boolean>\n"
             + "  </void>\n"
diff --git a/test/java/beans/XMLDecoder/spec/AbstractTest.java b/test/java/beans/XMLDecoder/spec/AbstractTest.java
new file mode 100644
index 0000000..2b8abb2
--- /dev/null
+++ b/test/java/beans/XMLDecoder/spec/AbstractTest.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+import java.beans.ExceptionListener;
+import java.beans.XMLDecoder;
+
+import java.io.ByteArrayInputStream;
+
+abstract class AbstractTest implements ExceptionListener {
+    public void exceptionThrown(Exception exception) {
+        throw new Error("unexpected exception", exception);
+    }
+
+    /**
+     * Validates the XML decoder for XML archive
+     * that defined in the public field of the subclass.
+     *
+     * @param decoder  the initialized XML decoder
+     * @throws Error if validation failed
+     */
+    protected abstract void validate(XMLDecoder decoder);
+
+    /**
+     * This is entry point to start testing.
+     *
+     * @param security  use {@code true} to start
+     *                  second pass in secure context
+     */
+    final void test(boolean security) {
+        byte[] array = getFieldValue("XML").getBytes(); // NON-NLS: the field name
+        ByteArrayInputStream input = new ByteArrayInputStream(array);
+        XMLDecoder decoder = new XMLDecoder(input);
+        decoder.setExceptionListener(this);
+        validate(decoder);
+        try {
+            throw new Error("unexpected object" + decoder.readObject());
+        } catch (ArrayIndexOutOfBoundsException exception) {
+            // expected exception
+        }
+        decoder.close();
+        if (security) {
+            System.setSecurityManager(new SecurityManager());
+            test(false);
+        }
+    }
+
+    private String getFieldValue(String field) {
+        try {
+            return getClass().getField(field).get(this).toString();
+        } catch (NoSuchFieldException exception) {
+            throw new Error("unexpected exception", exception);
+        } catch (IllegalAccessException exception) {
+            throw new Error("unexpected exception", exception);
+        }
+    }
+}
diff --git a/test/java/beans/XMLDecoder/spec/TestArray.java b/test/java/beans/XMLDecoder/spec/TestArray.java
new file mode 100644
index 0000000..7ae34a1
--- /dev/null
+++ b/test/java/beans/XMLDecoder/spec/TestArray.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary Tests <array> element
+ * @author Sergey Malenkov
+ */
+
+import java.beans.XMLDecoder;
+import java.lang.reflect.Array;
+
+public final class TestArray extends AbstractTest {
+    public static final String XML
+            = "<java>\n"
+            + " <array class=\"java.lang.Number\">\n"
+            + "  <byte>-111</byte>\n"
+            + "  <long>1111</long>\n"
+            + " </array>\n"
+            + " <array length=\"3\">\n"
+            + "  <void index=\"1\">\n"
+            + "   <string>Hello, world!</string>\n"
+            + "  </void>\n"
+            + " </array>\n"
+            + "</java>";
+
+    public static void main(String[] args) {
+        new TestArray().test(true);
+    }
+
+    @Override
+    protected void validate(XMLDecoder decoder) {
+        Number[] numbers = getArray(Number.class, 2, decoder.readObject());
+        if (!numbers[0].equals(Byte.valueOf("-111"))) { // NON-NLS: hardcoded in XML
+            throw new Error("unexpected byte value");
+        }
+        if (!numbers[1].equals(Long.valueOf("1111"))) { // NON-NLS: hardcoded in XML
+            throw new Error("unexpected long value");
+        }
+
+        Object[] objects = getArray(Object.class, 3, decoder.readObject());
+        if (objects[0] != null) {
+            throw new Error("unexpected first value");
+        }
+        if (!objects[1].equals("Hello, world!")) { // NON-NLS: hardcoded in XML
+            throw new Error("unexpected string value");
+        }
+        if (objects[2] != null) {
+            throw new Error("unexpected last value");
+        }
+    }
+
+    private static <T> T[] getArray(Class<T> component, int length, Object object) {
+        Class type = object.getClass();
+        if (!type.isArray()) {
+            throw new Error("array expected");
+        }
+        if (!type.getComponentType().equals(component)) {
+            throw new Error("unexpected component type");
+        }
+        if (length != Array.getLength(object)) {
+            throw new Error("unexpected array length");
+        }
+        return (T[]) object;
+    }
+}
diff --git a/test/java/beans/XMLDecoder/spec/TestBoolean.java b/test/java/beans/XMLDecoder/spec/TestBoolean.java
new file mode 100644
index 0000000..e24d1fb
--- /dev/null
+++ b/test/java/beans/XMLDecoder/spec/TestBoolean.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary Tests <boolean> element
+ * @author Sergey Malenkov
+ */
+
+import java.beans.XMLDecoder;
+
+public final class TestBoolean extends AbstractTest {
+    public static final String XML
+            = "<java>\n"
+            + " <boolean>true</boolean>\n"
+            + " <boolean>false</boolean>\n"
+            + "</java>";
+
+    public static void main(String[] args) {
+        new TestBoolean().test(true);
+    }
+
+    @Override
+    protected void validate(XMLDecoder decoder) {
+        if (!Boolean.TRUE.equals(decoder.readObject())) {
+            throw new Error("true expected");
+        }
+        if (!Boolean.FALSE.equals(decoder.readObject())) {
+            throw new Error("false expected");
+        }
+    }
+}
diff --git a/test/java/beans/XMLDecoder/spec/TestByte.java b/test/java/beans/XMLDecoder/spec/TestByte.java
new file mode 100644
index 0000000..46693d9
--- /dev/null
+++ b/test/java/beans/XMLDecoder/spec/TestByte.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary Tests <byte> element
+ * @author Sergey Malenkov
+ */
+
+import java.beans.XMLDecoder;
+
+public final class TestByte extends AbstractTest {
+    public static final String XML
+            = "<java>\n"
+            + " <byte>0</byte>\n"
+            + " <byte>127</byte>\n"
+            + " <byte>-128</byte>\n"
+            + "</java>";
+
+    public static void main(String[] args) {
+        new TestByte().test(true);
+    }
+
+    @Override
+    protected void validate(XMLDecoder decoder) {
+        validate((byte) 0, decoder.readObject());
+        validate(Byte.MAX_VALUE, decoder.readObject());
+        validate(Byte.MIN_VALUE, decoder.readObject());
+    }
+
+    private static void validate(byte value, Object object) {
+        if (!object.equals(Byte.valueOf(value))) {
+            throw new Error("byte " + value + " expected");
+        }
+    }
+}
diff --git a/test/java/beans/XMLDecoder/spec/TestChar.java b/test/java/beans/XMLDecoder/spec/TestChar.java
new file mode 100644
index 0000000..cb29b71
--- /dev/null
+++ b/test/java/beans/XMLDecoder/spec/TestChar.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary Tests <char> element
+ * @author Sergey Malenkov
+ */
+
+import java.beans.XMLDecoder;
+
+public final class TestChar extends AbstractTest {
+    public static final String XML
+            = "<java>\n"
+            + " <char>X</char>\n"
+            + " <char code=\"#20\"/>\n"
+            + "</java>";
+
+    public static void main(String[] args) {
+        new TestChar().test(true);
+    }
+
+    @Override
+    protected void validate(XMLDecoder decoder) {
+        if (!decoder.readObject().equals(Character.valueOf('X'))) {
+            throw new Error("unexpected character");
+        }
+        if (!decoder.readObject().equals(Character.valueOf((char) 0x20))) {
+            throw new Error("unexpected character code");
+        }
+    }
+}
diff --git a/test/java/beans/XMLDecoder/spec/TestClass.java b/test/java/beans/XMLDecoder/spec/TestClass.java
new file mode 100644
index 0000000..2c16ba7
--- /dev/null
+++ b/test/java/beans/XMLDecoder/spec/TestClass.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary Tests <class> element
+ * @author Sergey Malenkov
+ */
+
+import java.beans.XMLDecoder;
+
+public final class TestClass extends AbstractTest {
+    public static final String PREFIX = "javax.swing.colorchooser.";
+    public static final String INTERFACE = "ColorSelectionModel";
+    public static final String PUBLIC_CLASS = "DefaultColorSelectionModel";
+    public static final String PRIVATE_CLASS = "DiagramComponent";
+    public static final String XML
+            = "<java>\n"
+            + " <class>" + PREFIX + INTERFACE + "</class>\n"
+            + " <class>" + PREFIX + PUBLIC_CLASS + "</class>\n"
+            + " <class>" + PREFIX + PRIVATE_CLASS + "</class>\n"
+            + "</java>";
+
+    public static void main(String[] args) {
+        new TestClass().test(true);
+    }
+
+    @Override
+    protected void validate(XMLDecoder decoder) {
+        validate(PREFIX + INTERFACE, decoder.readObject());
+        validate(PREFIX + PUBLIC_CLASS, decoder.readObject());
+        validate(PREFIX + PRIVATE_CLASS, decoder.readObject());
+    }
+
+    private static void validate(String name, Object object) {
+        Class type = (Class) object;
+        if (!type.getName().equals(name)) {
+            throw new Error(name + " expected");
+        }
+    }
+}
diff --git a/test/java/beans/XMLDecoder/spec/TestDouble.java b/test/java/beans/XMLDecoder/spec/TestDouble.java
new file mode 100644
index 0000000..8e3d918
--- /dev/null
+++ b/test/java/beans/XMLDecoder/spec/TestDouble.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary Tests <double> element
+ * @author Sergey Malenkov
+ */
+
+import java.beans.XMLDecoder;
+
+public final class TestDouble extends AbstractTest {
+    public static final String XML
+            = "<java>\n"
+            + " <double>0</double>\n"
+            + " <double>1000</double>\n"
+            + " <double>-1.1e15</double>\n"
+            + " <double>10.11e-123</double>\n"
+            + "</java>";
+
+    public static void main(String[] args) {
+        new TestDouble().test(true);
+    }
+
+    @Override
+    protected void validate(XMLDecoder decoder) {
+        validate(0.0, decoder.readObject());
+        validate(1000.0, decoder.readObject());
+        validate(-1.1e15, decoder.readObject());
+        validate(10.11e-123, decoder.readObject());
+    }
+
+    private static void validate(double value, Object object) {
+        if (!object.equals(Double.valueOf(value))) {
+            throw new Error("double " + value + " expected");
+        }
+    }
+}
diff --git a/test/java/beans/XMLDecoder/spec/TestFalse.java b/test/java/beans/XMLDecoder/spec/TestFalse.java
new file mode 100644
index 0000000..57a81b8
--- /dev/null
+++ b/test/java/beans/XMLDecoder/spec/TestFalse.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary Tests <false> element
+ * @author Sergey Malenkov
+ */
+
+import java.beans.XMLDecoder;
+
+public final class TestFalse extends AbstractTest {
+    public static final String XML
+            = "<java>\n"
+            + " <false/>\n"
+            + "</java>";
+
+    public static void main(String[] args) {
+        new TestFalse().test(true);
+    }
+
+    @Override
+    protected void validate(XMLDecoder decoder) {
+        if (!Boolean.FALSE.equals(decoder.readObject())) {
+            throw new Error("false expected");
+        }
+    }
+}
diff --git a/test/java/beans/XMLDecoder/spec/TestField.java b/test/java/beans/XMLDecoder/spec/TestField.java
new file mode 100644
index 0000000..aa84408
--- /dev/null
+++ b/test/java/beans/XMLDecoder/spec/TestField.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary Tests <field> element
+ * @author Sergey Malenkov
+ */
+
+import java.beans.XMLDecoder;
+
+public final class TestField extends AbstractTest {
+    public static final String XML
+            = "<java>\n"
+            + " <field name=\"FIELD\" class=\"TestField\"/>\n"
+            + " <field name=\"FIELD\" class=\"TestField\">\n"
+            + "  <string>static postfix</string>\n"
+            + " </field>\n"
+            + " <field name=\"FIELD\" class=\"TestField\"/>\n"
+            + " <property name=\"owner\">\n"
+            + "  <field id=\"prefix\" name=\"field\"/>\n"
+            + "  <field name=\"field\">\n"
+            + "   <string>postfix</string>\n"
+            + "  </field>\n"
+            + "  <field id=\"postfix\" name=\"field\"/>\n"
+            + " </property>\n"
+            + " <var idref=\"prefix\"/>\n"
+            + " <var idref=\"postfix\"/>\n"
+            + "</java>";
+
+    public static void main(String[] args) {
+        new TestField().test(true);
+    }
+
+    public static String FIELD;
+    public String field;
+
+    @Override
+    protected void validate(XMLDecoder decoder) {
+        FIELD = "static prefix";
+        field = "prefix";
+        decoder.setOwner(this);
+        validate(decoder, "static prefix");
+        validate(decoder, "static postfix");
+        validate(decoder, "prefix");
+        validate(decoder, "postfix");
+    }
+
+    private static void validate(XMLDecoder decoder, String name) {
+        if (!decoder.readObject().equals(name)) {
+            throw new Error(name + " expected");
+        }
+    }
+}
diff --git a/test/java/beans/XMLDecoder/spec/TestFloat.java b/test/java/beans/XMLDecoder/spec/TestFloat.java
new file mode 100644
index 0000000..bb1287f
--- /dev/null
+++ b/test/java/beans/XMLDecoder/spec/TestFloat.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary Tests <float> element
+ * @author Sergey Malenkov
+ */
+
+import java.beans.XMLDecoder;
+
+public final class TestFloat extends AbstractTest {
+    public static final String XML
+            = "<java>\n"
+            + " <float>0</float>\n"
+            + " <float>100</float>\n"
+            + " <float>-1e15</float>\n"
+            + " <float>100e-20</float>\n"
+            + "</java>";
+
+    public static void main(String[] args) {
+        new TestFloat().test(true);
+    }
+
+    @Override
+    protected void validate(XMLDecoder decoder) {
+        validate(0.0f, decoder.readObject());
+        validate(100.0f, decoder.readObject());
+        validate(-1e15f, decoder.readObject());
+        validate(100e-20f, decoder.readObject());
+    }
+
+    private static void validate(float value, Object object) {
+        if (!object.equals(Float.valueOf(value))) {
+            throw new Error("float " + value + " expected");
+        }
+    }
+}
diff --git a/test/java/beans/XMLDecoder/spec/TestInt.java b/test/java/beans/XMLDecoder/spec/TestInt.java
new file mode 100644
index 0000000..531c944
--- /dev/null
+++ b/test/java/beans/XMLDecoder/spec/TestInt.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary Tests <int> element
+ * @author Sergey Malenkov
+ */
+
+import java.beans.XMLDecoder;
+
+public final class TestInt extends AbstractTest {
+    public static final String XML
+            = "<java>\n"
+            + " <int>0</int>\n"
+            + " <int>127</int>\n"
+            + " <int>-128</int>\n"
+            + " <int>32767</int>\n"
+            + " <int>-32768</int>\n"
+            + " <int>2147483647</int>\n"
+            + " <int>-2147483648</int>\n"
+            + "</java>";
+
+    public static void main(String[] args) {
+        new TestInt().test(true);
+    }
+
+    @Override
+    protected void validate(XMLDecoder decoder) {
+        validate(0, decoder.readObject());
+        validate((int) Byte.MAX_VALUE, decoder.readObject());
+        validate((int) Byte.MIN_VALUE, decoder.readObject());
+        validate((int) Short.MAX_VALUE, decoder.readObject());
+        validate((int) Short.MIN_VALUE, decoder.readObject());
+        validate(Integer.MAX_VALUE, decoder.readObject());
+        validate(Integer.MIN_VALUE, decoder.readObject());
+    }
+
+    private static void validate(int value, Object object) {
+        if (!object.equals(Integer.valueOf(value))) {
+            throw new Error("int " + value + " expected");
+        }
+    }
+}
diff --git a/test/java/beans/XMLDecoder/spec/TestJava.java b/test/java/beans/XMLDecoder/spec/TestJava.java
new file mode 100644
index 0000000..5786195
--- /dev/null
+++ b/test/java/beans/XMLDecoder/spec/TestJava.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary Tests <java> element
+ * @author Sergey Malenkov
+ */
+
+import java.beans.XMLDecoder;
+
+public final class TestJava extends AbstractTest {
+    public static final String XML
+            = "<java>\n"
+            + " <void id=\"owner\" method=\"getOwner\">\n"
+            + "  <void method=\"init\">\n"
+            + "   <string>Hello, world!</string>\n"
+            + "  </void>\n"
+            + " </void>\n"
+            + " <object idref=\"owner\"/>\n"
+            + "</java>";
+
+    public static void main(String[] args) {
+        new TestJava().test(true);
+    }
+
+    private String message;
+
+    public void init(String message) {
+        this.message = message;
+    }
+
+    @Override
+    protected void validate(XMLDecoder decoder) {
+        decoder.setOwner(this);
+        if (this != decoder.readObject()) {
+            throw new Error("owner should be the same");
+        }
+        if (this.message == null) {
+            throw new Error("owner's method is not called");
+        }
+    }
+}
diff --git a/test/java/beans/XMLDecoder/spec/TestLong.java b/test/java/beans/XMLDecoder/spec/TestLong.java
new file mode 100644
index 0000000..16a7e32
--- /dev/null
+++ b/test/java/beans/XMLDecoder/spec/TestLong.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary Tests <long> element
+ * @author Sergey Malenkov
+ */
+
+import java.beans.XMLDecoder;
+
+public final class TestLong extends AbstractTest {
+    public static final String XML
+            = "<java>\n"
+            + " <long>0</long>\n"
+            + " <long>127</long>\n"
+            + " <long>-128</long>\n"
+            + " <long>32767</long>\n"
+            + " <long>-32768</long>\n"
+            + " <long>2147483647</long>\n"
+            + " <long>-2147483648</long>\n"
+            + " <long>9223372036854775807</long>\n"
+            + " <long>-9223372036854775808</long>\n"
+            + "</java>";
+
+    public static void main(String[] args) {
+        new TestLong().test(true);
+    }
+
+    @Override
+    protected void validate(XMLDecoder decoder) {
+        validate(0L, decoder.readObject());
+        validate((long) Byte.MAX_VALUE, decoder.readObject());
+        validate((long) Byte.MIN_VALUE, decoder.readObject());
+        validate((long) Short.MAX_VALUE, decoder.readObject());
+        validate((long) Short.MIN_VALUE, decoder.readObject());
+        validate((long) Integer.MAX_VALUE, decoder.readObject());
+        validate((long) Integer.MIN_VALUE, decoder.readObject());
+        validate(Long.MAX_VALUE, decoder.readObject());
+        validate(Long.MIN_VALUE, decoder.readObject());
+    }
+
+    private static void validate(long value, Object object) {
+        if (!object.equals(Long.valueOf(value))) {
+            throw new Error("long " + value + " expected");
+        }
+    }
+}
diff --git a/test/java/beans/XMLDecoder/spec/TestMethod.java b/test/java/beans/XMLDecoder/spec/TestMethod.java
new file mode 100644
index 0000000..01ee5e1
--- /dev/null
+++ b/test/java/beans/XMLDecoder/spec/TestMethod.java
@@ -0,0 +1,178 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary Tests <method> element
+ * @author Sergey Malenkov
+ */
+
+import java.beans.XMLDecoder;
+
+public final class TestMethod extends AbstractTest {
+    public static final String XML
+            = "<java>\n"
+            + " <new class=\"TestMethod$A\">\n"
+            + "  <method name=\"m\">\n"
+            + "   <new class=\"TestMethod$Y\"/>\n"
+            + "   <new class=\"TestMethod$Y\"/>\n"
+            + "  </method>\n"
+            + " </new>\n"
+            + " <new class=\"TestMethod$B\">\n"
+            + "  <method name=\"m\">\n"
+            + "   <new class=\"TestMethod$Y\"/>\n"
+            + "   <new class=\"TestMethod$Y\"/>\n"
+            + "  </method>\n"
+            + " </new>\n"
+            + " <new class=\"TestMethod$C\">\n"
+            + "  <method name=\"m\">\n"
+            + "   <new class=\"TestMethod$Z\"/>\n"
+            + "   <new class=\"TestMethod$Z\"/>\n"
+            + "  </method>\n"
+            + " </new>\n"
+            + " <new class=\"TestMethod$D\">\n"
+            + "  <method name=\"m\">\n"
+            + "   <new class=\"TestMethod$Z\"/>\n"
+            + "   <new class=\"TestMethod$Z\"/>\n"
+            + "  </method>\n"
+            + " </new>\n"
+            + " <new class=\"TestMethod$E\">\n"
+            + "  <method name=\"m\">\n"
+            + "   <new class=\"TestMethod$Z\"/>\n"
+            + "   <new class=\"TestMethod$Z\"/>\n"
+            + "  </method>\n"
+            + " </new>\n"
+            + "</java>";
+
+    public static void main(String[] args) {
+        new TestMethod().test(true);
+    }
+
+    private NoSuchMethodException exception;
+
+    @Override
+    public void exceptionThrown(Exception exception) {
+        if (this.exception != null) {
+            // only one exception allowed
+            super.exceptionThrown(exception);
+        } else if (exception instanceof NoSuchMethodException) {
+            // expected exception: ambiguous methods are found
+            this.exception = (NoSuchMethodException) exception;
+        } else {
+            super.exceptionThrown(exception);
+        }
+    }
+
+    @Override
+    protected void validate(XMLDecoder decoder) {
+        this.exception = null;
+        validate(decoder, A.class);
+        validate(decoder, B.class);
+        validate(decoder, C.class);
+        validate(decoder, D.class);
+        validate(decoder, E.class);
+        if (this.exception == null) {
+            throw new Error("NoSuchMethodException expected");
+        }
+    }
+
+    private static void validate(XMLDecoder decoder, Class type) {
+        if (!type.equals(decoder.readObject().getClass())) {
+            throw new Error("unexpected class");
+        }
+    }
+
+    /**
+     * All ambiguous method declarations should fail.
+     */
+    public static class A {
+        public void m(X x1, X x2) {
+            throw new Error("A.m(X,X) should not be called");
+        }
+
+        public void m(X x1, Y y2) {
+            throw new Error("A.m(X,Y) should not be called");
+        }
+
+        public void m(Y y1, X x2) {
+            throw new Error("A.m(Y,X) should not be called");
+        }
+    }
+
+    /**
+     * The most specific method in this case would be the second declaration.
+     */
+    public static class B {
+        public void m(X x1, X x2) {
+            throw new Error("B.m(X,X) should not be called");
+        }
+
+        public void m(X x1, Y y2) {
+            // expected: B.m(X,Y) should be called
+        }
+    }
+
+    /**
+     * The most specific method in this case would be the first declaration.
+     */
+    public static class C {
+        public void m(Y y1, Y y2) {
+            // expected: C.m(Y,Y) should be called
+        }
+
+        public void m(X x1, X x2) {
+            throw new Error("C.m(X,X) should not be called");
+        }
+    }
+
+    /**
+     * Same as the previous case but flip methods.
+     */
+    public static class D {
+        public void m(X x1, X x2) {
+            throw new Error("D.m(X,X) should not be called");
+        }
+
+        public void m(Y y1, Y y2) {
+            // expected: D.m(Y,Y) should be called
+        }
+    }
+
+    /**
+     * The method should be called with (Z,Z).
+     */
+    public static class E {
+        public void m(X x1, X x2) {
+            // expected: E.m(X,X) should be called
+        }
+    }
+
+    public static class X {
+    }
+
+    public static class Y extends X {
+    }
+
+    public static class Z extends Y {
+    }
+}
diff --git a/test/java/beans/XMLDecoder/spec/TestNew.java b/test/java/beans/XMLDecoder/spec/TestNew.java
new file mode 100644
index 0000000..3e1e86d
--- /dev/null
+++ b/test/java/beans/XMLDecoder/spec/TestNew.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary Tests <new> element
+ * @author Sergey Malenkov
+ */
+
+import java.beans.XMLDecoder;
+import java.util.ArrayList;
+import java.util.List;
+
+public final class TestNew extends AbstractTest {
+    public static final String XML
+            = "<java>\n"
+            + " <new class=\"TestNew\"/>\n"
+            + " <new class=\"TestNew\">\n"
+            + "  <null/>\n"
+            + " </new>\n"
+            + " <new class=\"TestNew\">\n"
+            + "  <string>single</string>\n"
+            + " </new>\n"
+            + " <new class=\"TestNew\">\n"
+            + "  <string>first</string>\n"
+            + "  <string>second</string>\n"
+            + "  <string>third</string>\n"
+            + " </new>\n"
+            + "</java>";
+
+    public static void main(String[] args) {
+        new TestNew().test(true);
+    }
+
+    private List<String> list;
+
+    public TestNew(String...messages) {
+        if (messages != null) {
+            this.list = new ArrayList<String>();
+            for (String message : messages) {
+                this.list.add(message);
+            }
+        }
+    }
+
+    @Override
+    public boolean equals(Object object) {
+        if (object instanceof TestNew) {
+            TestNew test = (TestNew) object;
+            return (test.list == null)
+                    ? this.list == null
+                    : test.list.equals(this.list);
+        }
+        return false;
+    }
+
+    @Override
+    protected void validate(XMLDecoder decoder) {
+        validate(decoder.readObject());
+        validate(decoder.readObject(), null);
+        validate(decoder.readObject(), "single");
+        validate(decoder.readObject(), "first", "second", "third");
+    }
+
+    private static void validate(Object object, String...messages) {
+        if (!object.equals(new TestNew(messages))) {
+            throw new Error("expected object");
+        }
+    }
+}
diff --git a/test/java/beans/XMLDecoder/spec/TestNull.java b/test/java/beans/XMLDecoder/spec/TestNull.java
new file mode 100644
index 0000000..e14bf95
--- /dev/null
+++ b/test/java/beans/XMLDecoder/spec/TestNull.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary Tests <null> element
+ * @author Sergey Malenkov
+ */
+
+import java.beans.XMLDecoder;
+
+public final class TestNull extends AbstractTest {
+    public static final String XML
+            = "<java>\n"
+            + " <null/>\n"
+            + "</java>";
+
+    public static void main(String[] args) {
+        new TestNull().test(true);
+    }
+
+    @Override
+    protected void validate(XMLDecoder decoder) {
+        if (null != decoder.readObject()) {
+            throw new Error("null value expected");
+        }
+    }
+}
diff --git a/test/java/beans/XMLDecoder/spec/TestObject.java b/test/java/beans/XMLDecoder/spec/TestObject.java
new file mode 100644
index 0000000..d9531b3
--- /dev/null
+++ b/test/java/beans/XMLDecoder/spec/TestObject.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary Tests <object> element
+ * @author Sergey Malenkov
+ */
+
+import java.beans.XMLDecoder;
+import javax.swing.JButton;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.SwingConstants;
+
+public final class TestObject extends AbstractTest {
+    public static final String XML // TODO
+            = "<java>\n"
+            + " <object class=\"javax.swing.JPanel\">\n"
+            + "  <void method=\"add\">\n"
+            + "   <object id=\"button\" class=\"javax.swing.JButton\">\n"
+            + "    <string>button</string>\n"
+            + "    <void property=\"verticalAlignment\">\n"
+            + "     <object field=\"CENTER\" class=\"javax.swing.SwingConstants\"/>\n"
+            + "    </void>\n"
+            + "   </object>\n"
+            + "  </void>\n"
+            + "  <void method=\"add\">\n"
+            + "   <object class=\"javax.swing.JLabel\">\n"
+            + "    <string>label</string>\n"
+            + "    <void property=\"labelFor\">\n"
+            + "     <object idref=\"button\"/>\n"
+            + "    </void>\n"
+            + "   </object>\n"
+            + "  </void>\n"
+            + " </object>\n"
+            + "</java>";
+
+    public static void main(String[] args) {
+        new TestObject().test(true);
+    }
+
+    @Override
+    protected void validate(XMLDecoder decoder) {
+        JPanel panel = (JPanel) decoder.readObject();
+        if (2 != panel.getComponents().length) {
+            throw new Error("unexpected component count");
+        }
+        JButton button = (JButton) panel.getComponents()[0];
+        if (!button.getText().equals("button")) { // NON-NLS: hardcoded in XML
+            throw new Error("unexpected button text");
+        }
+        if (SwingConstants.CENTER != button.getVerticalAlignment()) {
+            throw new Error("unexpected vertical alignment");
+        }
+        JLabel label = (JLabel) panel.getComponents()[1];
+        if (!label.getText().equals("label")) { // NON-NLS: hardcoded in XML
+            throw new Error("unexpected label text");
+        }
+        if (button != label.getLabelFor()) {
+            throw new Error("unexpected component");
+        }
+    }
+}
diff --git a/test/java/beans/XMLDecoder/spec/TestProperty.java b/test/java/beans/XMLDecoder/spec/TestProperty.java
new file mode 100644
index 0000000..e1f9c77
--- /dev/null
+++ b/test/java/beans/XMLDecoder/spec/TestProperty.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary Tests <property> element
+ * @author Sergey Malenkov
+ */
+
+import java.beans.XMLDecoder;
+
+public final class TestProperty extends AbstractTest {
+    public static final String XML
+            = "<java>\n"
+            + " <property name=\"owner\">\n"
+            + "  <property name=\"message\">\n"
+            + "   <string>message</string>\n"
+            + "  </property>\n"
+            + "  <property id=\"message\" name=\"message\"/>\n"
+            + "  <property name=\"indexed\" index=\"1\">\n"
+            + "   <string>indexed</string>\n"
+            + "  </property>\n"
+            + "  <property id=\"indexed\" name=\"indexed\" index=\"1\"/>\n"
+            + " </property>\n"
+            + " <var idref=\"message\"/>\n"
+            + " <var idref=\"indexed\"/>\n"
+            + "</java>";
+
+    public static void main(String[] args) {
+        new TestProperty().test(true);
+    }
+
+    private int index;
+    private String message;
+
+    public String getMessage() {
+        return this.message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+
+    public String getIndexed(int index) {
+        if (this.index != index) {
+            throw new Error("unexpected index");
+        }
+        return this.message;
+    }
+
+    public void setIndexed(int index, String message) {
+        this.index = index;
+        this.message = message;
+    }
+
+    @Override
+    protected void validate(XMLDecoder decoder) {
+        decoder.setOwner(this);
+        validate(decoder, "message");
+        validate(decoder, "indexed");
+    }
+
+    private static void validate(XMLDecoder decoder, String name) {
+        if (!decoder.readObject().equals(name)) {
+            throw new Error(name + " expected");
+        }
+    }
+}
diff --git a/test/java/beans/XMLDecoder/spec/TestShort.java b/test/java/beans/XMLDecoder/spec/TestShort.java
new file mode 100644
index 0000000..99a0c57
--- /dev/null
+++ b/test/java/beans/XMLDecoder/spec/TestShort.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary Tests <short> element
+ * @author Sergey Malenkov
+ */
+
+import java.beans.XMLDecoder;
+
+public final class TestShort extends AbstractTest {
+    public static final String XML
+            = "<java>\n"
+            + " <short>0</short>\n"
+            + " <short>127</short>\n"
+            + " <short>-128</short>\n"
+            + " <short>32767</short>\n"
+            + " <short>-32768</short>\n"
+            + "</java>";
+
+    public static void main(String[] args) {
+        new TestShort().test(true);
+    }
+
+    @Override
+    protected void validate(XMLDecoder decoder) {
+        validate((short) 0, decoder.readObject());
+        validate((short) Byte.MAX_VALUE, decoder.readObject());
+        validate((short) Byte.MIN_VALUE, decoder.readObject());
+        validate(Short.MAX_VALUE, decoder.readObject());
+        validate(Short.MIN_VALUE, decoder.readObject());
+    }
+
+    private static void validate(short value, Object object) {
+        if (!object.equals(Short.valueOf(value))) {
+            throw new Error("short " + value + " expected");
+        }
+    }
+}
diff --git a/test/java/beans/XMLDecoder/spec/TestString.java b/test/java/beans/XMLDecoder/spec/TestString.java
new file mode 100644
index 0000000..d41b1bb
--- /dev/null
+++ b/test/java/beans/XMLDecoder/spec/TestString.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary Tests <string> element
+ * @author Sergey Malenkov
+ */
+
+import java.beans.XMLDecoder;
+
+public final class TestString extends AbstractTest {
+    public static final String PREFIX = " prefix ";
+    public static final String POSTFIX = " postfix ";
+    public static final String XML
+            = "<java>\n"
+            + " <string>" + PREFIX + "</string>\n"
+            + " <string>" + POSTFIX + "</string>\n"
+            + " <string>" + PREFIX + POSTFIX + "</string>\n"
+            + " <string>" + PREFIX + "<char code=\"0\"/>" + POSTFIX + "</string>\n"
+            + "</java>";
+
+    public static void main(String[] args) {
+        new TestString().test(true);
+    }
+
+    @Override
+    protected void validate(XMLDecoder decoder) {
+        validate(PREFIX, decoder.readObject());
+        validate(POSTFIX, decoder.readObject());
+        validate(PREFIX + POSTFIX, decoder.readObject());
+        validate(PREFIX + '\u0000' + POSTFIX, decoder.readObject());
+    }
+
+    private static void validate(String name, Object object) {
+        if (!object.equals(name)) {
+            throw new Error(name + " expected");
+        }
+    }
+}
diff --git a/test/java/beans/XMLDecoder/spec/TestTrue.java b/test/java/beans/XMLDecoder/spec/TestTrue.java
new file mode 100644
index 0000000..934d28e
--- /dev/null
+++ b/test/java/beans/XMLDecoder/spec/TestTrue.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary Tests <true> element
+ * @author Sergey Malenkov
+ */
+
+import java.beans.XMLDecoder;
+
+public final class TestTrue extends AbstractTest {
+    public static final String XML
+            = "<java>\n"
+            + " <true/>\n"
+            + "</java>";
+
+    public static void main(String[] args) {
+        new TestTrue().test(true);
+    }
+
+    @Override
+    protected void validate(XMLDecoder decoder) {
+        if (!Boolean.TRUE.equals(decoder.readObject())) {
+            throw new Error("true expected");
+        }
+    }
+}
diff --git a/test/java/beans/XMLDecoder/spec/TestVar.java b/test/java/beans/XMLDecoder/spec/TestVar.java
new file mode 100644
index 0000000..701edad
--- /dev/null
+++ b/test/java/beans/XMLDecoder/spec/TestVar.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @summary Tests <var> element
+ * @author Sergey Malenkov
+ */
+
+import java.beans.XMLDecoder;
+
+public final class TestVar extends AbstractTest {
+    public static final String XML
+            = "<java id=\"decoder\">\n"
+            + " <var idref=\"decoder\"/>\n"
+            + " <var id=\"another\" idref=\"decoder\"/>\n"
+            + " <var idref=\"another\"/>\n"
+            + " <var id=\"decoder\" idref=\"another\"/>\n"
+            + " <var idref=\"decoder\"/>\n"
+            + "</java>";
+
+    public static void main(String[] args) {
+        new TestVar().test(true);
+    }
+
+    @Override
+    protected void validate(XMLDecoder decoder) {
+        for (int i = 0; i < 3; i++) {
+            if (decoder != decoder.readObject()) {
+                throw new Error("decoder instance expected");
+            }
+        }
+    }
+}