JDK-6501431 : LTP: The property "accelerator" could not be serialized into XML
Type:Bug
Component:client-libs
Sub-Component:java.beans
Affected Version:7
Priority:P4
Status:Closed
Resolution:Fixed
OS:windows_xp
CPU:x86
Submitted:2006-12-06
Updated:2011-03-08
Resolved:2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.
Unresolved : Release in which this issue/RFE will be addressed. Resolved: Release in which this issue/RFE has been resolved. Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.
XMLEncoder does not serialize a value of the property "accelerator" in JMenu and JMenuItem classes.
Comments
EVALUATION
The property accelerator of the class JMenu is readonly.
So we can support the property accelerator only in the class JMenuItem.
11-12-2006
WORK AROUND
Use the following persistence delegate:
import java.awt.event.KeyEvent;
import java.beans.Encoder;
import java.beans.Expression;
import java.beans.PersistenceDelegate;
import javax.swing.KeyStroke;
public class KeyStrokePersistenceDelegate
extends PersistenceDelegate
{
protected boolean mutatesTo( Object oldInstance, Object newInstance )
{
return oldInstance.equals( newInstance );
}
protected Expression instantiate( Object oldInstance, Encoder out )
{
KeyStroke key = ( KeyStroke )oldInstance;
char ch = key.getKeyChar();
int code = key.getKeyCode();
int mask = key.getModifiers();
boolean onKeyRelease = key.isOnKeyRelease();
Object[] args = null;
if ( ch == KeyEvent.CHAR_UNDEFINED )
{
args = !onKeyRelease
? new Object[]{code, mask}
: new Object[]{code, mask, onKeyRelease};
}
else if ( code == KeyEvent.VK_UNDEFINED )
{
if ( !onKeyRelease )
{
args = ( mask == 0 )
? new Object[]{ch}
: new Object[]{ch, mask};
}
else if ( mask == 0 )
{
args = new Object[]{ch, onKeyRelease};
}
}
if ( args == null )
throw new IllegalStateException( "Unsupported KeyStroke: " + key );
return new Expression( key, KeyStroke.class, "getKeyStroke", args );
}
}
06-12-2006
EVALUATION
It is necessary to create appropriate persistence delegate for KeyStroke and AWTKeyStroke classes.
Also we should not mark the property "accelerator" as transient in MetaData.