[seam-commits] Seam SVN: r10647 - in modules/trunk/drools: src/main/java/org/jboss/seam/drools and 1 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Mon Apr 27 05:01:39 EDT 2009
Author: shane.bryzak at jboss.com
Date: 2009-04-27 05:01:39 -0400 (Mon, 27 Apr 2009)
New Revision: 10647
Added:
modules/trunk/drools/src/main/java/org/jboss/seam/drools/util/
modules/trunk/drools/src/main/java/org/jboss/seam/drools/util/Resources.java
Modified:
modules/trunk/drools/pom.xml
modules/trunk/drools/src/main/java/org/jboss/seam/drools/DroolsHandler.java
modules/trunk/drools/src/main/java/org/jboss/seam/drools/ManagedWorkingMemory.java
modules/trunk/drools/src/main/java/org/jboss/seam/drools/RuleAgent.java
modules/trunk/drools/src/main/java/org/jboss/seam/drools/RuleBase.java
Log:
added util classes, add dependencies, component conversion
Modified: modules/trunk/drools/pom.xml
===================================================================
--- modules/trunk/drools/pom.xml 2009-04-27 09:00:42 UTC (rev 10646)
+++ modules/trunk/drools/pom.xml 2009-04-27 09:01:39 UTC (rev 10647)
@@ -24,10 +24,27 @@
<artifactId>webbeans-logging</artifactId>
</dependency>
<dependency>
+ <groupId>org.jboss.seam</groupId>
+ <artifactId>seam-bpm</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.seam</groupId>
+ <artifactId>seam-el</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.drools</groupId>
+ <artifactId>drools-compiler</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jbpm</groupId>
+ <artifactId>jbpm-jpdl</artifactId>
+ </dependency>
+
</dependencies>
</project>
Modified: modules/trunk/drools/src/main/java/org/jboss/seam/drools/DroolsHandler.java
===================================================================
--- modules/trunk/drools/src/main/java/org/jboss/seam/drools/DroolsHandler.java 2009-04-27 09:00:42 UTC (rev 10646)
+++ modules/trunk/drools/src/main/java/org/jboss/seam/drools/DroolsHandler.java 2009-04-27 09:01:39 UTC (rev 10647)
@@ -27,7 +27,7 @@
for (String objectName: expressions)
{
Object object = Expressions.instance().createValueExpression(objectName).getValue();
- //Object object = new SeamVariableResolver().resolveVariable(objectName);
+
// assert the object into the rules engine
if (object instanceof Iterable)
{
@@ -42,7 +42,6 @@
}
}
- //workingMemory.setGlobal( "contextInstance", executionContext.getContextInstance() );
workingMemory.insert(Actor.instance());
return workingMemory;
Modified: modules/trunk/drools/src/main/java/org/jboss/seam/drools/ManagedWorkingMemory.java
===================================================================
--- modules/trunk/drools/src/main/java/org/jboss/seam/drools/ManagedWorkingMemory.java 2009-04-27 09:00:42 UTC (rev 10646)
+++ modules/trunk/drools/src/main/java/org/jboss/seam/drools/ManagedWorkingMemory.java 2009-04-27 09:01:39 UTC (rev 10647)
@@ -2,17 +2,17 @@
import java.io.Serializable;
+import javax.annotation.PreDestroy;
+import javax.context.ConversationScoped;
+import javax.inject.Current;
+import javax.inject.Produces;
+import javax.inject.manager.Manager;
+
import org.drools.RuleBase;
import org.drools.StatefulSession;
import org.drools.spi.GlobalResolver;
-import org.jboss.seam.Component;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Destroy;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.Unwrap;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.jboss.seam.core.Mutable;
-import org.jboss.seam.core.Expressions.ValueExpression;
+import org.jboss.seam.el.Expressions.ValueExpression;
/**
* A conversation-scoped Drools WorkingMemory for a named RuleBase
@@ -20,8 +20,7 @@
* @author Gavin King
*
*/
- at Scope(ScopeType.CONVERSATION)
- at BypassInterceptors
+ at ConversationScoped
public class ManagedWorkingMemory implements Mutable, Serializable
{
private static final long serialVersionUID = -1746942080571374743L;
@@ -30,6 +29,8 @@
private StatefulSession statefulSession;
private ValueExpression<RuleBase> ruleBase;
+ @Current Manager manager;
+
public boolean clearDirty()
{
return true;
@@ -59,7 +60,7 @@
this.ruleBaseName = ruleBaseName;
}
- @Unwrap
+ @Produces
public StatefulSession getStatefulSession()
{
if (statefulSession==null)
@@ -79,8 +80,8 @@
}
else if (ruleBaseName!=null)
{
- //deprecated stuff
- ruleBase = (RuleBase) Component.getInstance(ruleBaseName, true);
+ //deprecated stuff
+ ruleBase = (RuleBase) manager.getInstanceByName(ruleBaseName);
}
else
{
@@ -99,7 +100,7 @@
return new SeamGlobalResolver(delegate);
}
- @Destroy
+ @PreDestroy
public void destroy()
{
statefulSession.dispose();
Modified: modules/trunk/drools/src/main/java/org/jboss/seam/drools/RuleAgent.java
===================================================================
--- modules/trunk/drools/src/main/java/org/jboss/seam/drools/RuleAgent.java 2009-04-27 09:00:42 UTC (rev 10646)
+++ modules/trunk/drools/src/main/java/org/jboss/seam/drools/RuleAgent.java 2009-04-27 09:01:39 UTC (rev 10647)
@@ -4,20 +4,18 @@
import java.io.InputStream;
import java.util.Properties;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Create;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.Unwrap;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
-import org.jboss.seam.log.LogProvider;
-import org.jboss.seam.log.Logging;
-import org.jboss.seam.util.Resources;
+import javax.context.ApplicationScoped;
+import javax.inject.Initializer;
+import javax.inject.Produces;
+import org.jboss.seam.drools.util.Resources;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
+
/**
* Manager component for a rule base loaded from a drools RulesAgent
*/
- at Scope(ScopeType.APPLICATION)
- at BypassInterceptors
+ at ApplicationScoped
public class RuleAgent
{
private static final LogProvider log = Logging.getLogProvider(RuleAgent.class);
@@ -32,7 +30,7 @@
private String poll;
private String configName;
- @Create
+ @Initializer
public void createAgent() throws Exception
{
Properties properties = new Properties();
@@ -71,7 +69,7 @@
throws IOException
{
if (configurationFile != null) {
- InputStream inputStream = Resources.getResourceAsStream(configurationFile, null);
+ InputStream inputStream = Resources.getResourceAsStream(configurationFile);
if (inputStream != null) {
try {
properties.load(inputStream);
@@ -82,7 +80,7 @@
}
}
- @Unwrap
+ @Produces
public org.drools.RuleBase getRuleBase()
{
return agent.getRuleBase();
Modified: modules/trunk/drools/src/main/java/org/jboss/seam/drools/RuleBase.java
===================================================================
--- modules/trunk/drools/src/main/java/org/jboss/seam/drools/RuleBase.java 2009-04-27 09:00:42 UTC (rev 10646)
+++ modules/trunk/drools/src/main/java/org/jboss/seam/drools/RuleBase.java 2009-04-27 09:01:39 UTC (rev 10647)
@@ -4,19 +4,18 @@
import java.io.InputStreamReader;
import java.io.Reader;
+import javax.context.ApplicationScoped;
+import javax.inject.Initializer;
+import javax.inject.Produces;
+
import org.drools.RuleBaseFactory;
import org.drools.compiler.DroolsError;
import org.drools.compiler.PackageBuilder;
import org.drools.compiler.PackageBuilderConfiguration;
import org.drools.compiler.RuleError;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Create;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.Unwrap;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.jboss.seam.core.ResourceLoader;
-import org.jboss.seam.log.LogProvider;
-import org.jboss.seam.log.Logging;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
/**
* Manager component for a Drools RuleBase
@@ -24,8 +23,7 @@
* @author Gavin King
*
*/
- at Scope(ScopeType.APPLICATION)
- at BypassInterceptors
+ at ApplicationScoped
public class RuleBase
{
private static final LogProvider log = Logging.getLogProvider(RuleBase.class);
@@ -34,7 +32,7 @@
private String dslFile;
private org.drools.RuleBase ruleBase;
- @Create
+ @Initializer
public void compileRuleBase() throws Exception
{
PackageBuilderConfiguration conf = new PackageBuilderConfiguration();
@@ -87,7 +85,7 @@
ruleBase.addPackage( builder.getPackage() );
}
- @Unwrap
+ @Produces
public org.drools.RuleBase getRuleBase()
{
return ruleBase;
Added: modules/trunk/drools/src/main/java/org/jboss/seam/drools/util/Resources.java
===================================================================
--- modules/trunk/drools/src/main/java/org/jboss/seam/drools/util/Resources.java (rev 0)
+++ modules/trunk/drools/src/main/java/org/jboss/seam/drools/util/Resources.java 2009-04-27 09:01:39 UTC (rev 10647)
@@ -0,0 +1,123 @@
+package org.jboss.seam.drools.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
+
+public class Resources
+{
+ private static final LogProvider log = Logging.getLogProvider(Resources.class);
+
+ public static InputStream getResourceAsStream(String resource)
+ {
+ String stripped = resource.startsWith("/") ? resource.substring(1) : resource;
+
+ InputStream stream = getResourceAsStream(resource, stripped);
+ return stream;
+ }
+
+ public static URL getResource(String resource)
+ {
+ if (!resource.startsWith("/"))
+ {
+ resource = "/" + resource;
+ }
+
+ String stripped = resource.startsWith("/") ? resource.substring(1)
+ : resource;
+
+ URL url = getResource(resource, stripped);
+
+ return url;
+ }
+
+ static InputStream getResourceAsStream(String resource, String stripped)
+ {
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ InputStream stream = null;
+ if (classLoader != null)
+ {
+ stream = classLoader.getResourceAsStream(stripped);
+ if (stream != null)
+ {
+ log.debug("Loaded resource from context classloader: " + stripped);
+ }
+ }
+
+ if (stream == null)
+ {
+ stream = Resources.class.getResourceAsStream(resource);
+ if (stream != null)
+ {
+ log.debug("Loaded resource from Seam classloader: " + resource);
+ }
+ }
+
+ if (stream == null)
+ {
+ stream = Resources.class.getClassLoader()
+ .getResourceAsStream(stripped);
+ if (stream != null)
+ {
+ log.debug("Loaded resource from Seam classloader: " + stripped);
+ }
+ }
+
+ return stream;
+ }
+
+ static URL getResource(String resource, String stripped)
+ {
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ URL url = null;
+ if (classLoader != null)
+ {
+ url = classLoader.getResource(stripped);
+ if (url != null)
+ {
+ log.debug("Loaded resource from context classloader: " + url);
+ }
+ }
+
+ if (url == null)
+ {
+ url = Resources.class.getResource(resource);
+ if (url != null)
+ {
+ log.debug("Loaded resource from Seam classloader: " + url);
+ }
+ }
+
+ if (url == null)
+ {
+ url = Resources.class.getClassLoader().getResource(stripped);
+ if (url != null)
+ {
+ log.debug("Loaded resource from Seam classloader: " + url);
+ }
+ }
+
+ return url;
+ }
+
+ public static void closeStream(InputStream inputStream)
+ {
+ if (inputStream == null)
+ {
+ return;
+ }
+
+ try
+ {
+ inputStream.close();
+ }
+ catch (IOException e)
+ {
+ //
+ }
+ }
+
+}
\ No newline at end of file
More information about the seam-commits
mailing list