Skip to content

Commit

Permalink
JBRULES-3145 BZ-811745: improving the agent code to handle different
Browse files Browse the repository at this point in the history
types of serialized packages - Phase 3.
  • Loading branch information
manstis committed Apr 25, 2012
1 parent 5fadf55 commit 2222a7f
Showing 1 changed file with 33 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,31 +81,35 @@ public void addPackage(InputStream in) {

/**
* This will add the BINARY package to the rulebase.
* @param in An input stream to the serialized package.
* @param classLoader used as the parent ClassLoader for the Package's internal ClassLaoder
*
* @param in
* An input stream to the serialized package.
* @param classLoader
* used as the parent ClassLoader for the Package's internal
* ClassLaoder
*/
public void addPackage(InputStream in, ClassLoader classLoader) {
public void addPackage(InputStream in,
ClassLoader classLoader) {
if ( classLoader == null ) {
classLoader = this.classLoader;
}

try {
Object opkg = DroolsStreamUtils.streamIn(in, classLoader);
if ( !(opkg instanceof Package) ) {

Object opkg = DroolsStreamUtils.streamIn( in,
classLoader );

if ( opkg instanceof Package ) {
Package pkg = (Package) opkg;
addPackage( pkg );
} else if ( opkg instanceof Package[] ) {
Package[] pkgs = (Package[]) opkg;
for ( Package pkg : pkgs ) {
addPackage( pkg );
}
} else {
throw new IllegalArgumentException( "Can only add instances of org.drools.rule.Package to a rulebase instance." );
}
Package binPkg = (Package) opkg;

if ( !binPkg.isValid() ) {
throw new IllegalArgumentException( "Can't add a non valid package to a rulebase." );
}

try {
this.ruleBase.addPackage( binPkg );
} catch ( Exception e ) {
throw new RuntimeDroolsException( "Unable to add package to the rulebase.",
e );
}

} catch ( IOException e ) {
throw new RuntimeDroolsException( e );
Expand All @@ -120,6 +124,18 @@ public void addPackage(InputStream in, ClassLoader classLoader) {
}

}

private void addPackage(Package pkg) {
if ( !pkg.isValid() ) {
throw new IllegalArgumentException( "Can't add a non valid package to a rulebase." );
}
try {
this.ruleBase.addPackage( pkg );
} catch ( Exception e ) {
throw new RuntimeDroolsException( "Unable to add package to the rulebase.",
e );
}
}

public RuleBase getRuleBase() {
return this.ruleBase;
Expand Down

0 comments on commit 2222a7f

Please sign in to comment.