[jboss-svn-commits] JBL Code SVN: r19266 - labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/common.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Mar 27 12:04:41 EDT 2008


Author: mingjin
Date: 2008-03-27 12:04:41 -0400 (Thu, 27 Mar 2008)
New Revision: 19266

Modified:
   labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
Log:
JBRULES-1535 User provided packages with the same name were merged/changed after calling RuleBase.addPackage
- AbstractRuleBase: checking for null containers in add/mergePackage's.

Modified: labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java	2008-03-27 15:54:55 UTC (rev 19265)
+++ labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java	2008-03-27 16:04:41 UTC (rev 19266)
@@ -451,27 +451,31 @@
 
             final Map newGlobals = newPkg.getGlobals();
 
-            // Check that the global data is valid, we cannot change the type
-            // of an already declared global variable
-            for ( final Iterator it = newGlobals.keySet().iterator(); it.hasNext(); ) {
-                final String identifier = (String) it.next();
-                final Class type = (Class) newGlobals.get( identifier );
-                final boolean f = this.globals.containsKey( identifier );
-                if ( f ) {
-                    final boolean y = !this.globals.get( identifier ).equals( type );
-                    if ( f && y ) {
-                        throw new PackageIntegrationException( pkg );
+            if (newGlobals != null) {
+                // Check that the global data is valid, we cannot change the type
+                // of an already declared global variable
+                for ( final Iterator it = newGlobals.keySet().iterator(); it.hasNext(); ) {
+                    final String identifier = (String) it.next();
+                    final Class type = (Class) newGlobals.get( identifier );
+                    final boolean f = this.globals.containsKey( identifier );
+                    if ( f ) {
+                        final boolean y = !this.globals.get( identifier ).equals( type );
+                        if ( f && y ) {
+                            throw new PackageIntegrationException( pkg );
+                        }
                     }
                 }
+                this.globals.putAll( newGlobals );
             }
-            this.globals.putAll( newGlobals );
 
-            // Add type declarations
-            for ( TypeDeclaration type : newPkg.getTypeDeclarations().values() ) {
-                // should we allow overrides?
-                if ( !this.classTypeDeclaration.containsKey( type.getTypeClass() ) ) {
-                    this.classTypeDeclaration.put( type.getTypeClass(),
-                                                   type );
+            if (newPkg.getTypeDeclarations() != null) {
+                // Add type declarations
+                for ( TypeDeclaration type : newPkg.getTypeDeclarations().values() ) {
+                    // should we allow overrides?
+                    if ( !this.classTypeDeclaration.containsKey( type.getTypeClass() ) ) {
+                        this.classTypeDeclaration.put( type.getTypeClass(),
+                                                       type );
+                    }
                 }
             }
 
@@ -483,7 +487,7 @@
             }
 
             //and now the rule flows
-            if ( newPkg.getRuleFlows() != Collections.EMPTY_MAP ) {
+            if ( newPkg.getRuleFlows() != null ) {
                 final Map flows = newPkg.getRuleFlows();
                 for ( final Iterator iter = flows.entrySet().iterator(); iter.hasNext(); ) {
                     final Entry flow = (Entry) iter.next();
@@ -518,34 +522,38 @@
         // Merge imports
         imports.putAll( newPkg.getImports() );
 
-        // Add globals
-        for ( final Iterator it = newPkg.getGlobals().keySet().iterator(); it.hasNext(); ) {
-            final String identifier = (String) it.next();
-            final Class type = (Class) globals.get( identifier );
-            if ( globals.containsKey( identifier ) && !globals.get( identifier ).equals( type ) ) {
-                throw new PackageIntegrationException( "Unable to merge new Package",
-                                                       newPkg );
+        if (newPkg.getGlobals() != null) {
+            // Add globals
+            for ( final Iterator it = newPkg.getGlobals().keySet().iterator(); it.hasNext(); ) {
+                final String identifier = (String) it.next();
+                final Class type = (Class) globals.get( identifier );
+                if ( globals.containsKey( identifier ) && !globals.get( identifier ).equals( type ) ) {
+                    throw new PackageIntegrationException( "Unable to merge new Package",
+                                                           newPkg );
+                }
             }
-        }
-        if (globals == Collections.EMPTY_MAP) {
-            for (Object object : newPkg.getGlobals().entrySet()) {
-                Map.Entry   entry   = (Map.Entry)object;
-                pkg.addGlobal((String)entry.getKey(), (Class)entry.getValue());
+            if (globals == Collections.EMPTY_MAP) {
+                for (Object object : newPkg.getGlobals().entrySet()) {
+                    Map.Entry   entry   = (Map.Entry)object;
+                    pkg.addGlobal((String)entry.getKey(), (Class)entry.getValue());
+                }
+            } else {
+                globals.putAll( newPkg.getGlobals() );
             }
-        } else {
-            globals.putAll( newPkg.getGlobals() );
         }
 
-        // add type declarations
-        for ( TypeDeclaration type : newPkg.getTypeDeclarations().values() ) {
-            // should we allow overrides?
-            if ( !this.classTypeDeclaration.containsKey( type.getTypeClass() ) ) {
-                this.classTypeDeclaration.put( type.getTypeClass(),
-                                               type );
+        if (newPkg.getTypeDeclarations() != null) {
+            // add type declarations
+            for ( TypeDeclaration type : newPkg.getTypeDeclarations().values() ) {
+                // should we allow overrides?
+                if ( !this.classTypeDeclaration.containsKey( type.getTypeClass() ) ) {
+                    this.classTypeDeclaration.put( type.getTypeClass(),
+                                                   type );
+                }
+                if ( !pkg.getTypeDeclarations().containsKey( type.getTypeName() ) ) {
+                    pkg.addTypeDeclaration( type );
+                }
             }
-            if ( !pkg.getTypeDeclarations().containsKey( type.getTypeName() ) ) {
-                pkg.addTypeDeclaration( type );
-            }
         }
 
         //Add rules into the RuleBase package
@@ -564,7 +572,7 @@
         }
 
         //and now the rule flows
-        if ( newPkg.getRuleFlows() != Collections.EMPTY_MAP ) {
+        if ( newPkg.getRuleFlows() != null ) {
             final Map flows = newPkg.getRuleFlows();
             for ( final Iterator iter = flows.values().iterator(); iter.hasNext(); ) {
                 final Process flow = (Process) iter.next();




More information about the jboss-svn-commits mailing list