The complete code of a simple Java 3D bean is shown below. Notice there
are no class member variables at all. The bean throws
NotSerializableException, etc. on attempted serialization from BeanBox.
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;
import java.awt.BorderLayout;
import java.awt.GraphicsConfiguration;
import java.io.*;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.swing.JPanel;
public class WindowOnMyUniverse extends JPanel {
public WindowOnMyUniverse( ) {
super( );
setLayout( new BorderLayout( ) );
GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration( );
Canvas3D canvas = new Canvas3D( config );
add( "Center", canvas );
SimpleUniverse myUniverse = new SimpleUniverse( canvas );
myUniverse.getViewingPlatform( ).setNominalViewingTransform( );
myUniverse.addBranchGraph( createSceneGraph( ) );
setSize( 400, 400 );
setVisible( true );
}
private BranchGroup createSceneGraph( ) {
BranchGroup root = new BranchGroup( );
ColorCube cube = new ColorCube( 0.4 );
root.addChild( cube );
return root;
}
}
The only way to remedy the problem was to implement Externalizable like
below. Now it serializes fine.
public class WindowOnMyUniverse extends JPanel implements Externalizable
{
[blah, blah, blah]
public void writeExternal( ObjectOutput out ) throws IOException {
}
public void readExternal( ObjectInput in ) throws IOException,
ClassNotFoundException {
}
}
A final interesting note is that when the bean is implementing
Externalizable like above deserialization should result in a call the no
args constructor and then a call to the readExternal() method. The no
args constructor of this bean should rebuild everything but it doesn't.
I tried the obvious alternative and put all of the code in the
constructor into an initBean() method then made a call to initBean() in
the readExternal() method but it still didn't work.
This doesn't work at all like Java object serialization is
supposed to, at least as I understand it. Comments?
Don
NeoVision Hypersystems
=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 3D Home Page: http://java.sun.com/products/java-media/3D/