--- a/jdk/src/share/classes/java/beans/MetaData.java Fri Apr 26 18:48:11 2013 +0400
+++ b/jdk/src/share/classes/java/beans/MetaData.java Mon Apr 29 16:42:22 2013 +0400
@@ -69,8 +69,9 @@
* @author Philip Milne
* @author Steve Langley
*/
+class MetaData {
-class NullPersistenceDelegate extends PersistenceDelegate {
+static final class NullPersistenceDelegate extends PersistenceDelegate {
// Note this will be called by all classes when they reach the
// top of their superclass chain.
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
@@ -87,7 +88,7 @@
*
* @author Sergey A. Malenkov
*/
-class EnumPersistenceDelegate extends PersistenceDelegate {
+static final class EnumPersistenceDelegate extends PersistenceDelegate {
protected boolean mutatesTo(Object oldInstance, Object newInstance) {
return oldInstance == newInstance;
}
@@ -98,7 +99,7 @@
}
}
-class PrimitivePersistenceDelegate extends PersistenceDelegate {
+static final class PrimitivePersistenceDelegate extends PersistenceDelegate {
protected boolean mutatesTo(Object oldInstance, Object newInstance) {
return oldInstance.equals(newInstance);
}
@@ -109,7 +110,7 @@
}
}
-class ArrayPersistenceDelegate extends PersistenceDelegate {
+static final class ArrayPersistenceDelegate extends PersistenceDelegate {
protected boolean mutatesTo(Object oldInstance, Object newInstance) {
return (newInstance != null &&
oldInstance.getClass() == newInstance.getClass() && // Also ensures the subtype is correct.
@@ -150,7 +151,7 @@
}
}
-class ProxyPersistenceDelegate extends PersistenceDelegate {
+static final class ProxyPersistenceDelegate extends PersistenceDelegate {
protected Expression instantiate(Object oldInstance, Encoder out) {
Class<?> type = oldInstance.getClass();
java.lang.reflect.Proxy p = (java.lang.reflect.Proxy)oldInstance;
@@ -185,7 +186,7 @@
}
// Strings
-class java_lang_String_PersistenceDelegate extends PersistenceDelegate {
+static final class java_lang_String_PersistenceDelegate extends PersistenceDelegate {
protected Expression instantiate(Object oldInstance, Encoder out) { return null; }
public void writeObject(Object oldInstance, Encoder out) {
@@ -194,7 +195,7 @@
}
// Classes
-class java_lang_Class_PersistenceDelegate extends PersistenceDelegate {
+static final class java_lang_Class_PersistenceDelegate extends PersistenceDelegate {
protected boolean mutatesTo(Object oldInstance, Object newInstance) {
return oldInstance.equals(newInstance);
}
@@ -228,7 +229,7 @@
}
// Fields
-class java_lang_reflect_Field_PersistenceDelegate extends PersistenceDelegate {
+static final class java_lang_reflect_Field_PersistenceDelegate extends PersistenceDelegate {
protected boolean mutatesTo(Object oldInstance, Object newInstance) {
return oldInstance.equals(newInstance);
}
@@ -243,7 +244,7 @@
}
// Methods
-class java_lang_reflect_Method_PersistenceDelegate extends PersistenceDelegate {
+static final class java_lang_reflect_Method_PersistenceDelegate extends PersistenceDelegate {
protected boolean mutatesTo(Object oldInstance, Object newInstance) {
return oldInstance.equals(newInstance);
}
@@ -267,7 +268,7 @@
*
* @author Sergey A. Malenkov
*/
-class java_util_Date_PersistenceDelegate extends PersistenceDelegate {
+static class java_util_Date_PersistenceDelegate extends PersistenceDelegate {
protected boolean mutatesTo(Object oldInstance, Object newInstance) {
if (!super.mutatesTo(oldInstance, newInstance)) {
return false;
@@ -290,7 +291,7 @@
*
* @author Sergey A. Malenkov
*/
-final class java_sql_Timestamp_PersistenceDelegate extends java_util_Date_PersistenceDelegate {
+static final class java_sql_Timestamp_PersistenceDelegate extends java_util_Date_PersistenceDelegate {
private static final Method getNanosMethod = getNanosMethod();
private static Method getNanosMethod() {
@@ -354,7 +355,7 @@
*
* @author Sergey A. Malenkov
*/
-abstract class java_util_Collections extends PersistenceDelegate {
+private static abstract class java_util_Collections extends PersistenceDelegate {
protected boolean mutatesTo(Object oldInstance, Object newInstance) {
if (!super.mutatesTo(oldInstance, newInstance)) {
return false;
@@ -367,6 +368,10 @@
return (oldC.size() == newC.size()) && oldC.containsAll(newC);
}
+ protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
+ // do not initialize these custom collections in default way
+ }
+
static final class EmptyList_PersistenceDelegate extends java_util_Collections {
protected Expression instantiate(Object oldInstance, Encoder out) {
return new Expression(oldInstance, Collections.class, "emptyList", null);
@@ -569,7 +574,7 @@
*
* @author Sergey A. Malenkov
*/
-class java_util_EnumMap_PersistenceDelegate extends PersistenceDelegate {
+static final class java_util_EnumMap_PersistenceDelegate extends PersistenceDelegate {
protected boolean mutatesTo(Object oldInstance, Object newInstance) {
return super.mutatesTo(oldInstance, newInstance) && (getType(oldInstance) == getType(newInstance));
}
@@ -588,7 +593,7 @@
*
* @author Sergey A. Malenkov
*/
-class java_util_EnumSet_PersistenceDelegate extends PersistenceDelegate {
+static final class java_util_EnumSet_PersistenceDelegate extends PersistenceDelegate {
protected boolean mutatesTo(Object oldInstance, Object newInstance) {
return super.mutatesTo(oldInstance, newInstance) && (getType(oldInstance) == getType(newInstance));
}
@@ -603,7 +608,7 @@
}
// Collection
-class java_util_Collection_PersistenceDelegate extends DefaultPersistenceDelegate {
+static class java_util_Collection_PersistenceDelegate extends DefaultPersistenceDelegate {
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
java.util.Collection<?> oldO = (java.util.Collection)oldInstance;
java.util.Collection<?> newO = (java.util.Collection)newInstance;
@@ -618,7 +623,7 @@
}
// List
-class java_util_List_PersistenceDelegate extends DefaultPersistenceDelegate {
+static class java_util_List_PersistenceDelegate extends DefaultPersistenceDelegate {
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
java.util.List<?> oldO = (java.util.List<?>)oldInstance;
java.util.List<?> newO = (java.util.List<?>)newInstance;
@@ -653,7 +658,7 @@
// Map
-class java_util_Map_PersistenceDelegate extends DefaultPersistenceDelegate {
+static class java_util_Map_PersistenceDelegate extends DefaultPersistenceDelegate {
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
// System.out.println("Initializing: " + newInstance);
java.util.Map<?,?> oldMap = (java.util.Map)oldInstance;
@@ -691,14 +696,14 @@
}
}
-class java_util_AbstractCollection_PersistenceDelegate extends java_util_Collection_PersistenceDelegate {}
-class java_util_AbstractList_PersistenceDelegate extends java_util_List_PersistenceDelegate {}
-class java_util_AbstractMap_PersistenceDelegate extends java_util_Map_PersistenceDelegate {}
-class java_util_Hashtable_PersistenceDelegate extends java_util_Map_PersistenceDelegate {}
+static final class java_util_AbstractCollection_PersistenceDelegate extends java_util_Collection_PersistenceDelegate {}
+static final class java_util_AbstractList_PersistenceDelegate extends java_util_List_PersistenceDelegate {}
+static final class java_util_AbstractMap_PersistenceDelegate extends java_util_Map_PersistenceDelegate {}
+static final class java_util_Hashtable_PersistenceDelegate extends java_util_Map_PersistenceDelegate {}
// Beans
-class java_beans_beancontext_BeanContextSupport_PersistenceDelegate extends java_util_Collection_PersistenceDelegate {}
+static final class java_beans_beancontext_BeanContextSupport_PersistenceDelegate extends java_util_Collection_PersistenceDelegate {}
// AWT
@@ -709,7 +714,7 @@
*
* @author Sergey A. Malenkov
*/
-final class java_awt_Insets_PersistenceDelegate extends PersistenceDelegate {
+static final class java_awt_Insets_PersistenceDelegate extends PersistenceDelegate {
protected boolean mutatesTo(Object oldInstance, Object newInstance) {
return oldInstance.equals(newInstance);
}
@@ -733,7 +738,7 @@
*
* @author Sergey A. Malenkov
*/
-final class java_awt_Font_PersistenceDelegate extends PersistenceDelegate {
+static final class java_awt_Font_PersistenceDelegate extends PersistenceDelegate {
protected boolean mutatesTo(Object oldInstance, Object newInstance) {
return oldInstance.equals(newInstance);
}
@@ -802,7 +807,7 @@
*
* @author Sergey A. Malenkov
*/
-final class java_awt_AWTKeyStroke_PersistenceDelegate extends PersistenceDelegate {
+static final class java_awt_AWTKeyStroke_PersistenceDelegate extends PersistenceDelegate {
protected boolean mutatesTo(Object oldInstance, Object newInstance) {
return oldInstance.equals(newInstance);
}
@@ -843,7 +848,7 @@
}
}
-class StaticFieldsPersistenceDelegate extends PersistenceDelegate {
+static class StaticFieldsPersistenceDelegate extends PersistenceDelegate {
protected void installFields(Encoder out, Class<?> cls) {
Field fields[] = cls.getFields();
for(int i = 0; i < fields.length; i++) {
@@ -870,13 +875,13 @@
}
// SystemColor
-class java_awt_SystemColor_PersistenceDelegate extends StaticFieldsPersistenceDelegate {}
+static final class java_awt_SystemColor_PersistenceDelegate extends StaticFieldsPersistenceDelegate {}
// TextAttribute
-class java_awt_font_TextAttribute_PersistenceDelegate extends StaticFieldsPersistenceDelegate {}
+static final class java_awt_font_TextAttribute_PersistenceDelegate extends StaticFieldsPersistenceDelegate {}
// MenuShortcut
-class java_awt_MenuShortcut_PersistenceDelegate extends PersistenceDelegate {
+static final class java_awt_MenuShortcut_PersistenceDelegate extends PersistenceDelegate {
protected boolean mutatesTo(Object oldInstance, Object newInstance) {
return oldInstance.equals(newInstance);
}
@@ -889,7 +894,7 @@
}
// Component
-class java_awt_Component_PersistenceDelegate extends DefaultPersistenceDelegate {
+static final class java_awt_Component_PersistenceDelegate extends DefaultPersistenceDelegate {
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
super.initialize(type, oldInstance, newInstance, out);
java.awt.Component c = (java.awt.Component)oldInstance;
@@ -936,7 +941,7 @@
}
// Container
-class java_awt_Container_PersistenceDelegate extends DefaultPersistenceDelegate {
+static final class java_awt_Container_PersistenceDelegate extends DefaultPersistenceDelegate {
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
super.initialize(type, oldInstance, newInstance, out);
// Ignore the children of a JScrollPane.
@@ -971,7 +976,7 @@
}
// Choice
-class java_awt_Choice_PersistenceDelegate extends DefaultPersistenceDelegate {
+static final class java_awt_Choice_PersistenceDelegate extends DefaultPersistenceDelegate {
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
super.initialize(type, oldInstance, newInstance, out);
java.awt.Choice m = (java.awt.Choice)oldInstance;
@@ -983,7 +988,7 @@
}
// Menu
-class java_awt_Menu_PersistenceDelegate extends DefaultPersistenceDelegate {
+static final class java_awt_Menu_PersistenceDelegate extends DefaultPersistenceDelegate {
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
super.initialize(type, oldInstance, newInstance, out);
java.awt.Menu m = (java.awt.Menu)oldInstance;
@@ -995,7 +1000,7 @@
}
// MenuBar
-class java_awt_MenuBar_PersistenceDelegate extends DefaultPersistenceDelegate {
+static final class java_awt_MenuBar_PersistenceDelegate extends DefaultPersistenceDelegate {
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
super.initialize(type, oldInstance, newInstance, out);
java.awt.MenuBar m = (java.awt.MenuBar)oldInstance;
@@ -1007,7 +1012,7 @@
}
// List
-class java_awt_List_PersistenceDelegate extends DefaultPersistenceDelegate {
+static final class java_awt_List_PersistenceDelegate extends DefaultPersistenceDelegate {
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
super.initialize(type, oldInstance, newInstance, out);
java.awt.List m = (java.awt.List)oldInstance;
@@ -1022,7 +1027,7 @@
// LayoutManagers
// BorderLayout
-class java_awt_BorderLayout_PersistenceDelegate extends DefaultPersistenceDelegate {
+static final class java_awt_BorderLayout_PersistenceDelegate extends DefaultPersistenceDelegate {
private static final String[] CONSTRAINTS = {
BorderLayout.NORTH,
BorderLayout.SOUTH,
@@ -1053,41 +1058,44 @@
}
// CardLayout
-class java_awt_CardLayout_PersistenceDelegate extends DefaultPersistenceDelegate {
+static final class java_awt_CardLayout_PersistenceDelegate extends DefaultPersistenceDelegate {
protected void initialize(Class<?> type, Object oldInstance,
Object newInstance, Encoder out) {
super.initialize(type, oldInstance, newInstance, out);
- Hashtable<?,?> tab = (Hashtable<?,?>)ReflectionUtils.getPrivateField(oldInstance,
- java.awt.CardLayout.class,
- "tab",
- out.getExceptionListener());
- if (tab != null) {
- for(Enumeration<?> e = tab.keys(); e.hasMoreElements();) {
- Object child = e.nextElement();
- invokeStatement(oldInstance, "addLayoutComponent",
- new Object[]{child, (String)tab.get(child)}, out);
+ if (getVector(newInstance).isEmpty()) {
+ for (Object card : getVector(oldInstance)) {
+ Object[] args = {MetaData.getPrivateFieldValue(card, "java.awt.CardLayout$Card.name"),
+ MetaData.getPrivateFieldValue(card, "java.awt.CardLayout$Card.comp")};
+ invokeStatement(oldInstance, "addLayoutComponent", args, out);
}
}
}
+ protected boolean mutatesTo(Object oldInstance, Object newInstance) {
+ return super.mutatesTo(oldInstance, newInstance) && getVector(newInstance).isEmpty();
+ }
+ private static Vector<?> getVector(Object instance) {
+ return (Vector<?>) MetaData.getPrivateFieldValue(instance, "java.awt.CardLayout.vector");
+ }
}
// GridBagLayout
-class java_awt_GridBagLayout_PersistenceDelegate extends DefaultPersistenceDelegate {
+static final class java_awt_GridBagLayout_PersistenceDelegate extends DefaultPersistenceDelegate {
protected void initialize(Class<?> type, Object oldInstance,
Object newInstance, Encoder out) {
super.initialize(type, oldInstance, newInstance, out);
- Hashtable<?,?> comptable = (Hashtable<?,?>)ReflectionUtils.getPrivateField(oldInstance,
- java.awt.GridBagLayout.class,
- "comptable",
- out.getExceptionListener());
- if (comptable != null) {
- for(Enumeration<?> e = comptable.keys(); e.hasMoreElements();) {
- Object child = e.nextElement();
- invokeStatement(oldInstance, "addLayoutComponent",
- new Object[]{child, comptable.get(child)}, out);
+ if (getHashtable(newInstance).isEmpty()) {
+ for (Map.Entry<?,?> entry : getHashtable(oldInstance).entrySet()) {
+ Object[] args = {entry.getKey(), entry.getValue()};
+ invokeStatement(oldInstance, "addLayoutComponent", args, out);
}
}
}
+ protected boolean mutatesTo(Object oldInstance, Object newInstance) {
+ return super.mutatesTo(oldInstance, newInstance) && getHashtable(newInstance).isEmpty();
+ }
+ private static Hashtable<?,?> getHashtable(Object instance) {
+ return (Hashtable<?,?>) MetaData.getPrivateFieldValue(instance, "java.awt.GridBagLayout.comptable");
+ }
}
// Swing
@@ -1095,7 +1103,7 @@
// JFrame (If we do this for Window instead of JFrame, the setVisible call
// will be issued before we have added all the children to the JFrame and
// will appear blank).
-class javax_swing_JFrame_PersistenceDelegate extends DefaultPersistenceDelegate {
+static final class javax_swing_JFrame_PersistenceDelegate extends DefaultPersistenceDelegate {
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
super.initialize(type, oldInstance, newInstance, out);
java.awt.Window oldC = (java.awt.Window)oldInstance;
@@ -1115,7 +1123,7 @@
// Models
// DefaultListModel
-class javax_swing_DefaultListModel_PersistenceDelegate extends DefaultPersistenceDelegate {
+static final class javax_swing_DefaultListModel_PersistenceDelegate extends DefaultPersistenceDelegate {
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
// Note, the "size" property will be set here.
super.initialize(type, oldInstance, newInstance, out);
@@ -1129,7 +1137,7 @@
}
// DefaultComboBoxModel
-class javax_swing_DefaultComboBoxModel_PersistenceDelegate extends DefaultPersistenceDelegate {
+static final class javax_swing_DefaultComboBoxModel_PersistenceDelegate extends DefaultPersistenceDelegate {
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
super.initialize(type, oldInstance, newInstance, out);
javax.swing.DefaultComboBoxModel<?> m = (javax.swing.DefaultComboBoxModel<?>)oldInstance;
@@ -1141,7 +1149,7 @@
// DefaultMutableTreeNode
-class javax_swing_tree_DefaultMutableTreeNode_PersistenceDelegate extends DefaultPersistenceDelegate {
+static final class javax_swing_tree_DefaultMutableTreeNode_PersistenceDelegate extends DefaultPersistenceDelegate {
protected void initialize(Class<?> type, Object oldInstance, Object
newInstance, Encoder out) {
super.initialize(type, oldInstance, newInstance, out);
@@ -1157,7 +1165,7 @@
}
// ToolTipManager
-class javax_swing_ToolTipManager_PersistenceDelegate extends PersistenceDelegate {
+static final class javax_swing_ToolTipManager_PersistenceDelegate extends PersistenceDelegate {
protected Expression instantiate(Object oldInstance, Encoder out) {
return new Expression(oldInstance, javax.swing.ToolTipManager.class,
"sharedInstance", new Object[]{});
@@ -1165,7 +1173,7 @@
}
// JTabbedPane
-class javax_swing_JTabbedPane_PersistenceDelegate extends DefaultPersistenceDelegate {
+static final class javax_swing_JTabbedPane_PersistenceDelegate extends DefaultPersistenceDelegate {
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
super.initialize(type, oldInstance, newInstance, out);
javax.swing.JTabbedPane p = (javax.swing.JTabbedPane)oldInstance;
@@ -1180,7 +1188,7 @@
}
// Box
-class javax_swing_Box_PersistenceDelegate extends DefaultPersistenceDelegate {
+static final class javax_swing_Box_PersistenceDelegate extends DefaultPersistenceDelegate {
protected boolean mutatesTo(Object oldInstance, Object newInstance) {
return super.mutatesTo(oldInstance, newInstance) && getAxis(oldInstance).equals(getAxis(newInstance));
}
@@ -1201,7 +1209,7 @@
// Container will return all of the sub menu items that
// need to be added to the menu item.
// Not so for JMenu apparently.
-class javax_swing_JMenu_PersistenceDelegate extends DefaultPersistenceDelegate {
+static final class javax_swing_JMenu_PersistenceDelegate extends DefaultPersistenceDelegate {
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
super.initialize(type, oldInstance, newInstance, out);
javax.swing.JMenu m = (javax.swing.JMenu)oldInstance;
@@ -1219,7 +1227,7 @@
*
* @author Sergey A. Malenkov
*/
-final class javax_swing_border_MatteBorder_PersistenceDelegate extends PersistenceDelegate {
+static final class javax_swing_border_MatteBorder_PersistenceDelegate extends PersistenceDelegate {
protected Expression instantiate(Object oldInstance, Encoder out) {
MatteBorder border = (MatteBorder) oldInstance;
Insets insets = border.getBorderInsets();
@@ -1239,7 +1247,7 @@
}
/* XXX - doens't seem to work. Debug later.
-class javax_swing_JMenu_PersistenceDelegate extends DefaultPersistenceDelegate {
+static final class javax_swing_JMenu_PersistenceDelegate extends DefaultPersistenceDelegate {
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
super.initialize(type, oldInstance, newInstance, out);
javax.swing.JMenu m = (javax.swing.JMenu)oldInstance;
@@ -1261,7 +1269,7 @@
*
* @author Sergey A. Malenkov
*/
-final class sun_swing_PrintColorUIResource_PersistenceDelegate extends PersistenceDelegate {
+static final class sun_swing_PrintColorUIResource_PersistenceDelegate extends PersistenceDelegate {
protected boolean mutatesTo(Object oldInstance, Object newInstance) {
return oldInstance.equals(newInstance);
}
@@ -1273,7 +1281,6 @@
}
}
-class MetaData {
private static final Map<String,Field> fields = Collections.synchronizedMap(new WeakHashMap<String, Field>());
private static Hashtable<String, PersistenceDelegate> internalPersistenceDelegates = new Hashtable<>();
@@ -1316,7 +1323,7 @@
if (Enum.class.isAssignableFrom(type)) {
return enumPersistenceDelegate;
}
- if (ReflectionUtils.isPrimitive(type)) {
+ if (null != XMLEncoder.primitiveTypeFor(type)) {
return primitivePersistenceDelegate;
}
// The persistence delegate for arrays is non-trivial; instantiate it lazily.
@@ -1350,7 +1357,7 @@
internalPersistenceDelegates.put(typeName, defaultPersistenceDelegate);
try {
String name = type.getName();
- Class c = Class.forName("java.beans." + name.replace('.', '_')
+ Class c = Class.forName("java.beans.MetaData$" + name.replace('.', '_')
+ "_PersistenceDelegate");
pd = (PersistenceDelegate)c.newInstance();
internalPersistenceDelegates.put(typeName, pd);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/beans/XMLEncoder/java_awt_GridBagLayout.java Mon Apr 29 16:42:22 2013 +0400
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8007458
+ * @summary Tests GridBagLayout encoding
+ * @author Sergey Malenkov
+ */
+
+import java.awt.Component;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.lang.reflect.Field;
+import java.util.Hashtable;
+import java.util.Map;
+import javax.swing.JLabel;
+
+public final class java_awt_GridBagLayout extends AbstractTest<GridBagLayout> {
+ private static final Field HASHTABLE = getField("java.awt.GridBagLayout.comptable");
+
+ public static void main(String[] args) {
+ new java_awt_GridBagLayout().test(true);
+ }
+
+ @Override
+ protected GridBagLayout getObject() {
+ GridBagLayout layout = new GridBagLayout();
+ update(layout, "1", 1, 1);
+ update(layout, "2", 2, 2);
+ update(layout, "3", 3, 3);
+ return layout;
+ }
+
+ @Override
+ protected GridBagLayout getAnotherObject() {
+ GridBagLayout layout = new GridBagLayout();
+ update(layout, "11", 1, 1);
+ update(layout, "12", 1, 2);
+ update(layout, "21", 2, 1);
+ update(layout, "22", 2, 2);
+ return layout;
+ }
+
+ @Override
+ protected void validate(GridBagLayout before, GridBagLayout after) {
+ super.validate(before, after);
+ try {
+ Hashtable a = (Hashtable) HASHTABLE.get(after);
+ Hashtable b = (Hashtable) HASHTABLE.get(before);
+ super.validator.validate(a, b);
+
+// for (int i = 0; i < size; i++) {
+// validator.validate(NAME.get(a.get(i)), NAME.get(b.get(i)));
+// validator.validate(COMP.get(a.get(i)), COMP.get(b.get(i)));
+// }
+ }
+ catch (Exception exception) {
+ throw new Error(exception);
+ }
+
+
+
+// for (String name : names) {
+// validator.validate(getConstraints(before, name), getConstraints(after, name));
+// }
+ }
+
+ private static void update(GridBagLayout layout, String id, int x, int y) {
+ GridBagConstraints gbc = new GridBagConstraints();
+ gbc.gridx = x;
+ gbc.gridy = y;
+ layout.addLayoutComponent(new JLabel(id), gbc);
+ }
+
+/*
+ private static GridBagConstraints getConstraints(GridBagLayout layout, String id) {
+ return (layout == null) ? null : ((MyGridBagLayout) layout).getConstraints(id);
+ }
+*/
+}