FileDocCategorySizeDatePackage
SerializableBeanGenerator.javaAPI DocGlassfish v2 API7094Fri May 04 22:32:58 BST 2007com.sun.ejb.codegen

SerializableBeanGenerator

public class SerializableBeanGenerator extends Generator implements ClassGeneratorFactory
This class is used to generate a Serializable sub-class of a 3.0 stateful session bean.

Fields Summary
private static com.sun.enterprise.util.LocalStringManagerImpl
localStrings
private static Logger
_logger
private Class
beanClass
private String
generatedSerializableClassName
private ClassLoader
loader
Constructors Summary
public SerializableBeanGenerator(ClassLoader cl, String beanClassName)

	super();

        loader = cl;
	try {
	    beanClass = cl.loadClass(beanClassName);
	} catch (ClassNotFoundException ex) {
	    throw new InvalidBean(
		localStrings.getLocalString(
		"generator.remote_interface_not_found",
		"Remote interface not found "));
	}

        generatedSerializableClassName = 
            EJBUtils.getGeneratedSerializableClassName(beanClassName);

    
Methods Summary
public java.lang.StringclassName()

        return getGeneratedClass();
    
public com.sun.corba.ee.impl.codegen.ClassGeneratorevaluate()


        _clear();

	String packageName = getPackageName(generatedSerializableClassName);
        String simpleName = getBaseName(generatedSerializableClassName);
        
        if( packageName != null ) {
            _package(packageName);
        } else {
            // no-arg _package() call is required for default package
            _package();
        }

        List toImplement = new LinkedList<Type>();
        toImplement.add(_t("java.io.Serializable"));
        _class(PUBLIC, simpleName, _t(beanClass.getName()), toImplement);

        _constructor( PUBLIC ) ;
        _body();
        _expr(_super(_s(_void()))) ;
        _end();

        _method( PRIVATE, _void(), "writeObject", _t("java.io.IOException"));
            _arg( _t("java.io.ObjectOutputStream"), "oos" );
        _body();
            _expr(_call( _t("com.sun.ejb.EJBUtils"), "serializeObjectFields",
                   _s(_void(), 
                      _Class(), _Object(), _t("java.io.ObjectOutputStream")),
                   _const(_t(beanClass.getName())), _this(), 
                   _v("oos")));
        _end();


        _method( PRIVATE, _void(), "readObject", _t("java.io.IOException"),
                 _t("java.lang.ClassNotFoundException") );
            _arg( _t("java.io.ObjectInputStream"), "ois" );
        _body();
            _expr(_call( _t("com.sun.ejb.EJBUtils"), "deserializeObjectFields",
                   _s(_void(), 
                      _Class(), _Object(), _t("java.io.ObjectInputStream")),
                   _const(_t(beanClass.getName())), _this(), 
                   _v("ois")));
        _end();
     
        _end();

        return _classGenerator() ;
    
public voidgenerate(java.io.OutputStream out)
Generate the code to the specified output stream.

param
the output stream
exception
GeneratorException on a generation error
exception
IOException on an IO error

	IndentingWriter p = new IndentingWriter(new OutputStreamWriter(out));

	String packageName = getPackageName(generatedSerializableClassName);
        String simpleName = getBaseName(generatedSerializableClassName);

        p.pln("");

	if (packageName != null) {
	    p.pln("package " + packageName + ";");
        }

        p.pln("");

	p.plnI("public class " + simpleName + " extends " + beanClass.getName()
               + " implements java.io.Serializable { ");

        p.pln("");

        p.plnI("private void writeObject(java.io.ObjectOutputStream oos) throws java.io.IOException {");
        p.pln("    com.sun.ejb.EJBUtils.serializeObjectFields(" +
              beanClass.getName() + ".class, this, oos);");
        p.pln("}");

        p.plnI("private void readObject(java.io.ObjectInputStream ois) throws java.io.IOException, java.lang.ClassNotFoundException {");
        p.pln("    com.sun.ejb.EJBUtils.deserializeObjectFields(" +
              beanClass.getName() + ".class, this, ois);");
        p.pln("}");

	p.pOln("}");
	p.close();
    
public java.lang.StringgetGeneratedClass()
Get the fully qualified name of the generated class.

return
the name of the generated class.

        return generatedSerializableClassName;