[seam-commits] Seam SVN: r12347 - in modules/drools/trunk: core/src/main/java/org/jboss/seam/drools and 8 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Thu Apr 1 01:25:54 EDT 2010
Author: tsurdilovic
Date: 2010-04-01 01:25:52 -0400 (Thu, 01 Apr 2010)
New Revision: 12347
Added:
modules/drools/trunk/.settings/
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeBaseProducer.java
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/config/
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/config/KnowledgeBaseConfig.java
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/old/
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/old/FactProvider.java
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/old/KnowledgeBaseManager.java
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/old/KnowledgeBaseManagerConfig.java
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/old/KnowledgeSessionManager.java
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/old/KnowledgeSessionManagerConfig.java
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/old/TemplateDataProvider.java
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/KBase.java
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/KBaseConfig.java
modules/drools/trunk/core/src/test/java/org/jboss/seam/drools/kbase/
modules/drools/trunk/core/src/test/java/org/jboss/seam/drools/kbase/KBaseTest.java
modules/drools/trunk/core/src/test/resources/org/jboss/seam/drools/kbase/
modules/drools/trunk/core/src/test/resources/org/jboss/seam/drools/kbase/KBaseTest-beans.xml
modules/drools/trunk/core/src/test/resources/org/jboss/seam/drools/kbase/kbaseconfig.properties
modules/drools/trunk/core/src/test/resources/org/jboss/seam/drools/kbase/kbasetest.drl
modules/drools/trunk/core/src/test/resources/org/jboss/seam/drools/kbase/kbuilderconfig.properties
Removed:
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/FactProvider.java
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeBaseManager.java
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeBaseManagerConfig.java
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeSessionManager.java
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeSessionManagerConfig.java
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/TemplateDataProvider.java
Modified:
modules/drools/trunk/docs/drools-reference.pdf
Log:
added kbase test
Deleted: modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/FactProvider.java
===================================================================
--- modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/FactProvider.java 2010-03-31 23:14:14 UTC (rev 12346)
+++ modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/FactProvider.java 2010-04-01 05:25:52 UTC (rev 12347)
@@ -1,20 +0,0 @@
-package org.jboss.seam.drools;
-
-import java.util.List;
-import java.util.Map;
-
-/**
- * Interface for fact providers.
- *
- * @author Tihomir Surdilovic
- *
- */
-public interface FactProvider
-{
- public List<Object> getFacts();
- public void setFacts(List<Object> facts);
-
- public Map<String, Object> getGlobals();
- public void setGlobals(Map<String, Object> globals);
-
-}
\ No newline at end of file
Deleted: modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeBaseManager.java
===================================================================
--- modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeBaseManager.java 2010-03-31 23:14:14 UTC (rev 12346)
+++ modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeBaseManager.java 2010-04-01 05:25:52 UTC (rev 12347)
@@ -1,207 +0,0 @@
-package org.jboss.seam.drools;
-
-import java.io.InputStream;
-import java.io.Reader;
-import java.io.StringReader;
-import java.util.Properties;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.inject.Disposes;
-import javax.enterprise.inject.Produces;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.inject.Inject;
-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;
-import org.drools.builder.ResourceType;
-import org.drools.event.knowledgebase.KnowledgeBaseEventListener;
-import org.drools.io.ResourceFactory;
-import org.drools.template.ObjectDataCompiler;
-import org.jboss.seam.drools.events.KnowledgeBuilderErrorsEvent;
-import org.jboss.seam.drools.events.RuleResourceAddedEvent;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Manager component for a Drools KnowledgeBase.
- *
- * @author Tihomir Surdilovic
- */
-public class KnowledgeBaseManager
-{
- private static final Logger log = LoggerFactory.getLogger(KnowledgeBaseManager.class);
-
- private KnowledgeBaseManagerConfig kbaseManagerConfig;
-
- @Inject
- BeanManager manager;
-
- @Inject
- public KnowledgeBaseManager(KnowledgeBaseManagerConfig kbaseManagerConfig) {
- this.kbaseManagerConfig = kbaseManagerConfig;
- }
-
- @Produces
- @ApplicationScoped
- public KnowledgeBase createKBase() throws Exception
- {
- KnowledgeBase kbase;
- KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(getKnowledgeBuilderConfiguration());
-
- for (String nextResource : kbaseManagerConfig.getRuleResources())
- {
- addResource(kbuilder, nextResource);
- }
-
- KnowledgeBuilderErrors kbuildererrors = kbuilder.getErrors();
- if (kbuildererrors.size() > 0)
- {
- for (KnowledgeBuilderError kbuildererror : kbuildererrors)
- {
- log.error(kbuildererror.getMessage());
- }
- manager.fireEvent(new KnowledgeBuilderErrorsEvent(kbuildererrors));
- }
-
- kbase = KnowledgeBaseFactory.newKnowledgeBase(getKnowledgeBaseConfiguration());
- kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
-
- if (kbaseManagerConfig.getEventListeners() != null)
- {
- for (String eventListener : kbaseManagerConfig.getEventListeners())
- {
- addEventListener(kbase, eventListener);
- }
- }
- return kbase;
- }
-
- public void disposeKBase(@Disposes KnowledgeBase kbase)
- {
- kbase = null;
- }
-
- private void addEventListener(org.drools.KnowledgeBase kbase, String eventListener) {
- try {
- @SuppressWarnings("unchecked")
- Class eventListenerClass = Class.forName(eventListener);
- Object eventListenerObject = eventListenerClass.newInstance();
-
- if(eventListenerObject instanceof KnowledgeBaseEventListener) {
- kbase.addEventListener((KnowledgeBaseEventListener) eventListenerObject);
- } else {
- log.debug("Event Listener " + eventListener + " is not of type KnowledgeBaseEventListener");
- }
- } catch(Exception e) {
- log.error("Error adding event listener " + e.getMessage());
- }
- }
-
- protected void addResource(KnowledgeBuilder kbuilder, String resource) throws Exception
- {
- if(KnowledgeBaseManagerConfig.isValidResource(resource)) {
- ResourceType resourceType = ResourceType.getResourceType(KnowledgeBaseManagerConfig.getResourceType(resource));
- if(KnowledgeBaseManagerConfig.isRuleTemplate(resource)) {
- @SuppressWarnings("unchecked")
- 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(KnowledgeBaseManagerConfig.getRuleResource(resource));
- if (templateStream == null)
- {
- throw new IllegalStateException("Could not locate rule resource: " + KnowledgeBaseManagerConfig.getRuleResource(resource));
- }
-
- ObjectDataCompiler converter = new ObjectDataCompiler();
- String drl = converter.compile(templateDataProvider.getTemplateData(), templateStream);
- templateStream.close();
- log.debug("Generated following DRL from template: " + drl);
- Reader rdr = new StringReader(drl);
-
- kbuilder.add(ResourceFactory.newReaderResource(rdr), resourceType);
- } else {
- if (KnowledgeBaseManagerConfig.getResourcePath(resource).equals(KnowledgeBaseManagerConfig.RESOURCE_TYPE_URL))
- {
- kbuilder.add(ResourceFactory.newUrlResource(KnowledgeBaseManagerConfig.getRuleResource(resource)), resourceType);
- manager.fireEvent(new RuleResourceAddedEvent(KnowledgeBaseManagerConfig.getRuleResource(resource)));
- }
- else if (KnowledgeBaseManagerConfig.getResourcePath(resource).equals(KnowledgeBaseManagerConfig.RESOURCE_TYPE_FILE))
- {
- kbuilder.add(ResourceFactory.newFileResource(KnowledgeBaseManagerConfig.getRuleResource(resource)), resourceType);
- manager.fireEvent(new RuleResourceAddedEvent(KnowledgeBaseManagerConfig.getRuleResource(resource)));
- }
- else if (KnowledgeBaseManagerConfig.getResourcePath(resource).equals(KnowledgeBaseManagerConfig.RESOURCE_TYPE_CLASSPATH))
- {
- kbuilder.add(ResourceFactory.newClassPathResource(KnowledgeBaseManagerConfig.getRuleResource(resource)), resourceType);
- manager.fireEvent(new RuleResourceAddedEvent(KnowledgeBaseManagerConfig.getRuleResource(resource)));
- }
- else
- {
- log.error("Invalid resource path: " + KnowledgeBaseManagerConfig.getResourcePath(resource));
- }
- }
- } else {
- log.error("Invalid resource definition: " + resource);
- }
- }
-
- public KnowledgeBuilderConfiguration getKnowledgeBuilderConfiguration() throws Exception
- {
- KnowledgeBuilderConfiguration kbuilderconfig = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
- if(kbaseManagerConfig.getKnowledgeBuilderConfigProp() != null) {
- kbuilderconfig = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(kbaseManagerConfig.getKnowledgeBuilderConfigProp(), null);
- log.debug("KnowledgeBuilderConfiguration loaded: " + kbaseManagerConfig.getKnowledgeBuilderConfigProp());
- } else {
- // 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();
-
- if(kbaseManagerConfig.getKnowledgeBaseConfigProp() != null) {
- kbaseconfig = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(kbaseManagerConfig.getKnowledgeBaseConfigProp(), null);
- log.debug("KnowledgeBaseConfiguration loaded: " + kbaseManagerConfig.getKnowledgeBaseConfigProp());
- } else {
- // 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
Deleted: modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeBaseManagerConfig.java
===================================================================
--- modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeBaseManagerConfig.java 2010-03-31 23:14:14 UTC (rev 12346)
+++ modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeBaseManagerConfig.java 2010-04-01 05:25:52 UTC (rev 12347)
@@ -1,116 +0,0 @@
-package org.jboss.seam.drools;
-
-import java.util.Properties;
-import java.util.regex.Pattern;
-
-/**
- * KnowledgeBaseManager Configuration.
- *
- * @author Tihomir Surdilovic
- */
-public class KnowledgeBaseManagerConfig
-{
- private static final Pattern DIVIDER = Pattern.compile(";");
- private static final int RESOURCE_PATH = 0;
- 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 Properties knowledgeBuilderConfigProp;
- private Properties knowledgeBaseConfigProp;
- private String[] ruleResources;
- private String[] eventListeners;
-
- public static boolean isValidResource(String resource) {
- return DIVIDER.split(resource.trim()).length >= 3;
- }
-
- public static boolean isRuleTemplate(String resource) {
- return DIVIDER.split(resource.trim()).length == 4;
- }
-
- public static String getResourceType(String resource) {
- return DIVIDER.split(resource.trim())[RESOURCE_TYPE];
- }
-
- public static String getRuleResource(String resource) {
- return DIVIDER.split(resource.trim())[RESOURCE];
- }
-
- public static String getTemplateData(String resource) {
- return DIVIDER.split(resource.trim())[RESOURCE_TEMPLATE_DATA];
- }
-
- public static String getResourcePath(String resource) {
- return DIVIDER.split(resource.trim())[RESOURCE_PATH];
- }
-
- public String getKnowledgeBuilderConfig()
- {
- return knowledgeBuilderConfig;
- }
-
- public void setKnowledgeBuilderConfig(String knowledgeBuilderConfig)
- {
- this.knowledgeBuilderConfig = knowledgeBuilderConfig;
- }
-
- public String getKnowledgeBaseConfig()
- {
- return knowledgeBaseConfig;
- }
-
- public void setKnowledgeBaseConfig(String knowledgeBaseConfig)
- {
- this.knowledgeBaseConfig = knowledgeBaseConfig;
- }
-
- public String[] getRuleResources()
- {
- return ruleResources;
- }
-
- public void setRuleResources(String[] ruleResources)
- {
- this.ruleResources = ruleResources;
- }
-
- public String[] getEventListeners()
- {
- return eventListeners;
- }
-
- public void setEventListeners(String[] eventListeners)
- {
- this.eventListeners = eventListeners;
- }
-
- public Properties getKnowledgeBuilderConfigProp()
- {
- return knowledgeBuilderConfigProp;
- }
-
- public void setKnowledgeBuilderConfigProp(Properties knowledgeBuilderConfigProp)
- {
- this.knowledgeBuilderConfigProp = knowledgeBuilderConfigProp;
- }
-
- public Properties getKnowledgeBaseConfigProp()
- {
- return knowledgeBaseConfigProp;
- }
-
- public void setKnowledgeBaseConfigProp(Properties knowledgeBaseConfigProp)
- {
- this.knowledgeBaseConfigProp = knowledgeBaseConfigProp;
- }
-
-
-
-}
Added: modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeBaseProducer.java
===================================================================
--- modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeBaseProducer.java (rev 0)
+++ modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeBaseProducer.java 2010-04-01 05:25:52 UTC (rev 12347)
@@ -0,0 +1,152 @@
+package org.jboss.seam.drools;
+
+import java.io.InputStream;
+import java.util.Properties;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+
+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;
+import org.drools.builder.ResourceType;
+import org.drools.event.knowledgebase.KnowledgeBaseEventListener;
+import org.drools.io.ResourceFactory;
+import org.jboss.seam.drools.config.KnowledgeBaseConfig;
+import org.jboss.seam.drools.events.KnowledgeBuilderErrorsEvent;
+import org.jboss.seam.drools.events.RuleResourceAddedEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author Tihomir Surdilovic
+ */
+public class KnowledgeBaseProducer
+{
+ private static final Logger log = LoggerFactory.getLogger(KnowledgeBaseProducer.class);
+ @Inject BeanManager manager;
+
+ @Produces
+ public KnowledgeBase produceKBase(KnowledgeBaseConfig kbaseConfig) throws Exception
+ {
+ KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(getKnowledgeBuilderConfiguration(kbaseConfig));
+
+ for (String nextResource : kbaseConfig.getRuleResources())
+ {
+ addResource(kbuilder, nextResource);
+ }
+
+ KnowledgeBuilderErrors kbuildererrors = kbuilder.getErrors();
+ if (kbuildererrors.size() > 0)
+ {
+ for (KnowledgeBuilderError kbuildererror : kbuildererrors)
+ {
+ log.error(kbuildererror.getMessage());
+ }
+ manager.fireEvent(new KnowledgeBuilderErrorsEvent(kbuildererrors));
+ }
+
+ KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(getKnowledgeBaseConfiguration(kbaseConfig));
+ kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
+
+ if (kbaseConfig.getEventListeners() != null)
+ {
+ for (String eventListener : kbaseConfig.getEventListeners())
+ {
+ addEventListener(kbase, eventListener);
+ }
+ }
+ return kbase;
+ }
+
+ private KnowledgeBuilderConfiguration getKnowledgeBuilderConfiguration(KnowledgeBaseConfig kbaseConfig) throws Exception
+ {
+ KnowledgeBuilderConfiguration droolsKbuilderConfig = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
+ if (kbaseConfig.getKnowledgeBuilderConfig() != null && kbaseConfig.getKnowledgeBuilderConfig().endsWith(".properties"))
+ {
+ Properties kbuilderProp = new Properties();
+ InputStream in = this.getClass().getClassLoader().getResourceAsStream(kbaseConfig.getKnowledgeBuilderConfig());
+ if (in == null)
+ {
+ throw new IllegalStateException("Could not locate knowledgeBuilderConfig: " + kbaseConfig.getKnowledgeBuilderConfig());
+ }
+ kbuilderProp.load(in);
+ in.close();
+ droolsKbuilderConfig = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(kbuilderProp, null);
+ log.debug("KnowledgeBuilderConfiguration loaded: " + kbaseConfig.getKnowledgeBuilderConfig());
+ }
+ return droolsKbuilderConfig;
+ }
+
+ public KnowledgeBaseConfiguration getKnowledgeBaseConfiguration(KnowledgeBaseConfig kbaseConfig) throws Exception
+ {
+ KnowledgeBaseConfiguration droolsKbaseConfig = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
+ if (kbaseConfig.getKnowledgeBaseConfig() != null && kbaseConfig.getKnowledgeBaseConfig().endsWith(".properties"))
+ {
+ Properties kbaseProp = new Properties();
+ InputStream in = this.getClass().getClassLoader().getResourceAsStream(kbaseConfig.getKnowledgeBaseConfig());
+ if (in == null)
+ {
+ throw new IllegalStateException("Could not locate knowledgeBaseConfig: " + kbaseConfig.getKnowledgeBaseConfig());
+ }
+ kbaseProp.load(in);
+ in.close();
+ droolsKbaseConfig = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(kbaseProp, null);
+ log.debug("KnowledgeBaseConfiguration loaded: " + kbaseConfig.getKnowledgeBaseConfig());
+ }
+ return droolsKbaseConfig;
+ }
+
+ private void addResource(KnowledgeBuilder kbuilder, String resource) throws Exception
+ {
+ //TODO add support for drools templates definition!
+ ResourceType resourceType = ResourceType.getResourceType(KnowledgeBaseConfig.getResourceType(resource));
+ if(KnowledgeBaseConfig.isValidResource(resource)) {
+ if (KnowledgeBaseConfig.getResourcePath(resource).equals(KnowledgeBaseConfig.RESOURCE_TYPE_URL))
+ {
+ kbuilder.add(ResourceFactory.newUrlResource(KnowledgeBaseConfig.getRuleResource(resource)), resourceType);
+ manager.fireEvent(new RuleResourceAddedEvent(KnowledgeBaseConfig.getRuleResource(resource)));
+ }
+ else if (KnowledgeBaseConfig.getResourcePath(resource).equals(KnowledgeBaseConfig.RESOURCE_TYPE_FILE))
+ {
+ kbuilder.add(ResourceFactory.newFileResource(KnowledgeBaseConfig.getRuleResource(resource)), resourceType);
+ manager.fireEvent(new RuleResourceAddedEvent(KnowledgeBaseConfig.getRuleResource(resource)));
+ }
+ else if (KnowledgeBaseConfig.getResourcePath(resource).equals(KnowledgeBaseConfig.RESOURCE_TYPE_CLASSPATH))
+ {
+ kbuilder.add(ResourceFactory.newClassPathResource(KnowledgeBaseConfig.getRuleResource(resource)), resourceType);
+ manager.fireEvent(new RuleResourceAddedEvent(KnowledgeBaseConfig.getRuleResource(resource)));
+ }
+ else
+ {
+ log.error("Invalid resource path: " + KnowledgeBaseConfig.getResourcePath(resource));
+ }
+ } else {
+ log.error("Invalid resource definition: " + resource);
+ }
+ }
+
+ private void addEventListener(org.drools.KnowledgeBase kbase, String eventListener) {
+ try {
+ @SuppressWarnings("unchecked")
+ Class eventListenerClass = Class.forName(eventListener);
+ Object eventListenerObject = eventListenerClass.newInstance();
+
+ if(eventListenerObject instanceof KnowledgeBaseEventListener) {
+ kbase.addEventListener((KnowledgeBaseEventListener) eventListenerObject);
+ } else {
+ log.debug("Event Listener " + eventListener + " is not of type KnowledgeBaseEventListener");
+ }
+ } catch(Exception e) {
+ log.error("Error adding event listener " + e.getMessage());
+ }
+ }
+}
Deleted: modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeSessionManager.java
===================================================================
--- modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeSessionManager.java 2010-03-31 23:14:14 UTC (rev 12346)
+++ modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeSessionManager.java 2010-04-01 05:25:52 UTC (rev 12347)
@@ -1,186 +0,0 @@
-package org.jboss.seam.drools;
-
-import java.io.InputStream;
-import java.util.Hashtable;
-import java.util.Map;
-import java.util.Properties;
-
-import java.lang.annotation.Annotation;
-import javax.enterprise.inject.Any;
-import javax.enterprise.inject.Disposes;
-import javax.enterprise.inject.Instance;
-import javax.enterprise.inject.Produces;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.enterprise.inject.spi.InjectionPoint;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.security.auth.login.Configuration;
-
-import org.drools.KnowledgeBase;
-import org.drools.KnowledgeBaseFactory;
-import org.drools.event.process.ProcessEventListener;
-import org.drools.event.rule.AgendaEventListener;
-import org.drools.event.rule.WorkingMemoryEventListener;
-import org.drools.logger.KnowledgeRuntimeLogger;
-import org.drools.logger.KnowledgeRuntimeLoggerFactory;
-import org.drools.runtime.KnowledgeSessionConfiguration;
-import org.drools.runtime.StatefulKnowledgeSession;
-import org.drools.runtime.StatelessKnowledgeSession;
-import org.drools.runtime.process.WorkItemHandler;
-import org.jboss.seam.drools.events.KnowledgeSessionCreatedEvent;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Manager component for a Drools Knowledge Sessions.
- *
- * @author Tihomir Surdilovic
- */
-public class KnowledgeSessionManager
-{
- private static final Logger log = LoggerFactory.getLogger(KnowledgeSessionManager.class);
-
- private KnowledgeSessionManagerConfig ksessionManagerConfig;
- private Map<Integer, KnowledgeRuntimeLogger> statefulKnowledgeLoggers = new Hashtable<Integer, KnowledgeRuntimeLogger>();
-
- @Inject
- BeanManager manager;
-
- @Inject
- public KnowledgeSessionManager(KnowledgeSessionManagerConfig ksessionManagerConfig)
- {
- this.ksessionManagerConfig = ksessionManagerConfig;
- }
-
- @Produces
- @Any
- public StatefulKnowledgeSession getStatefulSession(InjectionPoint ip, Instance<KnowledgeBase> kbase) throws Exception
- {
- StatefulKnowledgeSession ksession = kbase.select(ip.getQualifiers().toArray(new Annotation[0])).get().newStatefulKnowledgeSession(getKSessionConfig(), null);
- addEventListeners(ksession);
- addWorkItemHandlers(ksession);
- addAuditLog(ksession);
- manager.fireEvent(new KnowledgeSessionCreatedEvent(ksession.getId()));
- return ksession;
- }
-
- public void disposeStatefulSession(@Disposes StatefulKnowledgeSession statefulSession)
- {
- if (statefulKnowledgeLoggers.get(statefulSession.getId()) != null)
- {
- statefulKnowledgeLoggers.get(statefulSession.getId()).close();
- }
- statefulSession.dispose();
- }
-
- @Produces
- @Any
- public StatelessKnowledgeSession getStatelessSession(InjectionPoint ip, Instance<KnowledgeBase> kbase) throws Exception
- {
- StatelessKnowledgeSession ksession = kbase.select(ip.getQualifiers().toArray(new Annotation[0])).get().newStatelessKnowledgeSession(getKSessionConfig());
- addEventListeners(ksession);
- manager.fireEvent(new KnowledgeSessionCreatedEvent(-1));
- return ksession;
- }
-
- private KnowledgeSessionConfiguration getKSessionConfig() throws Exception
- {
- KnowledgeSessionConfiguration ksessionConfig = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
- if(ksessionManagerConfig.getKnowledgeSessionConfigProp() != null) {
- ksessionConfig = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(ksessionManagerConfig.getKnowledgeSessionConfigProp());
- } else {
- // Only allow resource for .properties files
- if (ksessionManagerConfig.getKnowledgeSessionConfig() != null && ksessionManagerConfig.getKnowledgeSessionConfig().endsWith(".properties"))
- {
- Properties ksessionProp = new Properties();
- InputStream in = this.getClass().getClassLoader().getResourceAsStream(ksessionManagerConfig.getKnowledgeSessionConfig());
- if (in == null)
- {
- throw new IllegalStateException("Could not locate knowledgeSessionrConfig: " + ksessionManagerConfig.getKnowledgeSessionConfig());
- }
- ksessionProp.load(in);
- in.close();
- ksessionConfig = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(ksessionProp);
- log.debug("KnowledgeSessionConfiguration loaded: " + ksessionManagerConfig.getKnowledgeSessionConfig());
- }
- }
- return ksessionConfig;
- }
-
-
- private void addAuditLog(StatefulKnowledgeSession ksession) throws Exception {
- if(ksessionManagerConfig.getAuditLog() != null) {
- if(KnowledgeSessionManagerConfig.isFileLogger(ksessionManagerConfig.getAuditLog())) {
- String logName = KnowledgeSessionManagerConfig.getFileLoggerPath(ksessionManagerConfig.getAuditLog()) + System.currentTimeMillis();
- KnowledgeRuntimeLogger krLogger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, logName);
- statefulKnowledgeLoggers.put(ksession.getId(), krLogger);
- } else if(KnowledgeSessionManagerConfig.isConsoleLogger(ksessionManagerConfig.getAuditLog())) {
- KnowledgeRuntimeLogger krLogger = KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);
- statefulKnowledgeLoggers.put(ksession.getId(), krLogger);
- } else if(KnowledgeSessionManagerConfig.isThreadedLogger(ksessionManagerConfig.getAuditLog())) {
- String logName = KnowledgeSessionManagerConfig.getThreadedLoggerPath(ksessionManagerConfig.getAuditLog()) + System.currentTimeMillis();
- int interval = KnowledgeSessionManagerConfig.getThreadedLoggerInterval(ksessionManagerConfig.getAuditLog());
- KnowledgeRuntimeLogger krLogger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, logName, interval);
- statefulKnowledgeLoggers.put(ksession.getId(), krLogger);
- } else {
- log.warn("Invalid logger specified: " + ksessionManagerConfig.getAuditLog());
- }
- }
- }
-
- public void addEventListeners(StatefulKnowledgeSession ksession) throws Exception {
- if(ksessionManagerConfig.getEventListeners() != null) {
- for(String eventListener : ksessionManagerConfig.getEventListeners()) {
- Class eventListenerClass = Class.forName(eventListener);
- Object eventListenerObject = eventListenerClass.newInstance();
-
- if(eventListenerObject instanceof WorkingMemoryEventListener) {
- ksession.addEventListener((WorkingMemoryEventListener) eventListenerObject);
- } else if(eventListenerObject instanceof AgendaEventListener) {
- ksession.addEventListener((AgendaEventListener) eventListenerObject);
- } else if(eventListenerObject instanceof ProcessEventListener) {
- ksession.addEventListener((ProcessEventListener) eventListenerObject);
- } else {
- log.debug("Invalid Event Listener: " + eventListener);
- }
- }
- }
- }
-
- public void addEventListeners(StatelessKnowledgeSession ksession) throws Exception{
- if(ksessionManagerConfig.getEventListeners() != null) {
- for(String eventListener : ksessionManagerConfig.getEventListeners()) {
- @SuppressWarnings("unchecked")
- Class eventListenerClass = Class.forName(eventListener);
- Object eventListenerObject = eventListenerClass.newInstance();
-
- if(eventListenerObject instanceof WorkingMemoryEventListener) {
- ksession.addEventListener((WorkingMemoryEventListener) eventListenerObject);
- } else if(eventListenerObject instanceof AgendaEventListener) {
- ksession.addEventListener((AgendaEventListener) eventListenerObject);
- } else if(eventListenerObject instanceof ProcessEventListener) {
- ksession.addEventListener((ProcessEventListener) eventListenerObject);
- } else {
- log.debug("Invalid Event Listener: " + eventListener);
- }
- }
- }
- }
-
- public void addWorkItemHandlers(StatefulKnowledgeSession ksession) {
- if(ksessionManagerConfig.getWorkItemHandlers() != null) {
- for(String workItemHandlerStr : ksessionManagerConfig.getWorkItemHandlers()) {
- if(KnowledgeSessionManagerConfig.isValidWorkItemHandler(workItemHandlerStr)) {
- @SuppressWarnings("unchecked")
- Bean<WorkItemHandler> workItemHandlerBean = (Bean<WorkItemHandler>) manager.getBeans(KnowledgeSessionManagerConfig.getWorkItemHandlerType(workItemHandlerStr)).iterator().next();
- WorkItemHandler handler = (WorkItemHandler) manager.getReference(workItemHandlerBean, Configuration.class, manager.createCreationalContext(workItemHandlerBean));
- log.debug("Registering new WorkItemHandler: " + KnowledgeSessionManagerConfig.getWorkItemHandlerName(workItemHandlerStr));
- ksession.getWorkItemManager().registerWorkItemHandler(KnowledgeSessionManagerConfig.getWorkItemHandlerName(workItemHandlerStr), handler);
- }
- }
- }
- }
-
-
-}
Deleted: modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeSessionManagerConfig.java
===================================================================
--- modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeSessionManagerConfig.java 2010-03-31 23:14:14 UTC (rev 12346)
+++ modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeSessionManagerConfig.java 2010-04-01 05:25:52 UTC (rev 12347)
@@ -1,106 +0,0 @@
-package org.jboss.seam.drools;
-
-import java.util.Properties;
-import java.util.regex.Pattern;
-
-/**
- * KnowledgeSessionManager Configuration.
- *
- * @author Tihomir Surdilovic
- */
-public class KnowledgeSessionManagerConfig
-{
- private static final Pattern DIVIDER = Pattern.compile(";");
- private static final int WORKITEMHANDLER_NAME = 0;
- private static final int WORKITEMHANDLER_TYPE = 1;
- private static final int AUDIT_LOG_TYPE = 0;
- private static final int AUDIT_LOG_INFO = 1;
- private static final int AUDIT_LOG_INTERVAL = 2;
- private static final String AUDIT_LOG_TYPE_FILE = "file";
- private static final String AUDIT_LOG_TYPE_CONSOLE = "console";
- private static final String AUDIT_LOG_TYPE_THREADED = "threaded";
-
- private String[] eventListeners;
- private String[] workItemHandlers;
- private String knowledgeSessionConfig;
- private Properties knowledgeSessionConfigProp;
- private String auditLog;
-
- public static String getWorkItemHandlerName(String workItemHandlerStr) {
- return DIVIDER.split(workItemHandlerStr.trim())[WORKITEMHANDLER_NAME];
- }
-
- public static String getWorkItemHandlerType(String workItemHandlerStr) {
- return DIVIDER.split(workItemHandlerStr.trim())[WORKITEMHANDLER_TYPE];
- }
-
- public static boolean isValidWorkItemHandler(String workItemHandlerStr) {
- return DIVIDER.split(workItemHandlerStr.trim()).length == 2;
- }
-
- public static boolean isFileLogger(String auditLog) {
- return DIVIDER.split(auditLog.trim())[AUDIT_LOG_TYPE] == AUDIT_LOG_TYPE_FILE;
- }
-
- public static boolean isConsoleLogger(String auditLog) {
- return DIVIDER.split(auditLog.trim())[AUDIT_LOG_TYPE] == AUDIT_LOG_TYPE_CONSOLE;
- }
-
- public static boolean isThreadedLogger(String auditLog) {
- return DIVIDER.split(auditLog.trim())[AUDIT_LOG_TYPE] == AUDIT_LOG_TYPE_THREADED;
- }
-
- public static String getFileLoggerPath(String auditLog) {
- return DIVIDER.split(auditLog.trim())[AUDIT_LOG_INFO];
- }
-
- public static String getThreadedLoggerPath(String auditLog) {
- return DIVIDER.split(auditLog.trim())[AUDIT_LOG_INFO];
- }
-
- public static int getThreadedLoggerInterval(String auditLog) {
- return Integer.parseInt(DIVIDER.split(auditLog.trim())[AUDIT_LOG_INTERVAL]);
- }
-
- public String[] getEventListeners()
- {
- return eventListeners;
- }
- public void setEventListeners(String[] eventListeners)
- {
- this.eventListeners = eventListeners;
- }
- public String[] getWorkItemHandlers()
- {
- return workItemHandlers;
- }
- public void setWorkItemHandlers(String[] workItemHandlers)
- {
- this.workItemHandlers = workItemHandlers;
- }
- public String getKnowledgeSessionConfig()
- {
- return knowledgeSessionConfig;
- }
- public void setKnowledgeSessionConfig(String knowledgeSessionConfig)
- {
- this.knowledgeSessionConfig = knowledgeSessionConfig;
- }
- public String getAuditLog()
- {
- return auditLog;
- }
- public void setAuditLog(String auditLog)
- {
- this.auditLog = auditLog;
- }
- public Properties getKnowledgeSessionConfigProp()
- {
- return knowledgeSessionConfigProp;
- }
- public void setKnowledgeSessionConfigProp(Properties knowledgeSessionConfigProp)
- {
- this.knowledgeSessionConfigProp = knowledgeSessionConfigProp;
- }
-
-}
Deleted: modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/TemplateDataProvider.java
===================================================================
--- modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/TemplateDataProvider.java 2010-03-31 23:14:14 UTC (rev 12346)
+++ modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/TemplateDataProvider.java 2010-04-01 05:25:52 UTC (rev 12347)
@@ -1,14 +0,0 @@
-package org.jboss.seam.drools;
-
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * Interface for template data providers.
- *
- * @author Tihomir Surdilovic
- */
-public interface TemplateDataProvider
-{
- public Collection<Map<String, Object>> getTemplateData();
-}
Added: modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/config/KnowledgeBaseConfig.java
===================================================================
--- modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/config/KnowledgeBaseConfig.java (rev 0)
+++ modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/config/KnowledgeBaseConfig.java 2010-04-01 05:25:52 UTC (rev 12347)
@@ -0,0 +1,89 @@
+package org.jboss.seam.drools.config;
+
+import java.util.regex.Pattern;
+
+/**
+ *
+ * @author Tihomir Surdilovic
+ */
+public class KnowledgeBaseConfig
+{
+ private static final Pattern DIVIDER = Pattern.compile(":");
+ private static final int RESOURCE_PATH = 0;
+ 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";
+
+ public static boolean isValidResource(String resource) {
+ return DIVIDER.split(resource.trim()).length >= 3;
+ }
+
+ public static boolean isRuleTemplate(String resource) {
+ return DIVIDER.split(resource.trim()).length == 4;
+ }
+
+ public static String getResourceType(String resource) {
+ return DIVIDER.split(resource.trim())[RESOURCE_TYPE];
+ }
+
+ public static String getRuleResource(String resource) {
+ return DIVIDER.split(resource.trim())[RESOURCE];
+ }
+
+ public static String getTemplateData(String resource) {
+ return DIVIDER.split(resource.trim())[RESOURCE_TEMPLATE_DATA];
+ }
+
+ public static String getResourcePath(String resource) {
+ return DIVIDER.split(resource.trim())[RESOURCE_PATH];
+ }
+
+ private String knowledgeBuilderConfig;
+ private String knowledgeBaseConfig;
+ private String[] ruleResources;
+ private String[] eventListeners;
+
+ public String getKnowledgeBuilderConfig()
+ {
+ return knowledgeBuilderConfig;
+ }
+
+ public void setKnowledgeBuilderConfig(String knowledgeBuilderConfig)
+ {
+ this.knowledgeBuilderConfig = knowledgeBuilderConfig;
+ }
+
+ public String getKnowledgeBaseConfig()
+ {
+ return knowledgeBaseConfig;
+ }
+
+ public void setKnowledgeBaseConfig(String knowledgeBaseConfig)
+ {
+ this.knowledgeBaseConfig = knowledgeBaseConfig;
+ }
+
+ public String[] getRuleResources()
+ {
+ return ruleResources;
+ }
+
+ public void setRuleResources(String[] ruleResources)
+ {
+ this.ruleResources = ruleResources;
+ }
+
+ public String[] getEventListeners()
+ {
+ return eventListeners;
+ }
+
+ public void setEventListeners(String[] eventListeners)
+ {
+ this.eventListeners = eventListeners;
+ }
+}
Copied: modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/old/FactProvider.java (from rev 12298, modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/FactProvider.java)
===================================================================
--- modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/old/FactProvider.java (rev 0)
+++ modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/old/FactProvider.java 2010-04-01 05:25:52 UTC (rev 12347)
@@ -0,0 +1,20 @@
+package org.jboss.seam.drools.old;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Interface for fact providers.
+ *
+ * @author Tihomir Surdilovic
+ *
+ */
+public interface FactProvider
+{
+ public List<Object> getFacts();
+ public void setFacts(List<Object> facts);
+
+ public Map<String, Object> getGlobals();
+ public void setGlobals(Map<String, Object> globals);
+
+}
\ No newline at end of file
Copied: modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/old/KnowledgeBaseManager.java (from rev 12298, modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeBaseManager.java)
===================================================================
--- modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/old/KnowledgeBaseManager.java (rev 0)
+++ modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/old/KnowledgeBaseManager.java 2010-04-01 05:25:52 UTC (rev 12347)
@@ -0,0 +1,207 @@
+package org.jboss.seam.drools.old;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.Properties;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Disposes;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+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;
+import org.drools.builder.ResourceType;
+import org.drools.event.knowledgebase.KnowledgeBaseEventListener;
+import org.drools.io.ResourceFactory;
+import org.drools.template.ObjectDataCompiler;
+import org.jboss.seam.drools.events.KnowledgeBuilderErrorsEvent;
+import org.jboss.seam.drools.events.RuleResourceAddedEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Manager component for a Drools KnowledgeBase.
+ *
+ * @author Tihomir Surdilovic
+ */
+public class KnowledgeBaseManager
+{
+ private static final Logger log = LoggerFactory.getLogger(KnowledgeBaseManager.class);
+
+ private KnowledgeBaseManagerConfig kbaseManagerConfig;
+
+ @Inject
+ BeanManager manager;
+
+ @Inject
+ public KnowledgeBaseManager(KnowledgeBaseManagerConfig kbaseManagerConfig) {
+ this.kbaseManagerConfig = kbaseManagerConfig;
+ }
+
+ @Produces
+ @ApplicationScoped
+ public KnowledgeBase createKBase() throws Exception
+ {
+ KnowledgeBase kbase;
+ KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(getKnowledgeBuilderConfiguration());
+
+ for (String nextResource : kbaseManagerConfig.getRuleResources())
+ {
+ addResource(kbuilder, nextResource);
+ }
+
+ KnowledgeBuilderErrors kbuildererrors = kbuilder.getErrors();
+ if (kbuildererrors.size() > 0)
+ {
+ for (KnowledgeBuilderError kbuildererror : kbuildererrors)
+ {
+ log.error(kbuildererror.getMessage());
+ }
+ manager.fireEvent(new KnowledgeBuilderErrorsEvent(kbuildererrors));
+ }
+
+ kbase = KnowledgeBaseFactory.newKnowledgeBase(getKnowledgeBaseConfiguration());
+ kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
+
+ if (kbaseManagerConfig.getEventListeners() != null)
+ {
+ for (String eventListener : kbaseManagerConfig.getEventListeners())
+ {
+ addEventListener(kbase, eventListener);
+ }
+ }
+ return kbase;
+ }
+
+ public void disposeKBase(@Disposes KnowledgeBase kbase)
+ {
+ kbase = null;
+ }
+
+ private void addEventListener(org.drools.KnowledgeBase kbase, String eventListener) {
+ try {
+ @SuppressWarnings("unchecked")
+ Class eventListenerClass = Class.forName(eventListener);
+ Object eventListenerObject = eventListenerClass.newInstance();
+
+ if(eventListenerObject instanceof KnowledgeBaseEventListener) {
+ kbase.addEventListener((KnowledgeBaseEventListener) eventListenerObject);
+ } else {
+ log.debug("Event Listener " + eventListener + " is not of type KnowledgeBaseEventListener");
+ }
+ } catch(Exception e) {
+ log.error("Error adding event listener " + e.getMessage());
+ }
+ }
+
+ protected void addResource(KnowledgeBuilder kbuilder, String resource) throws Exception
+ {
+ if(KnowledgeBaseManagerConfig.isValidResource(resource)) {
+ ResourceType resourceType = ResourceType.getResourceType(KnowledgeBaseManagerConfig.getResourceType(resource));
+ if(KnowledgeBaseManagerConfig.isRuleTemplate(resource)) {
+ @SuppressWarnings("unchecked")
+ 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(KnowledgeBaseManagerConfig.getRuleResource(resource));
+ if (templateStream == null)
+ {
+ throw new IllegalStateException("Could not locate rule resource: " + KnowledgeBaseManagerConfig.getRuleResource(resource));
+ }
+
+ ObjectDataCompiler converter = new ObjectDataCompiler();
+ String drl = converter.compile(templateDataProvider.getTemplateData(), templateStream);
+ templateStream.close();
+ log.debug("Generated following DRL from template: " + drl);
+ Reader rdr = new StringReader(drl);
+
+ kbuilder.add(ResourceFactory.newReaderResource(rdr), resourceType);
+ } else {
+ if (KnowledgeBaseManagerConfig.getResourcePath(resource).equals(KnowledgeBaseManagerConfig.RESOURCE_TYPE_URL))
+ {
+ kbuilder.add(ResourceFactory.newUrlResource(KnowledgeBaseManagerConfig.getRuleResource(resource)), resourceType);
+ manager.fireEvent(new RuleResourceAddedEvent(KnowledgeBaseManagerConfig.getRuleResource(resource)));
+ }
+ else if (KnowledgeBaseManagerConfig.getResourcePath(resource).equals(KnowledgeBaseManagerConfig.RESOURCE_TYPE_FILE))
+ {
+ kbuilder.add(ResourceFactory.newFileResource(KnowledgeBaseManagerConfig.getRuleResource(resource)), resourceType);
+ manager.fireEvent(new RuleResourceAddedEvent(KnowledgeBaseManagerConfig.getRuleResource(resource)));
+ }
+ else if (KnowledgeBaseManagerConfig.getResourcePath(resource).equals(KnowledgeBaseManagerConfig.RESOURCE_TYPE_CLASSPATH))
+ {
+ kbuilder.add(ResourceFactory.newClassPathResource(KnowledgeBaseManagerConfig.getRuleResource(resource)), resourceType);
+ manager.fireEvent(new RuleResourceAddedEvent(KnowledgeBaseManagerConfig.getRuleResource(resource)));
+ }
+ else
+ {
+ log.error("Invalid resource path: " + KnowledgeBaseManagerConfig.getResourcePath(resource));
+ }
+ }
+ } else {
+ log.error("Invalid resource definition: " + resource);
+ }
+ }
+
+ public KnowledgeBuilderConfiguration getKnowledgeBuilderConfiguration() throws Exception
+ {
+ KnowledgeBuilderConfiguration kbuilderconfig = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
+ if(kbaseManagerConfig.getKnowledgeBuilderConfigProp() != null) {
+ kbuilderconfig = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(kbaseManagerConfig.getKnowledgeBuilderConfigProp(), null);
+ log.debug("KnowledgeBuilderConfiguration loaded: " + kbaseManagerConfig.getKnowledgeBuilderConfigProp());
+ } else {
+ // 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();
+
+ if(kbaseManagerConfig.getKnowledgeBaseConfigProp() != null) {
+ kbaseconfig = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(kbaseManagerConfig.getKnowledgeBaseConfigProp(), null);
+ log.debug("KnowledgeBaseConfiguration loaded: " + kbaseManagerConfig.getKnowledgeBaseConfigProp());
+ } else {
+ // 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
Copied: modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/old/KnowledgeBaseManagerConfig.java (from rev 12298, modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeBaseManagerConfig.java)
===================================================================
--- modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/old/KnowledgeBaseManagerConfig.java (rev 0)
+++ modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/old/KnowledgeBaseManagerConfig.java 2010-04-01 05:25:52 UTC (rev 12347)
@@ -0,0 +1,116 @@
+package org.jboss.seam.drools.old;
+
+import java.util.Properties;
+import java.util.regex.Pattern;
+
+/**
+ * KnowledgeBaseManager Configuration.
+ *
+ * @author Tihomir Surdilovic
+ */
+public class KnowledgeBaseManagerConfig
+{
+ private static final Pattern DIVIDER = Pattern.compile(";");
+ private static final int RESOURCE_PATH = 0;
+ 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 Properties knowledgeBuilderConfigProp;
+ private Properties knowledgeBaseConfigProp;
+ private String[] ruleResources;
+ private String[] eventListeners;
+
+ public static boolean isValidResource(String resource) {
+ return DIVIDER.split(resource.trim()).length >= 3;
+ }
+
+ public static boolean isRuleTemplate(String resource) {
+ return DIVIDER.split(resource.trim()).length == 4;
+ }
+
+ public static String getResourceType(String resource) {
+ return DIVIDER.split(resource.trim())[RESOURCE_TYPE];
+ }
+
+ public static String getRuleResource(String resource) {
+ return DIVIDER.split(resource.trim())[RESOURCE];
+ }
+
+ public static String getTemplateData(String resource) {
+ return DIVIDER.split(resource.trim())[RESOURCE_TEMPLATE_DATA];
+ }
+
+ public static String getResourcePath(String resource) {
+ return DIVIDER.split(resource.trim())[RESOURCE_PATH];
+ }
+
+ public String getKnowledgeBuilderConfig()
+ {
+ return knowledgeBuilderConfig;
+ }
+
+ public void setKnowledgeBuilderConfig(String knowledgeBuilderConfig)
+ {
+ this.knowledgeBuilderConfig = knowledgeBuilderConfig;
+ }
+
+ public String getKnowledgeBaseConfig()
+ {
+ return knowledgeBaseConfig;
+ }
+
+ public void setKnowledgeBaseConfig(String knowledgeBaseConfig)
+ {
+ this.knowledgeBaseConfig = knowledgeBaseConfig;
+ }
+
+ public String[] getRuleResources()
+ {
+ return ruleResources;
+ }
+
+ public void setRuleResources(String[] ruleResources)
+ {
+ this.ruleResources = ruleResources;
+ }
+
+ public String[] getEventListeners()
+ {
+ return eventListeners;
+ }
+
+ public void setEventListeners(String[] eventListeners)
+ {
+ this.eventListeners = eventListeners;
+ }
+
+ public Properties getKnowledgeBuilderConfigProp()
+ {
+ return knowledgeBuilderConfigProp;
+ }
+
+ public void setKnowledgeBuilderConfigProp(Properties knowledgeBuilderConfigProp)
+ {
+ this.knowledgeBuilderConfigProp = knowledgeBuilderConfigProp;
+ }
+
+ public Properties getKnowledgeBaseConfigProp()
+ {
+ return knowledgeBaseConfigProp;
+ }
+
+ public void setKnowledgeBaseConfigProp(Properties knowledgeBaseConfigProp)
+ {
+ this.knowledgeBaseConfigProp = knowledgeBaseConfigProp;
+ }
+
+
+
+}
Copied: modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/old/KnowledgeSessionManager.java (from rev 12298, modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeSessionManager.java)
===================================================================
--- modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/old/KnowledgeSessionManager.java (rev 0)
+++ modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/old/KnowledgeSessionManager.java 2010-04-01 05:25:52 UTC (rev 12347)
@@ -0,0 +1,186 @@
+package org.jboss.seam.drools.old;
+
+import java.io.InputStream;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Properties;
+
+import java.lang.annotation.Annotation;
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.Disposes;
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.security.auth.login.Configuration;
+
+import org.drools.KnowledgeBase;
+import org.drools.KnowledgeBaseFactory;
+import org.drools.event.process.ProcessEventListener;
+import org.drools.event.rule.AgendaEventListener;
+import org.drools.event.rule.WorkingMemoryEventListener;
+import org.drools.logger.KnowledgeRuntimeLogger;
+import org.drools.logger.KnowledgeRuntimeLoggerFactory;
+import org.drools.runtime.KnowledgeSessionConfiguration;
+import org.drools.runtime.StatefulKnowledgeSession;
+import org.drools.runtime.StatelessKnowledgeSession;
+import org.drools.runtime.process.WorkItemHandler;
+import org.jboss.seam.drools.events.KnowledgeSessionCreatedEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Manager component for a Drools Knowledge Sessions.
+ *
+ * @author Tihomir Surdilovic
+ */
+public class KnowledgeSessionManager
+{
+ private static final Logger log = LoggerFactory.getLogger(KnowledgeSessionManager.class);
+
+ private KnowledgeSessionManagerConfig ksessionManagerConfig;
+ private Map<Integer, KnowledgeRuntimeLogger> statefulKnowledgeLoggers = new Hashtable<Integer, KnowledgeRuntimeLogger>();
+
+ @Inject
+ BeanManager manager;
+
+ @Inject
+ public KnowledgeSessionManager(KnowledgeSessionManagerConfig ksessionManagerConfig)
+ {
+ this.ksessionManagerConfig = ksessionManagerConfig;
+ }
+
+ @Produces
+ @Any
+ public StatefulKnowledgeSession getStatefulSession(InjectionPoint ip, Instance<KnowledgeBase> kbase) throws Exception
+ {
+ StatefulKnowledgeSession ksession = kbase.select(ip.getQualifiers().toArray(new Annotation[0])).get().newStatefulKnowledgeSession(getKSessionConfig(), null);
+ addEventListeners(ksession);
+ addWorkItemHandlers(ksession);
+ addAuditLog(ksession);
+ manager.fireEvent(new KnowledgeSessionCreatedEvent(ksession.getId()));
+ return ksession;
+ }
+
+ public void disposeStatefulSession(@Disposes StatefulKnowledgeSession statefulSession)
+ {
+ if (statefulKnowledgeLoggers.get(statefulSession.getId()) != null)
+ {
+ statefulKnowledgeLoggers.get(statefulSession.getId()).close();
+ }
+ statefulSession.dispose();
+ }
+
+ @Produces
+ @Any
+ public StatelessKnowledgeSession getStatelessSession(InjectionPoint ip, Instance<KnowledgeBase> kbase) throws Exception
+ {
+ StatelessKnowledgeSession ksession = kbase.select(ip.getQualifiers().toArray(new Annotation[0])).get().newStatelessKnowledgeSession(getKSessionConfig());
+ addEventListeners(ksession);
+ manager.fireEvent(new KnowledgeSessionCreatedEvent(-1));
+ return ksession;
+ }
+
+ private KnowledgeSessionConfiguration getKSessionConfig() throws Exception
+ {
+ KnowledgeSessionConfiguration ksessionConfig = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
+ if(ksessionManagerConfig.getKnowledgeSessionConfigProp() != null) {
+ ksessionConfig = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(ksessionManagerConfig.getKnowledgeSessionConfigProp());
+ } else {
+ // Only allow resource for .properties files
+ if (ksessionManagerConfig.getKnowledgeSessionConfig() != null && ksessionManagerConfig.getKnowledgeSessionConfig().endsWith(".properties"))
+ {
+ Properties ksessionProp = new Properties();
+ InputStream in = this.getClass().getClassLoader().getResourceAsStream(ksessionManagerConfig.getKnowledgeSessionConfig());
+ if (in == null)
+ {
+ throw new IllegalStateException("Could not locate knowledgeSessionrConfig: " + ksessionManagerConfig.getKnowledgeSessionConfig());
+ }
+ ksessionProp.load(in);
+ in.close();
+ ksessionConfig = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(ksessionProp);
+ log.debug("KnowledgeSessionConfiguration loaded: " + ksessionManagerConfig.getKnowledgeSessionConfig());
+ }
+ }
+ return ksessionConfig;
+ }
+
+
+ private void addAuditLog(StatefulKnowledgeSession ksession) throws Exception {
+ if(ksessionManagerConfig.getAuditLog() != null) {
+ if(KnowledgeSessionManagerConfig.isFileLogger(ksessionManagerConfig.getAuditLog())) {
+ String logName = KnowledgeSessionManagerConfig.getFileLoggerPath(ksessionManagerConfig.getAuditLog()) + System.currentTimeMillis();
+ KnowledgeRuntimeLogger krLogger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, logName);
+ statefulKnowledgeLoggers.put(ksession.getId(), krLogger);
+ } else if(KnowledgeSessionManagerConfig.isConsoleLogger(ksessionManagerConfig.getAuditLog())) {
+ KnowledgeRuntimeLogger krLogger = KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);
+ statefulKnowledgeLoggers.put(ksession.getId(), krLogger);
+ } else if(KnowledgeSessionManagerConfig.isThreadedLogger(ksessionManagerConfig.getAuditLog())) {
+ String logName = KnowledgeSessionManagerConfig.getThreadedLoggerPath(ksessionManagerConfig.getAuditLog()) + System.currentTimeMillis();
+ int interval = KnowledgeSessionManagerConfig.getThreadedLoggerInterval(ksessionManagerConfig.getAuditLog());
+ KnowledgeRuntimeLogger krLogger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, logName, interval);
+ statefulKnowledgeLoggers.put(ksession.getId(), krLogger);
+ } else {
+ log.warn("Invalid logger specified: " + ksessionManagerConfig.getAuditLog());
+ }
+ }
+ }
+
+ public void addEventListeners(StatefulKnowledgeSession ksession) throws Exception {
+ if(ksessionManagerConfig.getEventListeners() != null) {
+ for(String eventListener : ksessionManagerConfig.getEventListeners()) {
+ Class eventListenerClass = Class.forName(eventListener);
+ Object eventListenerObject = eventListenerClass.newInstance();
+
+ if(eventListenerObject instanceof WorkingMemoryEventListener) {
+ ksession.addEventListener((WorkingMemoryEventListener) eventListenerObject);
+ } else if(eventListenerObject instanceof AgendaEventListener) {
+ ksession.addEventListener((AgendaEventListener) eventListenerObject);
+ } else if(eventListenerObject instanceof ProcessEventListener) {
+ ksession.addEventListener((ProcessEventListener) eventListenerObject);
+ } else {
+ log.debug("Invalid Event Listener: " + eventListener);
+ }
+ }
+ }
+ }
+
+ public void addEventListeners(StatelessKnowledgeSession ksession) throws Exception{
+ if(ksessionManagerConfig.getEventListeners() != null) {
+ for(String eventListener : ksessionManagerConfig.getEventListeners()) {
+ @SuppressWarnings("unchecked")
+ Class eventListenerClass = Class.forName(eventListener);
+ Object eventListenerObject = eventListenerClass.newInstance();
+
+ if(eventListenerObject instanceof WorkingMemoryEventListener) {
+ ksession.addEventListener((WorkingMemoryEventListener) eventListenerObject);
+ } else if(eventListenerObject instanceof AgendaEventListener) {
+ ksession.addEventListener((AgendaEventListener) eventListenerObject);
+ } else if(eventListenerObject instanceof ProcessEventListener) {
+ ksession.addEventListener((ProcessEventListener) eventListenerObject);
+ } else {
+ log.debug("Invalid Event Listener: " + eventListener);
+ }
+ }
+ }
+ }
+
+ public void addWorkItemHandlers(StatefulKnowledgeSession ksession) {
+ if(ksessionManagerConfig.getWorkItemHandlers() != null) {
+ for(String workItemHandlerStr : ksessionManagerConfig.getWorkItemHandlers()) {
+ if(KnowledgeSessionManagerConfig.isValidWorkItemHandler(workItemHandlerStr)) {
+ @SuppressWarnings("unchecked")
+ Bean<WorkItemHandler> workItemHandlerBean = (Bean<WorkItemHandler>) manager.getBeans(KnowledgeSessionManagerConfig.getWorkItemHandlerType(workItemHandlerStr)).iterator().next();
+ WorkItemHandler handler = (WorkItemHandler) manager.getReference(workItemHandlerBean, Configuration.class, manager.createCreationalContext(workItemHandlerBean));
+ log.debug("Registering new WorkItemHandler: " + KnowledgeSessionManagerConfig.getWorkItemHandlerName(workItemHandlerStr));
+ ksession.getWorkItemManager().registerWorkItemHandler(KnowledgeSessionManagerConfig.getWorkItemHandlerName(workItemHandlerStr), handler);
+ }
+ }
+ }
+ }
+
+
+}
Copied: modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/old/KnowledgeSessionManagerConfig.java (from rev 12298, modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeSessionManagerConfig.java)
===================================================================
--- modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/old/KnowledgeSessionManagerConfig.java (rev 0)
+++ modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/old/KnowledgeSessionManagerConfig.java 2010-04-01 05:25:52 UTC (rev 12347)
@@ -0,0 +1,106 @@
+package org.jboss.seam.drools.old;
+
+import java.util.Properties;
+import java.util.regex.Pattern;
+
+/**
+ * KnowledgeSessionManager Configuration.
+ *
+ * @author Tihomir Surdilovic
+ */
+public class KnowledgeSessionManagerConfig
+{
+ private static final Pattern DIVIDER = Pattern.compile(";");
+ private static final int WORKITEMHANDLER_NAME = 0;
+ private static final int WORKITEMHANDLER_TYPE = 1;
+ private static final int AUDIT_LOG_TYPE = 0;
+ private static final int AUDIT_LOG_INFO = 1;
+ private static final int AUDIT_LOG_INTERVAL = 2;
+ private static final String AUDIT_LOG_TYPE_FILE = "file";
+ private static final String AUDIT_LOG_TYPE_CONSOLE = "console";
+ private static final String AUDIT_LOG_TYPE_THREADED = "threaded";
+
+ private String[] eventListeners;
+ private String[] workItemHandlers;
+ private String knowledgeSessionConfig;
+ private Properties knowledgeSessionConfigProp;
+ private String auditLog;
+
+ public static String getWorkItemHandlerName(String workItemHandlerStr) {
+ return DIVIDER.split(workItemHandlerStr.trim())[WORKITEMHANDLER_NAME];
+ }
+
+ public static String getWorkItemHandlerType(String workItemHandlerStr) {
+ return DIVIDER.split(workItemHandlerStr.trim())[WORKITEMHANDLER_TYPE];
+ }
+
+ public static boolean isValidWorkItemHandler(String workItemHandlerStr) {
+ return DIVIDER.split(workItemHandlerStr.trim()).length == 2;
+ }
+
+ public static boolean isFileLogger(String auditLog) {
+ return DIVIDER.split(auditLog.trim())[AUDIT_LOG_TYPE] == AUDIT_LOG_TYPE_FILE;
+ }
+
+ public static boolean isConsoleLogger(String auditLog) {
+ return DIVIDER.split(auditLog.trim())[AUDIT_LOG_TYPE] == AUDIT_LOG_TYPE_CONSOLE;
+ }
+
+ public static boolean isThreadedLogger(String auditLog) {
+ return DIVIDER.split(auditLog.trim())[AUDIT_LOG_TYPE] == AUDIT_LOG_TYPE_THREADED;
+ }
+
+ public static String getFileLoggerPath(String auditLog) {
+ return DIVIDER.split(auditLog.trim())[AUDIT_LOG_INFO];
+ }
+
+ public static String getThreadedLoggerPath(String auditLog) {
+ return DIVIDER.split(auditLog.trim())[AUDIT_LOG_INFO];
+ }
+
+ public static int getThreadedLoggerInterval(String auditLog) {
+ return Integer.parseInt(DIVIDER.split(auditLog.trim())[AUDIT_LOG_INTERVAL]);
+ }
+
+ public String[] getEventListeners()
+ {
+ return eventListeners;
+ }
+ public void setEventListeners(String[] eventListeners)
+ {
+ this.eventListeners = eventListeners;
+ }
+ public String[] getWorkItemHandlers()
+ {
+ return workItemHandlers;
+ }
+ public void setWorkItemHandlers(String[] workItemHandlers)
+ {
+ this.workItemHandlers = workItemHandlers;
+ }
+ public String getKnowledgeSessionConfig()
+ {
+ return knowledgeSessionConfig;
+ }
+ public void setKnowledgeSessionConfig(String knowledgeSessionConfig)
+ {
+ this.knowledgeSessionConfig = knowledgeSessionConfig;
+ }
+ public String getAuditLog()
+ {
+ return auditLog;
+ }
+ public void setAuditLog(String auditLog)
+ {
+ this.auditLog = auditLog;
+ }
+ public Properties getKnowledgeSessionConfigProp()
+ {
+ return knowledgeSessionConfigProp;
+ }
+ public void setKnowledgeSessionConfigProp(Properties knowledgeSessionConfigProp)
+ {
+ this.knowledgeSessionConfigProp = knowledgeSessionConfigProp;
+ }
+
+}
Copied: modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/old/TemplateDataProvider.java (from rev 12298, modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/TemplateDataProvider.java)
===================================================================
--- modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/old/TemplateDataProvider.java (rev 0)
+++ modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/old/TemplateDataProvider.java 2010-04-01 05:25:52 UTC (rev 12347)
@@ -0,0 +1,14 @@
+package org.jboss.seam.drools.old;
+
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * Interface for template data providers.
+ *
+ * @author Tihomir Surdilovic
+ */
+public interface TemplateDataProvider
+{
+ public Collection<Map<String, Object>> getTemplateData();
+}
Added: modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/KBase.java
===================================================================
--- modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/KBase.java (rev 0)
+++ modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/KBase.java 2010-04-01 05:25:52 UTC (rev 12347)
@@ -0,0 +1,22 @@
+package org.jboss.seam.drools.qualifier;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+ at Qualifier
+ at Target({METHOD, FIELD})
+ at Documented
+ at Retention(RUNTIME)
+ at Inherited
+public @interface KBase
+{
+ String name();
+}
Added: modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/KBaseConfig.java
===================================================================
--- modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/KBaseConfig.java (rev 0)
+++ modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/KBaseConfig.java 2010-04-01 05:25:52 UTC (rev 12347)
@@ -0,0 +1,22 @@
+package org.jboss.seam.drools.qualifier;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+ at Qualifier
+ at Target({METHOD, FIELD})
+ at Documented
+ at Retention(RUNTIME)
+ at Inherited
+public @interface KBaseConfig
+{
+ String name();
+}
Added: modules/drools/trunk/core/src/test/java/org/jboss/seam/drools/kbase/KBaseTest.java
===================================================================
--- modules/drools/trunk/core/src/test/java/org/jboss/seam/drools/kbase/KBaseTest.java (rev 0)
+++ modules/drools/trunk/core/src/test/java/org/jboss/seam/drools/kbase/KBaseTest.java 2010-04-01 05:25:52 UTC (rev 12347)
@@ -0,0 +1,42 @@
+package org.jboss.seam.drools.kbase;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import javax.inject.Inject;
+
+import org.drools.KnowledgeBase;
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.drools.KnowledgeBaseProducer;
+import org.jboss.seam.drools.qualifier.KBase;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+ at RunWith(Arquillian.class)
+public class KBaseTest
+{
+ @Deployment
+ public static JavaArchive createTestArchive()
+ {
+ return Archives.create("kbasetest.jar", JavaArchive.class)
+ .addPackages(true, KnowledgeBaseProducer.class.getPackage())
+ .addResource(KBaseTest.class.getPackage().getName().replaceAll("\\.", "/") + "/kbasetest.drl")
+ .addResource(KBaseTest.class.getPackage().getName().replaceAll("\\.", "/") + "/kbuilderconfig.properties")
+ .addResource(KBaseTest.class.getPackage().getName().replaceAll("\\.", "/") + "/kbaseconfig.properties")
+ .addManifestResource(KBaseTest.class.getPackage().getName().replaceAll("\\.", "/") + "/KBaseTest-beans.xml",
+ ArchivePaths.create("beans.xml"));
+ }
+
+ @Inject @KBase(name="kbase1") KnowledgeBase kbase;
+
+ @Test
+ public void testKBase() {
+ assertNotNull(kbase);
+ }
+}
+
Added: modules/drools/trunk/core/src/test/resources/org/jboss/seam/drools/kbase/KBaseTest-beans.xml
===================================================================
--- modules/drools/trunk/core/src/test/resources/org/jboss/seam/drools/kbase/KBaseTest-beans.xml (rev 0)
+++ modules/drools/trunk/core/src/test/resources/org/jboss/seam/drools/kbase/KBaseTest-beans.xml 2010-04-01 05:25:52 UTC (rev 12347)
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:s="urn:java:seam:core"
+ xmlns:drools="urn:java:org.jboss.seam.drools"
+ xmlns:drools-config="urn:java:org.jboss.seam.drools.config"
+ xmlns:drools-qualifier="urn:java:org.jboss.seam.drools.qualifier">
+
+ <drools-config:KnowledgeBaseConfig>
+ <s:overrides/>
+ <drools-qualifier:KBaseConfig name="kbaseconfig1"/>
+ <drools-config:knowledgeBuilderConfig>kbuilderconfig.properties</drools-config:knowledgeBuilderConfig>
+ <drools-config:knowledgeBaseConfig>kbaseconfig.properties</drools-config:knowledgeBaseConfig>
+ <drools-config:ruleResources>
+ <s:value>classpath:kbasetest.drl:DRL</s:value>
+ </drools-config:ruleResources>
+ <drools-config:eventListeners>
+ <s:value>org.drools.event.knowledgebase.DefaultKnowledgeBaseEventListener</s:value>
+ </drools-config:eventListeners>
+ </drools-config:KnowledgeBaseConfig>
+
+ <drools:KnowledgeBaseProducer>
+ <s:specializes/>
+ <drools:produceKBase>
+ <drools-qualifier:KBase name="kbase1"/>
+ <s:Inject/>
+ <drools-qualifier:KBaseConfig name="kbaseconfig1"/>
+ </drools:produceKBase>
+ </drools:KnowledgeBaseProducer>
+
+</beans>
\ No newline at end of file
Added: modules/drools/trunk/core/src/test/resources/org/jboss/seam/drools/kbase/kbaseconfig.properties
===================================================================
Added: modules/drools/trunk/core/src/test/resources/org/jboss/seam/drools/kbase/kbasetest.drl
===================================================================
--- modules/drools/trunk/core/src/test/resources/org/jboss/seam/drools/kbase/kbasetest.drl (rev 0)
+++ modules/drools/trunk/core/src/test/resources/org/jboss/seam/drools/kbase/kbasetest.drl 2010-04-01 05:25:52 UTC (rev 12347)
@@ -0,0 +1,29 @@
+#created on: Apr 1, 2010
+package org.jboss.seam.drools.kbase
+
+#list any import classes here.
+
+
+
+#declare any global variables here
+
+
+
+
+rule "Your First Rule"
+
+ when
+ #conditions
+ then
+ #actions
+
+end
+
+rule "Your Second Rule"
+ #include attributes such as "salience" here...
+ when
+ #conditions
+ then
+ #actions
+
+end
Added: modules/drools/trunk/core/src/test/resources/org/jboss/seam/drools/kbase/kbuilderconfig.properties
===================================================================
Modified: modules/drools/trunk/docs/drools-reference.pdf
===================================================================
(Binary files differ)
More information about the seam-commits
mailing list