/**
* 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.
*/
public void writeExternal( final ObjectOutput out ) throws IOException {
ObjectOutput droolsStream;
boolean isDrools = out instanceof DroolsObjectOutputStream;
ByteArrayOutputStream bytes;
if (isDrools) {
droolsStream = out;
bytes = null;
} else {
bytes = new ByteArrayOutputStream();
droolsStream = new DroolsObjectOutputStream( bytes );
}
// must write this option first in order to properly deserialize later
droolsStream.writeBoolean( this.config.isClassLoaderCacheEnabled() );
droolsStream.writeObject( this.declarationClassLoader.getStore() );
droolsStream.writeObject( this.config );
droolsStream.writeObject( this.pkgs );
// Rules must be restored by an ObjectInputStream that can resolve using a given ClassLoader to handle seaprately by storing as
// a byte[]
droolsStream.writeObject( this.id );
droolsStream.writeInt( this.workingMemoryCounter.get() );
droolsStream.writeObject( this.processes );
droolsStream.writeObject( this.agendaGroupRuleTotals );
droolsStream.writeUTF( this.factHandleFactory.getClass().getName() );
droolsStream.writeObject( buildGlobalMapForSerialization() );
droolsStream.writeObject( this.partitionIDs );
this.eventSupport.removeEventListener( RuleBaseEventListener.class );
droolsStream.writeObject( this.eventSupport );
if (!isDrools) {
droolsStream.flush();
droolsStream.close();
bytes.close();
out.writeObject( bytes.toByteArray() );
}
}