[jboss-svn-commits] JBL Code SVN: r17491 - in labs/jbossrules/trunk/drools-compiler/src: main/java/org/drools/xml/processes and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Jan 2 07:49:25 EST 2008


Author: mark.proctor at jboss.com
Date: 2008-01-02 07:49:25 -0500 (Wed, 02 Jan 2008)
New Revision: 17491

Modified:
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilderConfiguration.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/processes/StartNodeHandler.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/Cheese.java
Log:
JBRULES-1394 RuleFlow Nodes should be pluggable
-PackageBuilder node builders are now pluggable, although not yet discoverable
-RuleBase node instance factories and pluggeable and discoverable
-added unit tests for start and end nodes

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilderConfiguration.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilderConfiguration.java	2008-01-02 12:33:57 UTC (rev 17490)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilderConfiguration.java	2008-01-02 12:49:25 UTC (rev 17491)
@@ -16,9 +16,6 @@
  * limitations under the License.
  */
 
-import java.io.File;
-import java.io.IOException;
-import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Collections;
 import java.util.HashMap;
@@ -32,6 +29,8 @@
 import org.drools.base.evaluators.EvaluatorDefinition;
 import org.drools.base.evaluators.EvaluatorRegistry;
 import org.drools.util.ChainedProperties;
+import org.drools.util.ClassUtils;
+import org.drools.util.ConfFileUtils;
 import org.drools.xml.DefaultSemanticModule;
 import org.drools.xml.Handler;
 import org.drools.xml.ProcessSemanticModule;
@@ -266,66 +265,19 @@
     }
 
     public void loadSemanticModule(String moduleLocation) {
-        // initialise default classloader, if it does not exist
-        if ( classLoader == null ) {
-            classLoader = Thread.currentThread().getContextClassLoader();
-            if ( classLoader == null ) {
-                classLoader = this.getClass().getClassLoader();
-            }
-        }
-
-        Properties properties = null;
-
-        // User home 
-        String userHome = System.getProperty( "user.home" );
-        if ( userHome.endsWith( "\\" ) || userHome.endsWith( "/" ) ) {
-            properties = loadProperties( userHome + moduleLocation );
-        } else {
-            properties = loadProperties( userHome + "/" + moduleLocation );
-        }
-
+        URL url = ConfFileUtils.getURL( moduleLocation, this.classLoader , getClass() );        
+        if ( url == null ) {
+            throw new IllegalArgumentException( moduleLocation + " is specified but cannot be found.'" );
+        }        
+        
+        Properties properties = ConfFileUtils.getProperties( url );        
         if ( properties == null ) {
-            // Working directory 
-            properties = loadProperties( moduleLocation );
-        }
-
-        // check META-INF directories for all known ClassLoaders
-
-        if ( properties == null ) {
-            ClassLoader confClassLoader = classLoader;
-            if ( confClassLoader != null ) {
-                properties = loadProperties( confClassLoader.getResource( "META-INF/" + moduleLocation ) );
-            }
-        }
-
-        if ( properties == null ) {
-            ClassLoader confClassLoader = getClass().getClassLoader();
-            if ( confClassLoader != null && confClassLoader != classLoader ) {
-                properties = loadProperties( confClassLoader.getResource( "META-INF/" + moduleLocation ) );
-            }
-        }
-
-        if ( properties == null ) {
-            ClassLoader confClassLoader = Thread.currentThread().getContextClassLoader();
-            if ( confClassLoader != null && confClassLoader != classLoader ) {
-                properties = loadProperties( confClassLoader.getResource( "META-INF/" + moduleLocation ) );
-            }
-        }
-
-        if ( properties == null ) {
-            ClassLoader confClassLoader = ClassLoader.getSystemClassLoader();
-            if ( confClassLoader != null && confClassLoader != classLoader ) {
-                properties = loadProperties( confClassLoader.getResource( "META-INF/" + moduleLocation ) );
-            }
-        }
-
-        if ( properties == null ) {
             throw new IllegalArgumentException( moduleLocation + " is specified but cannot be found.'" );
         }
 
         loadSemanticModule( properties );
     }
-
+    
     public void loadSemanticModule(Properties properties) {
         String uri = properties.getProperty( "uri",
                                              null );
@@ -351,39 +303,9 @@
                 throw new RuntimeException( "Handler name must be specified for Semantic Module" );
             }
 
-            Handler handler = null;
+            Handler handler = ( Handler ) ClassUtils.instantiateObject( handlerName, this.classLoader );
 
-            try {
-                handler = (Handler) this.classLoader.loadClass( handlerName ).newInstance();
-            } catch ( Exception e ) {
-                //swallow
-            }
-
             if ( handler == null ) {
-                try {
-                    handler = (Handler) getClass().getClassLoader().loadClass( handlerName ).newInstance();
-                } catch ( Exception e ) {
-                    //swallow
-                }
-            }
-
-            if ( handler == null ) {
-                try {
-                    handler = (Handler) Thread.currentThread().getContextClassLoader().loadClass( handlerName ).newInstance();
-                } catch ( Exception e ) {
-                    //swallow
-                }
-            }
-
-            if ( handler == null ) {
-                try {
-                    handler = (Handler) ClassLoader.getSystemClassLoader().loadClass( handlerName ).newInstance();
-                } catch ( Exception e ) {
-                    //swallow
-                }
-            }
-
-            if ( handler == null ) {
                 throw new RuntimeException( "Unable to load Semantic Module handler '" + elementName + ":" + handlerName + "'" );
             } else {
                 module.addHandler( elementName,
@@ -393,35 +315,6 @@
         this.semanticModules.addSemanticModule( module );
     }
 
-    private Properties loadProperties(String fileName) {
-        Properties properties = null;
-        if ( fileName != null ) {
-            File file = new File( fileName );
-            if ( file != null && file.exists() ) {
-                try {
-                    properties = loadProperties( file.toURL() );
-                } catch ( MalformedURLException e ) {
-                    throw new IllegalArgumentException( "file.toURL() failed for '" + file + "'" );
-                }
-            } 
-        }
-        return properties;
-    }
-
-    private Properties loadProperties(URL confURL) {
-        if ( confURL == null ) {
-            return null;
-        }
-        
-        Properties properties = new Properties();
-        try {
-            properties.load( confURL.openStream() );
-        } catch ( IOException e ) {
-            throw new IllegalArgumentException( "Invalid URL to properties file '" + confURL.toExternalForm() + "'" );
-        }
-        return properties;
-    }
-
     private void buildAccumulateFunctionsMap() {
         this.accumulateFunctions = new HashMap<String, String>();
         Map temp = new HashMap();

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/processes/StartNodeHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/processes/StartNodeHandler.java	2008-01-02 12:33:57 UTC (rev 17490)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/processes/StartNodeHandler.java	2008-01-02 12:49:25 UTC (rev 17491)
@@ -36,30 +36,31 @@
             this.allowNesting = false;
         }
     }
-    
 
-    
     public Object start(final String uri,
                         final String localName,
                         final Attributes attrs,
                         final ExtensibleXmlParser parser) throws SAXException {
         parser.startConfiguration( localName,
-                                                  attrs );
-        
-        RuleFlowProcessImpl  process = ( RuleFlowProcessImpl ) parser.getParent();
-        
+                                   attrs );
+
+        RuleFlowProcessImpl process = (RuleFlowProcessImpl) parser.getParent();
+
         final StartNode startNode = new StartNodeImpl();
 
-        final String name = attrs.getValue( "name" );        
-        emptyAttributeCheck( localName, "name", name, parser );        
+        final String name = attrs.getValue( "name" );
+        emptyAttributeCheck( localName,
+                             "name",
+                             name,
+                             parser );
         startNode.setName( name );
-        
-        process.addNode( startNode );        
-        ((ProcessBuildData)parser.getData()).addNode( startNode );
-        
+
+        process.addNode( startNode );
+        ((ProcessBuildData) parser.getData()).addNode( startNode );
+
         return startNode;
-    }    
-    
+    }
+
     public Object end(final String uri,
                       final String localName,
                       final ExtensibleXmlParser parser) throws SAXException {
@@ -69,6 +70,6 @@
 
     public Class generateNodeFor() {
         return StartNode.class;
-    }    
+    }
 
 }

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/Cheese.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/Cheese.java	2008-01-02 12:33:57 UTC (rev 17490)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/Cheese.java	2008-01-02 12:49:25 UTC (rev 17491)
@@ -37,6 +37,12 @@
     public Cheese() {
 
     }
+    
+    public Cheese(final String type) {
+        super();
+        this.type = type;
+        this.price = 0;
+    }    
 
     public Cheese(final String type,
                   final int price) {




More information about the jboss-svn-commits mailing list