提交 cf2fc83f 编写于 作者: M malenkov

6479191: LTP: XMLEncoder does not update initialized property of GridBagConstraints type

Reviewed-by: rupashka
上级 9d98d838
...@@ -222,6 +222,25 @@ public class DefaultPersistenceDelegate extends PersistenceDelegate { ...@@ -222,6 +222,25 @@ public class DefaultPersistenceDelegate extends PersistenceDelegate {
// Write out the properties of this instance. // Write out the properties of this instance.
private void initBean(Class type, Object oldInstance, Object newInstance, Encoder out) { private void initBean(Class type, Object oldInstance, Object newInstance, Encoder out) {
for (Field field : type.getFields()) {
int mod = field.getModifiers();
if (Modifier.isFinal(mod) || Modifier.isStatic(mod) || Modifier.isTransient(mod)) {
continue;
}
try {
Expression oldGetExp = new Expression(field, "get", new Object[] { oldInstance });
Expression newGetExp = new Expression(field, "get", new Object[] { newInstance });
Object oldValue = oldGetExp.getValue();
Object newValue = newGetExp.getValue();
out.writeExpression(oldGetExp);
if (!equals(newValue, out.get(oldValue))) {
out.writeStatement(new Statement(field, "set", new Object[] { oldInstance, oldValue }));
}
}
catch (Exception exception) {
out.getExceptionListener().exceptionThrown(exception);
}
}
BeanInfo info; BeanInfo info;
try { try {
info = Introspector.getBeanInfo(type); info = Introspector.getBeanInfo(type);
......
...@@ -700,56 +700,6 @@ class java_beans_beancontext_BeanContextSupport_PersistenceDelegate extends java ...@@ -700,56 +700,6 @@ class java_beans_beancontext_BeanContextSupport_PersistenceDelegate extends java
// AWT // AWT
/**
* The persistence delegate for {@link Dimension}.
* It is impossible to use {@link DefaultPersistenceDelegate}
* because all getters have return types that differ from parameter types
* of the constructor {@link Dimension#Dimension(int, int)}.
*
* @author Sergey A. Malenkov
*/
final class java_awt_Dimension_PersistenceDelegate extends PersistenceDelegate {
protected boolean mutatesTo(Object oldInstance, Object newInstance) {
return oldInstance.equals(newInstance);
}
protected Expression instantiate(Object oldInstance, Encoder out) {
Dimension dimension = (Dimension) oldInstance;
Object[] args = new Object[] {
dimension.width,
dimension.height,
};
return new Expression(dimension, dimension.getClass(), "new", args);
}
}
/**
* The persistence delegate for {@link GridBagConstraints}.
* It is impossible to use {@link DefaultPersistenceDelegate}
* because this class does not have any properties.
*
* @author Sergey A. Malenkov
*/
final class java_awt_GridBagConstraints_PersistenceDelegate extends PersistenceDelegate {
protected Expression instantiate(Object oldInstance, Encoder out) {
GridBagConstraints gbc = (GridBagConstraints) oldInstance;
Object[] args = new Object[] {
gbc.gridx,
gbc.gridy,
gbc.gridwidth,
gbc.gridheight,
gbc.weightx,
gbc.weighty,
gbc.anchor,
gbc.fill,
gbc.insets,
gbc.ipadx,
gbc.ipady,
};
return new Expression(gbc, gbc.getClass(), "new", args);
}
}
/** /**
* The persistence delegate for {@link Insets}. * The persistence delegate for {@link Insets}.
* It is impossible to use {@link DefaultPersistenceDelegate} * It is impossible to use {@link DefaultPersistenceDelegate}
...@@ -774,54 +724,6 @@ final class java_awt_Insets_PersistenceDelegate extends PersistenceDelegate { ...@@ -774,54 +724,6 @@ final class java_awt_Insets_PersistenceDelegate extends PersistenceDelegate {
} }
} }
/**
* The persistence delegate for {@link Point}.
* It is impossible to use {@link DefaultPersistenceDelegate}
* because all getters have return types that differ from parameter types
* of the constructor {@link Point#Point(int, int)}.
*
* @author Sergey A. Malenkov
*/
final class java_awt_Point_PersistenceDelegate extends PersistenceDelegate {
protected boolean mutatesTo(Object oldInstance, Object newInstance) {
return oldInstance.equals(newInstance);
}
protected Expression instantiate(Object oldInstance, Encoder out) {
Point point = (Point) oldInstance;
Object[] args = new Object[] {
point.x,
point.y,
};
return new Expression(point, point.getClass(), "new", args);
}
}
/**
* The persistence delegate for {@link Rectangle}.
* It is impossible to use {@link DefaultPersistenceDelegate}
* because all getters have return types that differ from parameter types
* of the constructor {@link Rectangle#Rectangle(int, int, int, int)}.
*
* @author Sergey A. Malenkov
*/
final class java_awt_Rectangle_PersistenceDelegate extends PersistenceDelegate {
protected boolean mutatesTo(Object oldInstance, Object newInstance) {
return oldInstance.equals(newInstance);
}
protected Expression instantiate(Object oldInstance, Encoder out) {
Rectangle rectangle = (Rectangle) oldInstance;
Object[] args = new Object[] {
rectangle.x,
rectangle.y,
rectangle.width,
rectangle.height,
};
return new Expression(rectangle, rectangle.getClass(), "new", args);
}
}
/** /**
* The persistence delegate for {@link Font}. * The persistence delegate for {@link Font}.
* It is impossible to use {@link DefaultPersistenceDelegate} * It is impossible to use {@link DefaultPersistenceDelegate}
......
...@@ -407,7 +407,20 @@ public class XMLEncoder extends Encoder { ...@@ -407,7 +407,20 @@ public class XMLEncoder extends Encoder {
os.writeObject(this); os.writeObject(this);
*/ */
mark(oldStm); mark(oldStm);
statementList(oldStm.getTarget()).add(oldStm); Object target = oldStm.getTarget();
if (target instanceof Field) {
String method = oldStm.getMethodName();
Object[] args = oldStm.getArguments();
if ((method == null) || (args == null)) {
}
else if (method.equals("get") && (args.length == 1)) {
target = args[0];
}
else if (method.equals("set") && (args.length == 2)) {
target = args[0];
}
}
statementList(target).add(oldStm);
} }
catch (Exception e) { catch (Exception e) {
getExceptionListener().exceptionThrown(new Exception("XMLEncoder: discarding statement " + oldStm, e)); getExceptionListener().exceptionThrown(new Exception("XMLEncoder: discarding statement " + oldStm, e));
...@@ -703,7 +716,9 @@ public class XMLEncoder extends Encoder { ...@@ -703,7 +716,9 @@ public class XMLEncoder extends Encoder {
statements.add(exp); statements.add(exp);
} }
outputValue(target, outer, false); outputValue(target, outer, false);
outputValue(value, outer, isArgument); if (expression) {
outputValue(value, outer, isArgument);
}
return; return;
} }
if (expression && (d.refs > 1)) { if (expression && (d.refs > 1)) {
...@@ -722,8 +737,10 @@ public class XMLEncoder extends Encoder { ...@@ -722,8 +737,10 @@ public class XMLEncoder extends Encoder {
} }
else if ((!expression && methodName.startsWith("set") && args.length == 1) || else if ((!expression && methodName.startsWith("set") && args.length == 1) ||
(expression && methodName.startsWith("get") && args.length == 0)) { (expression && methodName.startsWith("get") && args.length == 0)) {
attributes = attributes + " property=" + if (3 < methodName.length()) {
quote(Introspector.decapitalize(methodName.substring(3))); attributes = attributes + " property=" +
quote(Introspector.decapitalize(methodName.substring(3)));
}
} }
else if (!methodName.equals("new") && !methodName.equals("newInstance")) { else if (!methodName.equals("new") && !methodName.equals("newInstance")) {
attributes = attributes + " method=" + quote(methodName); attributes = attributes + " method=" + quote(methodName);
......
...@@ -55,7 +55,6 @@ public final class java_awt_GridBagConstraints extends AbstractTest<GridBagConst ...@@ -55,7 +55,6 @@ public final class java_awt_GridBagConstraints extends AbstractTest<GridBagConst
} }
protected GridBagConstraints getAnotherObject() { protected GridBagConstraints getAnotherObject() {
return null; // TODO: could not update property return new GridBagConstraints();
// return new GridBagConstraints();
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册