Author: tsurdilovic
Date: 2010-04-02 13:57:34 -0400 (Fri, 02 Apr 2010)
New Revision: 12373
Added:
modules/drools/trunk/core/src/test/resources/META-INF/beans.xml
Removed:
modules/drools/trunk/core/src/test/resources/META-INF/beans.xml
modules/drools/trunk/core/src/test/resources/org/jboss/seam/drools/kbase/KBaseTest-beans.xml
Modified:
modules/drools/trunk/core/pom.xml
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/KnowledgeBaseConfig.java
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/KBaseTest.java
Log:
added resource management
Modified: modules/drools/trunk/core/pom.xml
===================================================================
--- modules/drools/trunk/core/pom.xml 2010-04-02 13:38:51 UTC (rev 12372)
+++ modules/drools/trunk/core/pom.xml 2010-04-02 17:57:34 UTC (rev 12373)
@@ -75,6 +75,10 @@
<groupId>org.drools</groupId>
<artifactId>drools-workitems</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.jboss.weld</groupId>
+ <artifactId>weld-extensions</artifactId>
+ </dependency>
<!-- Test Dependencies -->
<dependency>
<groupId>junit</groupId>
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-02
13:38:51 UTC (rev 12372)
+++
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeBaseProducer.java 2010-04-02
17:57:34 UTC (rev 12373)
@@ -4,6 +4,7 @@
import java.util.Properties;
import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.SessionScoped;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.BeanManager;
import javax.inject.Inject;
@@ -22,6 +23,7 @@
import org.jboss.seam.drools.config.KnowledgeBaseConfig;
import org.jboss.seam.drools.events.KnowledgeBuilderErrorsEvent;
import org.jboss.seam.drools.events.RuleResourceAddedEvent;
+import org.jboss.weld.extensions.resources.ResourceProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,12 +34,13 @@
public class KnowledgeBaseProducer
{
private static final Logger log =
LoggerFactory.getLogger(KnowledgeBaseProducer.class);
+
@Inject BeanManager manager;
-
- @Produces //@ApplicationScoped
+ @Inject ResourceProvider resourceProvider;
+
+ @Produces
public KnowledgeBase produceKBase(KnowledgeBaseConfig kbaseConfig) throws Exception
{
- System.out.println("***KBASEPRODUCER CONFIG IS: " + kbaseConfig);
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder(getKnowledgeBuilderConfiguration(kbaseConfig));
for (String nextResource : kbaseConfig.getRuleResources())
@@ -74,7 +77,7 @@
if (kbaseConfig.getKnowledgeBuilderConfig() != null &&
kbaseConfig.getKnowledgeBuilderConfig().endsWith(".properties"))
{
Properties kbuilderProp = new Properties();
- InputStream in =
this.getClass().getClassLoader().getResourceAsStream(kbaseConfig.getKnowledgeBuilderConfig());
+ InputStream in =
resourceProvider.loadResourceStream(kbaseConfig.getKnowledgeBuilderConfig());
if (in == null)
{
throw new IllegalStateException("Could not locate
knowledgeBuilderConfig: " + kbaseConfig.getKnowledgeBuilderConfig());
@@ -93,7 +96,7 @@
if (kbaseConfig.getKnowledgeBaseConfig() != null &&
kbaseConfig.getKnowledgeBaseConfig().endsWith(".properties"))
{
Properties kbaseProp = new Properties();
- InputStream in =
this.getClass().getClassLoader().getResourceAsStream(kbaseConfig.getKnowledgeBaseConfig());
+ InputStream in =
resourceProvider.loadResourceStream(kbaseConfig.getKnowledgeBaseConfig());
if (in == null)
{
throw new IllegalStateException("Could not locate knowledgeBaseConfig:
" + kbaseConfig.getKnowledgeBaseConfig());
Modified:
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 2010-04-02
13:38:51 UTC (rev 12372)
+++
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/config/KnowledgeBaseConfig.java 2010-04-02
17:57:34 UTC (rev 12373)
@@ -46,6 +46,22 @@
private String knowledgeBaseConfig;
private String[] ruleResources;
private String[] eventListeners;
+
+ public String toString() {
+ StringBuffer buff = new StringBuffer();
+ buff.append("knowledgeBuilderConfig: " + getKnowledgeBuilderConfig() +
"\n")
+ .append("knowledgeBaseConfig: " + getKnowledgeBaseConfig() +
"\n")
+ .append("Rule Resources:\n");
+ for(String rr : getRuleResources()) {
+ buff.append("\t" + rr);
+ }
+ buff.append("\nEvent Listeners: \n");
+ for(String el : getEventListeners()) {
+ buff.append("\t" + el);
+ }
+
+ return buff.toString();
+ }
public String getKnowledgeBuilderConfig()
{
Modified:
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 2010-04-02
13:38:51 UTC (rev 12372)
+++
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/KBase.java 2010-04-02
17:57:34 UTC (rev 12373)
@@ -18,5 +18,5 @@
@Inherited
public @interface KBase
{
- String name();
+ String value() default "";
}
Modified:
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 2010-04-02
13:38:51 UTC (rev 12372)
+++
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/KBaseConfig.java 2010-04-02
17:57:34 UTC (rev 12373)
@@ -18,5 +18,5 @@
@Inherited
public @interface KBaseConfig
{
- String name();
+ String value() default "";
}
Modified:
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 2010-04-02
13:38:51 UTC (rev 12372)
+++
modules/drools/trunk/core/src/test/java/org/jboss/seam/drools/kbase/KBaseTest.java 2010-04-02
17:57:34 UTC (rev 12373)
@@ -3,19 +3,24 @@
import javax.enterprise.inject.Any;
import javax.enterprise.inject.Instance;
import static org.junit.Assert.assertNotNull;
+import static org.jboss.shrinkwrap.api.formatter.Formatters.VERBOSE;
import javax.enterprise.util.AnnotationLiteral;
import javax.inject.Inject;
import junit.framework.Assert;
+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.config.KnowledgeBaseConfig;
+import org.jboss.seam.drools.qualifier.KBase;
import org.jboss.seam.drools.qualifier.KBaseConfig;
import org.jboss.shrinkwrap.api.ArchivePaths;
import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.formatter.Formatters;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.weld.extensions.resources.ResourceProvider;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -26,37 +31,50 @@
public static JavaArchive createTestArchive()
{
String pkgPath = KBaseTest.class.getPackage().getName().replaceAll("\\.",
"/");
- return Archives.create("test.jar", JavaArchive.class)
+ JavaArchive archive = Archives.create("test.jar", JavaArchive.class)
.addPackages(true, KnowledgeBaseProducer.class.getPackage())
- .addResource(pkgPath + "/kbasetest.drl")
- .addResource(pkgPath + "/kbuilderconfig.properties")
- .addResource(pkgPath + "/kbaseconfig.properties")
+ .addClass(ResourceProvider.class)
+ .addResource(pkgPath + "/kbasetest.drl",
ArchivePaths.create("kbasetest.drl"))
+ .addResource(pkgPath + "/kbuilderconfig.properties",
ArchivePaths.create("kbuilderconfig.properties"))
+ .addResource(pkgPath + "/kbaseconfig.properties",
ArchivePaths.create("kbaseconfig.properties"))
.addManifestResource("META-INF/beans.xml",
ArchivePaths.create("beans.xml"));
// the XML bean config module doesn't pick up the beans.xml unless it's
located at src/test/resources/META-INF/beans.xml
//.addManifestResource(pkgPath + "/KBaseTest-beans.xml",
ArchivePaths.create("beans.xml"));
+ System.out.println(archive.toString(VERBOSE));
+
+ return archive;
}
@Inject @Any Instance<KnowledgeBaseConfig> kbaseConfigResolver;
- @Inject @KBaseConfig(name = "kbaseconfig1") KnowledgeBaseConfig config;
+ @Inject @KBaseConfig("kbaseconfig1") KnowledgeBaseConfig config;
+ @Inject @KBase("kbase1") KnowledgeBase kbase;
+
@Test
public void testKBaseConfig() {
Assert.assertFalse(kbaseConfigResolver.select(new
KBaseConfigBinding("kbaseconfig1")).isUnsatisfied());
KnowledgeBaseConfig kbaseConfig = kbaseConfigResolver.select(new
KBaseConfigBinding("kbaseconfig1")).get();
assertNotNull(kbaseConfig);
- System.out.println("**** " + kbaseConfig.getEventListeners());
+ System.out.println("\n\n\n**** " + kbaseConfig.toString() +
"********\n\n\n");
}
+ @Test
+ public void testKBase() {
+ assertNotNull(kbase);
+ }
+
+
+
static class KBaseConfigBinding extends AnnotationLiteral<KBaseConfig>
implements KBaseConfig
{
- private String name = null;
- public KBaseConfigBinding(String name)
+ private String value = null;
+ public KBaseConfigBinding(String value)
{
- this.name = name;
+ this.value = value;
}
- public String name() {
- return name;
+ public String value() {
+ return value;
}
}
}
Deleted: modules/drools/trunk/core/src/test/resources/META-INF/beans.xml
===================================================================
--- modules/drools/trunk/core/src/test/resources/META-INF/beans.xml 2010-04-02 13:38:51
UTC (rev 12372)
+++ modules/drools/trunk/core/src/test/resources/META-INF/beans.xml 2010-04-02 17:57:34
UTC (rev 12373)
@@ -1,35 +0,0 @@
-<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:org.jboss.seam.drools.config"
- xmlns:drools-qualifier="urn:java:org.jboss.seam.drools.qualifier"
- xmlns:drools-test="urn:java:org.jboss.seam.drools.kbase">
-
- <drools:KnowledgeBaseConfig>
- <s:overrides/>
- <drools-qualifier:KBaseConfig name="kbaseconfig1" />
- <drools:knowledgeBuilderConfig>kbuilderconfig.properties</drools:knowledgeBuilderConfig>
- <drools:knowledgeBaseConfig>kbaseconfig.properties</drools:knowledgeBaseConfig>
- <drools:ruleResources>
- <s:value>classpath:kbasetest.drl:DRL</s:value>
- </drools:ruleResources>
- <drools:eventListeners>
- <s:value>org.drools.event.knowledgebase.DefaultKnowledgeBaseEventListener
- </s:value>
- </drools:eventListeners>
- </drools:KnowledgeBaseConfig>
-
- <drools:KnowledgeBaseProducer>
- <s:specializes />
- <drools:produceKBase>
- <drools-qualifier:KBase name="kbase1" />
- <s:parameters>
- <drools:KnowledgeBaseConfig>
- <s:Inject />
- <drools-qualifier:KBaseConfig name="kbaseconfig1" />
- </drools:KnowledgeBaseConfig>
- </s:parameters>
- </drools:produceKBase>
- </drools:KnowledgeBaseProducer>
-
-</beans>
\ No newline at end of file
Added: modules/drools/trunk/core/src/test/resources/META-INF/beans.xml
===================================================================
--- modules/drools/trunk/core/src/test/resources/META-INF/beans.xml
(rev 0)
+++ modules/drools/trunk/core/src/test/resources/META-INF/beans.xml 2010-04-02 17:57:34
UTC (rev 12373)
@@ -0,0 +1,38 @@
+<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:org.jboss.seam.drools.config"
+ xmlns:drools-qualifier="urn:java:org.jboss.seam.drools.qualifier"
+ xmlns:drools-test="urn:java:org.jboss.seam.drools.kbase">
+
+ <drools:KnowledgeBaseConfig>
+ <s:overrides/>
+ <drools-qualifier:KBaseConfig value="kbaseconfig1" />
+ <drools:knowledgeBuilderConfig>
+ <s:value>/kbuilderconfig.properties</s:value>
+ </drools:knowledgeBuilderConfig>
+ <drools:knowledgeBaseConfig>
+ <s:value>/kbaseconfig.properties</s:value>
+ </drools:knowledgeBaseConfig>
+ <drools:ruleResources>
+ <s:value>classpath:kbasetest.drl:DRL</s:value>
+ </drools:ruleResources>
+ <drools:eventListeners>
+ <s:value>org.drools.event.knowledgebase.DefaultKnowledgeBaseEventListener</s:value>
+ </drools:eventListeners>
+ </drools:KnowledgeBaseConfig>
+
+ <drools:KnowledgeBaseProducer>
+ <s:specializes />
+ <drools:produceKBase>
+ <drools-qualifier:KBase value="kbase1" />
+ <s:parameters>
+ <drools:KnowledgeBaseConfig>
+ <s:Inject />
+ <drools-qualifier:KBaseConfig value="kbaseconfig1" />
+ </drools:KnowledgeBaseConfig>
+ </s:parameters>
+ </drools:produceKBase>
+ </drools:KnowledgeBaseProducer>
+
+</beans>
\ No newline at end of file
Deleted:
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 2010-04-02
13:38:51 UTC (rev 12372)
+++
modules/drools/trunk/core/src/test/resources/org/jboss/seam/drools/kbase/KBaseTest-beans.xml 2010-04-02
17:57:34 UTC (rev 12373)
@@ -1,35 +0,0 @@
-<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:org.jboss.seam.drools.config"
- xmlns:drools-qualifier="urn:java:org.jboss.seam.drools.qualifier"
- xmlns:drools-test="urn:java:org.jboss.seam.drools.kbase">
-
- <drools:KnowledgeBaseConfig>
- <s:overrides/>
- <drools-qualifier:KBaseConfig name="kbaseconfig1" />
- <drools:knowledgeBuilderConfig>kbuilderconfig.properties</drools:knowledgeBuilderConfig>
- <drools:knowledgeBaseConfig>kbaseconfig.properties</drools:knowledgeBaseConfig>
- <drools:ruleResources>
- <s:value>classpath:kbasetest.drl:DRL</s:value>
- </drools:ruleResources>
- <drools:eventListeners>
- <s:value>org.drools.event.knowledgebase.DefaultKnowledgeBaseEventListener
- </s:value>
- </drools:eventListeners>
- </drools:KnowledgeBaseConfig>
-
- <drools:KnowledgeBaseProducer>
- <s:specializes />
- <drools:produceKBase>
- <drools-qualifier:KBase name="kbase1" />
- <s:parameters>
- <drools:KnowledgeBaseConfig>
- <s:Inject />
- <drools-qualifier:KBaseConfig name="kbaseconfig1" />
- </drools:KnowledgeBaseConfig>
- </s:parameters>
- </drools:produceKBase>
- </drools:KnowledgeBaseProducer>
-
-</beans>
\ No newline at end of file