[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

can you store and retrieve instances of this class in ozone?




Hi.  I am following up on my troubles with serializing GUI items, then
ozone-storing them.  They are Swing components.  The following class
serializes and deserializes fine.  It also appears to store fine in
ozone, but I don't know how to verify that it does.  It does not retrieve,
however.

It is Sun's workaround to JInternalFrame which is known to be buggy for
serialization.  The item fixed here is the adding and removing listeners.

In Ozone, for some reason, retrieving it produces a null pointer exception,
even though the object in the db is non-null.

The same client code operating on other JComponent Swing components
works fine.  My Impl class has a simple 1-arg "store" and "retrieve"
methods storing and recalling a JComponent.

Could someone test-drive instances of the following class, perhaps
populating it with different stuff, and let me know how it goes, for
Ozone db storing and retrieval:

/*

This workaround only applies to Kestrel [Java 2 SDK 1.3 -- Marek].  
We need to remove the
EnableSerializationFocusListener instance added by
JComponent.enableSerialization() since it's missing a call to
super.compWriteObjectNotify().  In Kestrel we can get at the list of
Listeners with Component.getListeners() - which makes it possible to
remove the broken FocusListener.  So a subclass of JInternalFrame can
hack around this problem by removing the offending listener and adding
one that does the right thing.

[Note: this workaround was written by xxxxx@xxxxx]


 */

package edu.nwu.sesp.marek;

import javax.swing.*;
import javax.swing.event.*;     
import java.awt.*;              
import java.awt.event.*;        //for action and window events
import java.io.*;
import java.util.zip.*;
import java.util.*;


public class JInternalFixed extends JInternalFrame
{

    // [Note: this workaround was written by xxxxx@xxxxx]:


    public JInternalFixed (String a, 
			   boolean b, 
			   boolean c,
			   boolean d,
			   boolean e) 
    {
	super(a,b,c,d,e);
	EventListener[] esfl = getListeners(FocusListener.class);
	if (esfl.length != 0) removeFocusListener((FocusListener)esfl[0]);
	enableEvents(AWTEvent.FOCUS_EVENT_MASK | AWTEvent.KEY_EVENT_MASK);
	addFocusListener(new EnableSerializationFocusListener());
    }

    private class EnableSerializationFocusListener implements FocusListener, Serializable
    {
	public void focusGained(FocusEvent e) 
	{}
	
	public void focusLost(FocusEvent e) 
	{}

	private void writeObject(ObjectOutputStream s) throws IOException 
	{
	    s.defaultWriteObject();
	    JInternalFixed.this.compWriteObjectNotify();
	}
    }

    void compWriteObjectNotify() 
    {
	boolean old = isRootPaneCheckingEnabled();
	try 
	    {
		setRootPaneCheckingEnabled(false);
		if (ui != null) 
		    {
			ui.uninstallUI(this);
		    }
	    }
	finally 
	    {
		setRootPaneCheckingEnabled(old);
	    }
	

    }

} // class JInternalFixed extends JInternalFrame