// we have to do this before the merging, as it does some classloader resolving
String lastType = null;
try {
// Add the type declarations to the RuleBase
if ( newPkg.getTypeDeclarations() != null ) {
JavaDialectRuntimeData runtime = ((JavaDialectRuntimeData) newPkg.getDialectRuntimeRegistry().getDialectData( "java" ));
// add type declarations
for ( TypeDeclaration newDecl : newPkg.getTypeDeclarations().values() ) {
lastType = newDecl.getTypeClassName();
TypeDeclaration typeDeclaration = this.classTypeDeclaration.get( newDecl.getTypeClassName() );
if ( typeDeclaration == null ) {
String className = newDecl.getTypeClassName();
byte [] def = runtime.getClassDefinition(convertClassToResourcePath(className));
Class<?> definedKlass = registerAndLoadTypeDefinition( className, def );
if ( definedKlass == null && typeDeclaration.isNovel() ) {
throw new RuntimeException( "Registering null bytes for class " + className );
}
if (newDecl.getTypeClassDef() == null) {
newDecl.setTypeClassDef( new ClassDefinition() );
}
newDecl.getTypeClassDef().setDefinedClass( definedKlass );
newDecl.setTypeClass( definedKlass );
this.classTypeDeclaration.put( className, newDecl );
typeDeclaration = newDecl;
} else {
Class<?> definedKlass = typeDeclaration.getTypeClass();
newDecl.getTypeClassDef().setDefinedClass( definedKlass );
newDecl.setTypeClass( definedKlass );
mergeTypeDeclarations( typeDeclaration,
newDecl );
}
// update existing OTNs
updateDependentTypes( newPkg,
typeDeclaration );
}
for ( Function function : newPkg.getFunctions().values() ) {
String functionClassName = function.getClassName();
byte [] def = runtime.getStore().get(convertClassToResourcePath(functionClassName));
registerAndLoadTypeDefinition( functionClassName, def );
}
}
} catch (ClassNotFoundException e) {
throw new RuntimeDroolsException( "unable to resolve Type Declaration class '" + lastType + "'", e );