public void writeExternal(ObjectOutput stream) throws IOException {
        boolean isDroolsStream = stream instanceof DroolsObjectOutputStream;
        ByteArrayOutputStream bytes = null;
        ObjectOutput out;

        if (isDroolsStream) {
            out = stream;
        } else {
            bytes = new ByteArrayOutputStream();
            out = new DroolsObjectOutputStream(bytes);
        }

        out.writeObject(this.name);
        out.writeObject(this.classFieldAccessorStore);
        out.writeObject(this.dialectRuntimeRegistry);
        out.writeObject(this.typeDeclarations);
        out.writeObject(this.imports);
        out.writeObject(this.staticImports);
        out.writeObject(this.functions);
        out.writeObject(this.accumulateFunctions);
        out.writeObject(this.factTemplates);
        out.writeObject(this.globals);
        out.writeBoolean(this.valid);
        out.writeBoolean(this.needStreamMode);
        out.writeObject(this.rules);
        out.writeObject(this.entryPointsIds);
        out.writeObject(this.windowDeclarations);
        out.writeObject(this.traitRegistry);
        out.writeObject(this.resourceTypePackages);
        // writing the whole stream as a byte array
        if (!isDroolsStream) {
            bytes.flush();
            bytes.close();
            stream.writeObject(bytes.toByteArray());
        }
    }
public void writeExternal ( ObjectOutput stream ) throws IOException { boolean isDroolsStream = stream instanceof DroolsObjectOutputStream ; ByteArrayOutputStream bytes = null ; ObjectOutput out ; if ( isDroolsStream ) { out = stream ; } else { bytes = new ByteArrayOutputStream ( ) ; out = new DroolsObjectOutputStream ( bytes ) ; } out . writeObject ( this . name ) ; out . writeObject ( this . classFieldAccessorStore ) ; out . writeObject ( this . dialectRuntimeRegistry ) ; out . writeObject ( this . typeDeclarations ) ; out . writeObject ( this . imports ) ; out . writeObject ( this . staticImports ) ; out . writeObject ( this . functions ) ; out . writeObject ( this . accumulateFunctions ) ; out . writeObject ( this . factTemplates ) ; out . writeObject ( this . globals ) ; out . writeBoolean ( this . valid ) ; out . writeBoolean ( this . needStreamMode ) ; out . writeObject ( this . rules ) ; out . writeObject ( this . entryPointsIds ) ; out . writeObject ( this . windowDeclarations ) ; out . writeObject ( this . traitRegistry ) ; out . writeObject ( this . resourceTypePackages ) ; if ( ! isDroolsStream ) { bytes . flush ( ) ; bytes . close ( ) ; stream . writeObject ( bytes . toByteArray ( ) ) ; } }
Handles the write serialization of the Package. Patterns in Rules may
reference generated data which cannot be serialized by default methods.
The Package uses PackageCompilationData to hold a reference to the
generated bytecode. The generated bytecode must be restored before any
Rules.

@param stream out the stream to write the object to; should be an instance
of DroolsObjectOutputStream or OutputStream