loader1 );
KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder( conf );
builder.add( ResourceFactory.newInputStreamResource( getClass().getResourceAsStream( "test_EnumSerialization.drl" ) ),
ResourceType.DRL );
Collection<KnowledgePackage> pkgs = builder.getKnowledgePackages();
KnowledgePackage pkg = pkgs.iterator().next();
// serialize out
byte[] out = DroolsStreamUtils.streamOut( pkg );
// adding original packages to a kbase just to make sure they are fine
KnowledgeBaseConfiguration kbaseConf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration( null,
loader1 );
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase( kbaseConf );
kbase.addKnowledgePackages( pkgs );
// now, create another classloader and make sure it has access to the classes
ClassLoader loader2 = new SubvertedClassLoader( new URL[]{getClass().getResource( "/testEnum.jar" )},
this.getClass().getClassLoader() );
//loader2.loadClass( "org.drools.Primitives" );
//loader2.loadClass( "org.drools.TestEnum" );
// set context classloader and use it
ClassLoader ccl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader( loader2 );
KnowledgePackage pkg2 = (KnowledgePackage) DroolsStreamUtils.streamIn( out );
Collection<KnowledgePackage> pkgs2 = Collections.singleton( pkg2 );
Thread.currentThread().setContextClassLoader( ccl );
// create another kbase
KnowledgeBaseConfiguration kbaseConf2 = KnowledgeBaseFactory.newKnowledgeBaseConfiguration( null,