Seam SVN: r12351 - branches/community/Seam_2_2/src/test/ftest/examples.
by seam-commits@lists.jboss.org
Author: mgencur(a)redhat.com
Date: 2010-04-01 02:25:35 -0400 (Thu, 01 Apr 2010)
New Revision: 12351
Modified:
branches/community/Seam_2_2/src/test/ftest/examples/build.xml
Log:
JBSEAM-4610 - another change to support internet explorer and testng 5.10
Modified: branches/community/Seam_2_2/src/test/ftest/examples/build.xml
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/examples/build.xml 2010-04-01 06:13:37 UTC (rev 12350)
+++ branches/community/Seam_2_2/src/test/ftest/examples/build.xml 2010-04-01 06:25:35 UTC (rev 12351)
@@ -66,7 +66,7 @@
<path id="classpath.build">
<fileset dir="${root.lib.dir}">
- <include name="testng.jar"/>
+ <include name="testng-jdk15.jar"/>
</fileset>
<fileset dir="${ftest.lib.dir}" includes="**/*.jar" />
</path>
@@ -384,6 +384,8 @@
</dependency>
<dependency groupId="org.seleniumhq.webdriver" artifactId="webdriver-support" version="0.9.7376">
</dependency>
+ <dependency groupId="org.seleniumhq.webdriver" artifactId="webdriver-ie" version="0.9.7376">
+ </dependency>
</copyInlineDependencies>
<property name="copy.webdriver.done" value="true" />
</target>
14 years, 9 months
Seam SVN: r12350 - in modules/persistence/trunk: src/main/java/org/jboss/seam and 4 other directories.
by seam-commits@lists.jboss.org
Author: dan.j.allen
Date: 2010-04-01 02:13:37 -0400 (Thu, 01 Apr 2010)
New Revision: 12350
Added:
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/JtaTxInterceptor.java
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/TransactionPropagation.java
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/Transactional.java
modules/persistence/trunk/src/main/resources/META-INF/beans.xml
Modified:
modules/persistence/trunk/pom.xml
modules/persistence/trunk/src/main/java/org/jboss/seam/persistence/PersistenceContextExtension.java
modules/persistence/trunk/src/test/java/org/jboss/seam/persistence/PersistenceContextExtensionTest.java
Log:
commit incremental changes; nothing guarnateed to work yet
Modified: modules/persistence/trunk/pom.xml
===================================================================
--- modules/persistence/trunk/pom.xml 2010-04-01 05:46:09 UTC (rev 12349)
+++ modules/persistence/trunk/pom.xml 2010-04-01 06:13:37 UTC (rev 12350)
@@ -56,9 +56,17 @@
</dependency>
<dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core-test</artifactId>
+ <scope>test</scope>
</dependency>
+
</dependencies>
Modified: modules/persistence/trunk/src/main/java/org/jboss/seam/persistence/PersistenceContextExtension.java
===================================================================
--- modules/persistence/trunk/src/main/java/org/jboss/seam/persistence/PersistenceContextExtension.java 2010-04-01 05:46:09 UTC (rev 12349)
+++ modules/persistence/trunk/src/main/java/org/jboss/seam/persistence/PersistenceContextExtension.java 2010-04-01 06:13:37 UTC (rev 12350)
@@ -3,7 +3,9 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import javax.enterprise.context.ApplicationScoped;
@@ -26,17 +28,28 @@
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.PersistenceContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
- * Support for managed persistence contexts in Java SE environment.
+ * Support for managed persistence contexts in a Java SE environment or Servlet container.
+ *
+ * <p>Unlike with standard Java EE, the unitName attribute on {@link PersistenceContext} must
+ * be provided if the persistence unit is assigned a name in persistence.xml. This
+ * class supports multiple persistence units, but it does not permit multiple
+ * producers for the same persistence unit (naturally).</p>
*
* @author Gavin King
- *
+ * @author Dan Allen
*/
public class PersistenceContextExtension implements Extension
{
- private Bean<EntityManagerFactory> emfBean;
+ private static final Logger log = LoggerFactory.getLogger(PersistenceContextExtension.class);
+ private Map<String, Bean<EntityManagerFactory>> emfBeans = new HashMap<String, Bean<EntityManagerFactory>>();
+
+ private Boolean bootstrapRequired;
+
/**
* For @PersistenceContext producer fields, make a bean for the EMF, then
* wrap the producer CDI creates, to get the EM from the EMF bean we made
@@ -44,12 +57,31 @@
*/
void processProducer(@Observes ProcessProducer<?, EntityManager> pp, final BeanManager bm)
{
+ if (Boolean.FALSE.equals(bootstrapRequired))
+ {
+ return;
+ }
+ else if (bootstrapRequired == null)
+ {
+ if (isPersistenceContainerManaged())
+ {
+ bootstrapRequired = false;
+ return;
+ }
+ else
+ {
+ bootstrapRequired = true;
+ log.info("Java SE persistence bootstrap required");
+ }
+ }
+
if (pp.getAnnotatedMember().isAnnotationPresent(PersistenceContext.class))
{
- if (emfBean == null)
+ AnnotatedField<?> field = (AnnotatedField<?>) pp.getAnnotatedMember();
+ final String unitName = field.getAnnotation(PersistenceContext.class).unitName();
+ if (!emfBeans.containsKey(unitName))
{
- AnnotatedField<?> field = (AnnotatedField<?>) pp.getAnnotatedMember();
- final String unitName = field.getAnnotation(PersistenceContext.class).unitName();
+ log.info("Found persistence context producer for persistence unit: " + unitName);
final Class<?> module = field.getJavaMember().getDeclaringClass();
final Set<Annotation> qualifiers = new HashSet<Annotation>();
for (Annotation ann : field.getAnnotations())
@@ -65,14 +97,12 @@
{
qualifiers.add(new AnnotationLiteral<Default>()
{
-
/** default value. Added only to suppress compiler warnings. */
private static final long serialVersionUID = 1L;
});
}
qualifiers.add(new AnnotationLiteral<Any>()
{
-
/** default value. Added only to suppress compiler warnings. */
private static final long serialVersionUID = 1L;
});
@@ -81,15 +111,14 @@
{
/** default value. Added only to suppress compiler warnings. */
private static final long serialVersionUID = 1L;
-
{
add(EntityManagerFactory.class);
add(Object.class);
}
};
- // create a bean for the EMF
- emfBean = new Bean<EntityManagerFactory>()
+ // create and register a bean for the EMF
+ emfBeans.put(unitName, new Bean<EntityManagerFactory>()
{
public Set<Type> getTypes()
{
@@ -119,7 +148,6 @@
public Set<InjectionPoint> getInjectionPoints()
{
- // return Collections.EMPTY_SET;
return Collections.emptySet();
}
@@ -135,7 +163,6 @@
public Set<Class<? extends Annotation>> getStereotypes()
{
- // return Collections.EMPTY_SET;
return Collections.emptySet();
}
@@ -149,22 +176,19 @@
{
return false;
}
- };
+ });
}
else
{
- throw new RuntimeException("Only one EMF per application is supported");
+ throw new RuntimeException("There can only be one producer per persistence unit");
}
Producer<EntityManager> producer = new Producer<EntityManager>()
{
-
public Set<InjectionPoint> getInjectionPoints()
{
- // return Collections.EMPTY_SET;
return Collections.emptySet();
-
}
public EntityManager produce(CreationalContext<EntityManager> ctx)
@@ -174,13 +198,15 @@
private EntityManagerFactory getFactory(CreationalContext<EntityManager> ctx)
{
- return (EntityManagerFactory) bm.getReference(emfBean, EntityManagerFactory.class, ctx);
+ return (EntityManagerFactory) bm.getReference(emfBeans.get(unitName), EntityManagerFactory.class, ctx);
}
public void dispose(EntityManager em)
{
if (em.isOpen()) // work around what I suspect is a bug in Weld
+ {
em.close();
+ }
}
};
pp.setProducer(producer);
@@ -192,6 +218,39 @@
*/
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd)
{
- abd.addBean(emfBean);
+ for (Bean<EntityManagerFactory> emfBean : emfBeans.values())
+ {
+ abd.addBean(emfBean);
+ }
}
+
+ /**
+ * Check whether persistence is container managed. For now, this simply
+ * checks for the presence of the EJB API. If it's present, we assume
+ * this is an EE environment and that persistence is container managed.
+ */
+ boolean isPersistenceContainerManaged() {
+ boolean eeEnv = true;
+ try
+ {
+ if (Thread.currentThread().getContextClassLoader() != null)
+ {
+ Thread.currentThread().getContextClassLoader().loadClass("javax.ejb.Stateless");
+ }
+ else
+ {
+ Class.forName("javax.ejb.Stateless");
+ }
+ }
+ catch (ClassNotFoundException e)
+ {
+ eeEnv = false;
+ }
+ catch (NoClassDefFoundError e)
+ {
+ eeEnv = false;
+ }
+
+ return eeEnv;
+ }
}
Added: modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/JtaTxInterceptor.java
===================================================================
--- modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/JtaTxInterceptor.java (rev 0)
+++ modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/JtaTxInterceptor.java 2010-04-01 06:13:37 UTC (rev 12350)
@@ -0,0 +1,123 @@
+package org.jboss.seam.transaction;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import javax.inject.Inject;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InvocationContext;
+import javax.transaction.Status;
+import javax.transaction.UserTransaction;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A rudimentary transaction interceptor implementation, intended as a proof
+ * of concept.
+ *
+ * @author Matt Corey
+ * @author Dan Allen
+ */
+public @Transactional @Interceptor class JtaTxInterceptor {
+
+ private static final Logger log = LoggerFactory.getLogger(JtaTxInterceptor.class);
+
+ @Inject private UserTransaction utx;
+
+ /**
+ * Super quick impl. Needs to be done correctly.
+ */
+ @AroundInvoke
+ public Object workInTransaction(InvocationContext ic) throws Exception {
+ // TODO cache this information
+ TransactionPropagation type = getTransactionPropagation(ic.getMethod());
+
+ int status = utx.getStatus();
+ boolean transactionActive = (status == Status.STATUS_ACTIVE || status == Status.STATUS_MARKED_ROLLBACK);
+ boolean beginTransaction = isNewTransactionRequired(type, transactionActive);
+
+ if (beginTransaction) {
+ log.debug("Beginning transaction");
+ utx.begin();
+ }
+
+ Object result = null;
+ try {
+ result = ic.proceed();
+
+ if (beginTransaction) {
+ if (utx.getStatus() == Status.STATUS_MARKED_ROLLBACK) {
+ log.debug("Rolling back transaction marked for rollback");
+ utx.rollback();
+ }
+ else {
+ log.debug("Committing transaction");
+ utx.commit();
+ }
+ }
+
+ return result;
+ } catch (Exception e) {
+ if (beginTransaction && utx.getStatus() != Status.STATUS_NO_TRANSACTION) {
+ // FIXME don't rollback if this is an application exception which indicates no rollback
+ log.debug("Rolling back transaction as the result of an exception");
+ utx.rollback();
+ }
+
+ throw e;
+ }
+ }
+
+ /**
+ * Get the TransactionPropagation value
+ * FIXME cache this information
+ */
+ private TransactionPropagation getTransactionPropagation(Method m) {
+ // first look at the explicit method-level annotation
+ if (m.isAnnotationPresent(Transactional.class)) {
+ return m.getAnnotation(Transactional.class).value();
+ }
+ // now look at the method-level meta-annotations
+ for (Annotation a: m.getAnnotations()) {
+ if (a.annotationType().isAnnotationPresent(Transactional.class)) {
+ return a.annotationType().getAnnotation(Transactional.class).value();
+ }
+ }
+ // now try the explicit class-level annotation
+ if (m.getDeclaringClass().isAnnotationPresent(Transactional.class)) {
+ return m.getDeclaringClass().getAnnotation(Transactional.class).value();
+ }
+ // finally, try the class-level meta-annotations
+ for (Annotation a: m.getDeclaringClass().getAnnotations()) {
+ if (a.annotationType().isAnnotationPresent(Transactional.class)) {
+ return a.annotationType().getAnnotation(Transactional.class).value();
+ }
+ }
+ return null;
+ }
+
+ private boolean isNewTransactionRequired(TransactionPropagation type, boolean transactionActive) {
+ switch (type) {
+ case REQUIRED:
+ return !transactionActive;
+ case SUPPORTS:
+ return false;
+ case MANDATORY:
+ if (!transactionActive) {
+ throw new IllegalStateException("No transaction active on call to method that requires a transaction.");
+ }
+ else {
+ return false;
+ }
+ case NEVER:
+ if (transactionActive) {
+ throw new IllegalStateException("Transaction active on call to method that does not support transactions.");
+ }
+ else {
+ return false;
+ }
+ default:
+ throw new IllegalArgumentException("Unknown transaction type " + type);
+ }
+ }
+}
\ No newline at end of file
Added: modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/TransactionPropagation.java
===================================================================
--- modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/TransactionPropagation.java (rev 0)
+++ modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/TransactionPropagation.java 2010-04-01 06:13:37 UTC (rev 12350)
@@ -0,0 +1,8 @@
+package org.jboss.seam.transaction;
+
+/**
+ * @author Dan Allen
+ */
+public enum TransactionPropagation {
+ REQUIRED, SUPPORTS, MANDATORY, NEVER;
+}
\ No newline at end of file
Added: modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/Transactional.java
===================================================================
--- modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/Transactional.java (rev 0)
+++ modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/Transactional.java 2010-04-01 06:13:37 UTC (rev 12350)
@@ -0,0 +1,25 @@
+package org.jboss.seam.transaction;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import javax.enterprise.util.Nonbinding;
+import javax.interceptor.InterceptorBinding;
+
+/**
+ * @author Dan Allen
+ */
+@Inherited
+@InterceptorBinding
+(a)Retention(RetentionPolicy.RUNTIME)
+(a)Target({ElementType.METHOD, ElementType.TYPE})
+public @interface Transactional {
+ /**
+ * The transaction propagation type.
+ *
+ * @return REQUIRED by default
+ */
+ @Nonbinding TransactionPropagation value() default TransactionPropagation.REQUIRED;
+}
\ No newline at end of file
Added: modules/persistence/trunk/src/main/resources/META-INF/beans.xml
===================================================================
--- modules/persistence/trunk/src/main/resources/META-INF/beans.xml (rev 0)
+++ modules/persistence/trunk/src/main/resources/META-INF/beans.xml 2010-04-01 06:13:37 UTC (rev 12350)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ The contents of this file is permitted to be empty.
+ The schema definition is provided for your convenience.
+-->
+<beans xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://java.sun.com/xml/ns/javaee
+ http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+</beans>
Modified: modules/persistence/trunk/src/test/java/org/jboss/seam/persistence/PersistenceContextExtensionTest.java
===================================================================
--- modules/persistence/trunk/src/test/java/org/jboss/seam/persistence/PersistenceContextExtensionTest.java 2010-04-01 05:46:09 UTC (rev 12349)
+++ modules/persistence/trunk/src/test/java/org/jboss/seam/persistence/PersistenceContextExtensionTest.java 2010-04-01 06:13:37 UTC (rev 12350)
@@ -1,12 +1,13 @@
package org.jboss.seam.persistence;
-import org.jboss.weld.test.AbstractWeldTest;
+//import org.jboss.weld.test.AbstractWeldTest;
import org.testng.annotations.Test;
/**
* Presently, this is just a placeholder.
*/
@Test
-public class PersistenceContextExtensionTest extends AbstractWeldTest
+public class PersistenceContextExtensionTest
+//extends AbstractWeldTest
{
public void helloWorld(){
// System.out.println("hello world");
14 years, 9 months
Seam SVN: r12349 - modules/drools/trunk/docs.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2010-04-01 01:46:09 -0400 (Thu, 01 Apr 2010)
New Revision: 12349
Removed:
modules/drools/trunk/docs/drools-reference.pdf
Log:
removed generated pdf
Deleted: modules/drools/trunk/docs/drools-reference.pdf
===================================================================
(Binary files differ)
14 years, 9 months
Seam SVN: r12348 - modules/drools/trunk/core/src/main/java/org/jboss/seam/drools.
by seam-commits@lists.jboss.org
Author: tsurdilovic
Date: 2010-04-01 01:34:48 -0400 (Thu, 01 Apr 2010)
New Revision: 12348
Modified:
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeBaseProducer.java
Log:
added @ApplicationScoped
Modified: 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 2010-04-01 05:25:52 UTC (rev 12347)
+++ modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeBaseProducer.java 2010-04-01 05:34:48 UTC (rev 12348)
@@ -34,7 +34,7 @@
private static final Logger log = LoggerFactory.getLogger(KnowledgeBaseProducer.class);
@Inject BeanManager manager;
- @Produces
+ @Produces @ApplicationScoped
public KnowledgeBase produceKBase(KnowledgeBaseConfig kbaseConfig) throws Exception
{
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(getKnowledgeBuilderConfiguration(kbaseConfig));
14 years, 9 months
Seam SVN: r12347 - in modules/drools/trunk: core/src/main/java/org/jboss/seam/drools and 8 other directories.
by seam-commits@lists.jboss.org
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;
+
+@Qualifier
+@Target({METHOD, FIELD})
+@Documented
+@Retention(RUNTIME)
+@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;
+
+@Qualifier
+@Target({METHOD, FIELD})
+@Documented
+@Retention(RUNTIME)
+@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;
+
+(a)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)
14 years, 9 months