[seam-commits] Seam SVN: r11930 - modules/drools/trunk/src/main/java/org/jboss/seam/drools.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Thu Jan 7 09:34:04 EST 2010


Author: tsurdilovic
Date: 2010-01-07 09:34:04 -0500 (Thu, 07 Jan 2010)
New Revision: 11930

Modified:
   modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeBaseManager.java
   modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeBaseManagerConfig.java
Log:
Drools 5 integration.

Modified: modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeBaseManager.java
===================================================================
--- modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeBaseManager.java	2010-01-07 13:05:26 UTC (rev 11929)
+++ modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeBaseManager.java	2010-01-07 14:34:04 UTC (rev 11930)
@@ -3,6 +3,7 @@
 import java.io.InputStream;
 import java.io.Reader;
 import java.io.StringReader;
+import java.util.Properties;
 
 import javax.annotation.PostConstruct;
 import javax.enterprise.context.ApplicationScoped;
@@ -14,8 +15,10 @@
 import javax.security.auth.login.Configuration;
 
 import org.drools.KnowledgeBase;
+import org.drools.KnowledgeBaseConfiguration;
 import org.drools.KnowledgeBaseFactory;
 import org.drools.builder.KnowledgeBuilder;
+import org.drools.builder.KnowledgeBuilderConfiguration;
 import org.drools.builder.KnowledgeBuilderError;
 import org.drools.builder.KnowledgeBuilderErrors;
 import org.drools.builder.KnowledgeBuilderFactory;
@@ -36,9 +39,6 @@
 public class KnowledgeBaseManager
 {
    private static final Logger log = LoggerFactory.getLogger(KnowledgeBaseManager.class);
-   private static final String RESOURCE_TYPE_URL = "url";
-   private static final String RESOURCE_TYPE_FILE = "file";
-   private static final String RESOURCE_TYPE_CLASSPATH = "classpath";
    
    private KnowledgeBaseManagerConfig kbaseManagerConfig;
    private KnowledgeBase kbase;
@@ -66,7 +66,7 @@
    @PostConstruct
    private void createKBase() throws Exception
    {
-      KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(kbaseManagerConfig.getKnowledgeBuilderConfiguration());
+      KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(getKnowledgeBuilderConfiguration());
       
       for (String nextResource : kbaseManagerConfig.getRuleResources())
       {
@@ -83,7 +83,7 @@
          manager.fireEvent(new KnowledgeBuilderErrorsEvent(kbuildererrors));
       }
 
-      kbase = KnowledgeBaseFactory.newKnowledgeBase(kbaseManagerConfig.getKnowledgeBaseConfiguration());
+      kbase = KnowledgeBaseFactory.newKnowledgeBase(getKnowledgeBaseConfiguration());
       kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
 
       if (kbaseManagerConfig.getEventListeners() != null)
@@ -113,18 +113,18 @@
    
    protected void addResource(KnowledgeBuilder kbuilder, String resource) throws Exception
    {
-      if(kbaseManagerConfig.isValidResource(resource)) {
-         ResourceType resourceType = ResourceType.getResourceType(kbaseManagerConfig.getResourceType(resource));
-         if(kbaseManagerConfig.isRuleTemplate(resource)) {
+      if(KnowledgeBaseManagerConfig.isValidResource(resource)) {
+         ResourceType resourceType = ResourceType.getResourceType(KnowledgeBaseManagerConfig.getResourceType(resource));
+         if(KnowledgeBaseManagerConfig.isRuleTemplate(resource)) {
             @SuppressWarnings("unchecked")
-            Bean<TemplateDataProvider> templateDataProviderBean = (Bean<TemplateDataProvider>) manager.getBeans(kbaseManagerConfig.getTemplateData(resource)).iterator().next();
+            Bean<TemplateDataProvider> templateDataProviderBean = (Bean<TemplateDataProvider>) manager.getBeans(KnowledgeBaseManagerConfig.getTemplateData(resource)).iterator().next();
 
             TemplateDataProvider templateDataProvider = (TemplateDataProvider) manager.getReference(templateDataProviderBean, Configuration.class, manager.createCreationalContext(templateDataProviderBean));
 
-            InputStream templateStream = this.getClass().getClassLoader().getResourceAsStream(kbaseManagerConfig.getRuleResource(resource));
+            InputStream templateStream = this.getClass().getClassLoader().getResourceAsStream(KnowledgeBaseManagerConfig.getRuleResource(resource));
             if (templateStream == null)
             {
-               throw new IllegalStateException("Could not locate rule resource: " + kbaseManagerConfig.getRuleResource(resource));
+               throw new IllegalStateException("Could not locate rule resource: " + KnowledgeBaseManagerConfig.getRuleResource(resource));
             }
 
             ObjectDataCompiler converter = new ObjectDataCompiler();
@@ -135,28 +135,69 @@
 
             kbuilder.add(ResourceFactory.newReaderResource(rdr), resourceType);
          } else {
-            if (kbaseManagerConfig.getResourcePath(resource).equals(RESOURCE_TYPE_URL))
+            if (KnowledgeBaseManagerConfig.getResourcePath(resource).equals(KnowledgeBaseManagerConfig.RESOURCE_TYPE_URL))
             {
-               kbuilder.add(ResourceFactory.newUrlResource(kbaseManagerConfig.getRuleResource(resource)), resourceType);
-               manager.fireEvent(new RuleResourceAddedEvent(kbaseManagerConfig.getRuleResource(resource)));
+               kbuilder.add(ResourceFactory.newUrlResource(KnowledgeBaseManagerConfig.getRuleResource(resource)), resourceType);
+               manager.fireEvent(new RuleResourceAddedEvent(KnowledgeBaseManagerConfig.getRuleResource(resource)));
             }
-            else if (kbaseManagerConfig.getResourcePath(resource).equals(RESOURCE_TYPE_FILE))
+            else if (KnowledgeBaseManagerConfig.getResourcePath(resource).equals(KnowledgeBaseManagerConfig.RESOURCE_TYPE_FILE))
             {
-               kbuilder.add(ResourceFactory.newFileResource(kbaseManagerConfig.getRuleResource(resource)), resourceType);
-               manager.fireEvent(new RuleResourceAddedEvent(kbaseManagerConfig.getRuleResource(resource)));
+               kbuilder.add(ResourceFactory.newFileResource(KnowledgeBaseManagerConfig.getRuleResource(resource)), resourceType);
+               manager.fireEvent(new RuleResourceAddedEvent(KnowledgeBaseManagerConfig.getRuleResource(resource)));
             }
-            else if (kbaseManagerConfig.getResourcePath(resource).equals(RESOURCE_TYPE_CLASSPATH))
+            else if (KnowledgeBaseManagerConfig.getResourcePath(resource).equals(KnowledgeBaseManagerConfig.RESOURCE_TYPE_CLASSPATH))
             {
-               kbuilder.add(ResourceFactory.newClassPathResource(kbaseManagerConfig.getRuleResource(resource)), resourceType);
-               manager.fireEvent(new RuleResourceAddedEvent(kbaseManagerConfig.getRuleResource(resource)));
+               kbuilder.add(ResourceFactory.newClassPathResource(KnowledgeBaseManagerConfig.getRuleResource(resource)), resourceType);
+               manager.fireEvent(new RuleResourceAddedEvent(KnowledgeBaseManagerConfig.getRuleResource(resource)));
             }
             else
             {
-               log.error("Invalid resource path: " + kbaseManagerConfig.getResourcePath(resource));
+               log.error("Invalid resource path: " + KnowledgeBaseManagerConfig.getResourcePath(resource));
             }
          }
       } else {
          log.error("Invalid resource definition: " + resource);         
       }
    }
+   
+   public KnowledgeBuilderConfiguration getKnowledgeBuilderConfiguration() throws Exception
+   {
+      KnowledgeBuilderConfiguration kbuilderconfig = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
+      // Only allow resource for .properties files
+      if (kbaseManagerConfig.getKnowledgeBuilderConfig() != null && kbaseManagerConfig.getKnowledgeBuilderConfig().endsWith(".properties"))
+      {
+         Properties kbuilderProp = new Properties();
+         InputStream in = this.getClass().getClassLoader().getResourceAsStream(kbaseManagerConfig.getKnowledgeBuilderConfig());
+         if (in == null)
+         {
+            throw new IllegalStateException("Could not locate knowledgeBuilderConfig: " + kbaseManagerConfig.getKnowledgeBuilderConfig());
+         }
+         kbuilderProp.load(in);
+         in.close();
+         kbuilderconfig = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(kbuilderProp, null);
+         log.debug("KnowledgeBuilderConfiguration loaded: " + kbaseManagerConfig.getKnowledgeBuilderConfig());
+      }
+      return kbuilderconfig;
+   }
+
+   public KnowledgeBaseConfiguration getKnowledgeBaseConfiguration() throws Exception
+   {
+      KnowledgeBaseConfiguration kbaseconfig = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
+
+      // Only allow resource for .properties files
+      if (kbaseManagerConfig.getKnowledgeBaseConfig() != null && kbaseManagerConfig.getKnowledgeBaseConfig().endsWith(".properties"))
+      {
+         Properties kbaseProp = new Properties();
+         InputStream in = this.getClass().getClassLoader().getResourceAsStream(kbaseManagerConfig.getKnowledgeBaseConfig());
+         if (in == null)
+         {
+            throw new IllegalStateException("Could not locate knowledgeBaseConfig: " + kbaseManagerConfig.getKnowledgeBaseConfig());
+         }
+         kbaseProp.load(in);
+         in.close();
+         kbaseconfig = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(kbaseProp, null);
+         log.debug("KnowledgeBaseConfiguration loaded: " + kbaseManagerConfig.getKnowledgeBaseConfig());
+      }
+      return kbaseconfig;
+   }
 }
\ No newline at end of file

Modified: modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeBaseManagerConfig.java
===================================================================
--- modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeBaseManagerConfig.java	2010-01-07 13:05:26 UTC (rev 11929)
+++ modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeBaseManagerConfig.java	2010-01-07 14:34:04 UTC (rev 11930)
@@ -25,74 +25,37 @@
    private static final int RESOURCE = 1;
    private static final int RESOURCE_TYPE = 2;
    private static final int RESOURCE_TEMPLATE_DATA = 3;
+   
+   public static final String RESOURCE_TYPE_URL = "url";
+   public static final String RESOURCE_TYPE_FILE = "file";
+   public static final String RESOURCE_TYPE_CLASSPATH = "classpath";
 
    private String knowledgeBuilderConfig;
    private String knowledgeBaseConfig;
    private String[] ruleResources;
    private String[] eventListeners;
-
-   public KnowledgeBuilderConfiguration getKnowledgeBuilderConfiguration() throws Exception
-   {
-      KnowledgeBuilderConfiguration kbuilderconfig = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
-      // Only allow resource for .properties files
-      if (knowledgeBuilderConfig != null && knowledgeBuilderConfig.endsWith(".properties"))
-      {
-         Properties kbuilderProp = new Properties();
-         InputStream in = this.getClass().getClassLoader().getResourceAsStream(knowledgeBuilderConfig);
-         if (in == null)
-         {
-            throw new IllegalStateException("Could not locate knowledgeBuilderConfig: " + knowledgeBuilderConfig);
-         }
-         kbuilderProp.load(in);
-         in.close();
-         kbuilderconfig = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(kbuilderProp, null);
-         log.debug("KnowledgeBuilderConfiguration loaded: " + knowledgeBuilderConfig);
-      }
-      return kbuilderconfig;
-   }
-
-   public KnowledgeBaseConfiguration getKnowledgeBaseConfiguration() throws Exception
-   {
-      KnowledgeBaseConfiguration kbaseconfig = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
-
-      // Only allow resource for .properties files
-      if (knowledgeBaseConfig != null && knowledgeBaseConfig.endsWith(".properties"))
-      {
-         Properties kbaseProp = new Properties();
-         InputStream in = this.getClass().getClassLoader().getResourceAsStream(knowledgeBaseConfig);
-         if (in == null)
-         {
-            throw new IllegalStateException("Could not locate knowledgeBaseConfig: " + knowledgeBaseConfig);
-         }
-         kbaseProp.load(in);
-         in.close();
-         kbaseconfig = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(kbaseProp, null);
-         log.debug("KnowledgeBaseConfiguration loaded: " + knowledgeBaseConfig);
-      }
-      return kbaseconfig;
-   }
    
-   public boolean isValidResource(String resource) {
+   public static boolean isValidResource(String resource) {
       return DIVIDER.split(resource.trim()).length >= 3;
    }
    
-   public boolean isRuleTemplate(String resource) {
+   public static boolean isRuleTemplate(String resource) {
       return DIVIDER.split(resource.trim()).length == 4;
    }
    
-   public String getResourceType(String resource) {
+   public static String getResourceType(String resource) {
       return DIVIDER.split(resource.trim())[RESOURCE_TYPE];
    }
    
-   public String getRuleResource(String resource) {
+   public static String getRuleResource(String resource) {
       return DIVIDER.split(resource.trim())[RESOURCE];
    }
    
-   public String getTemplateData(String resource) {
+   public static String getTemplateData(String resource) {
       return DIVIDER.split(resource.trim())[RESOURCE_TEMPLATE_DATA];
    }
    
-   public String getResourcePath(String resource) {
+   public static String getResourcePath(String resource) {
       return DIVIDER.split(resource.trim())[RESOURCE_PATH];
    }
 



More information about the seam-commits mailing list