[jboss-svn-commits] JBL Code SVN: r13123 - in labs/jbossrules/trunk/drools-jsr94: src/main/java/org/drools/jsr94/rules and 6 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Jul 5 18:36:43 EDT 2007
Author: mark.proctor at jboss.com
Date: 2007-07-05 18:36:43 -0400 (Thu, 05 Jul 2007)
New Revision: 13123
Added:
labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/decisiontable/
labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/decisiontable/Cheese.java
labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/decisiontable/Person.java
labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/decisiontable/SpreadsheetIntegrationTest.java
labs/jbossrules/trunk/drools-jsr94/src/test/resources/org/drools/decisiontable/
labs/jbossrules/trunk/drools-jsr94/src/test/resources/org/drools/decisiontable/IntegrationExampleTest.xls
Modified:
labs/jbossrules/trunk/drools-jsr94/.classpath
labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/Constants.java
labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/admin/LocalRuleExecutionSetProviderImpl.java
labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/admin/RuleExecutionSetImpl.java
labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/jsr94/rules/ExampleRuleEngineFacade.java
Log:
JBRULES-446 Support rulebase configuration via jsr94 registerRuleExecutionSet properties
Modified: labs/jbossrules/trunk/drools-jsr94/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/.classpath 2007-07-05 22:12:15 UTC (rev 13122)
+++ labs/jbossrules/trunk/drools-jsr94/.classpath 2007-07-05 22:36:43 UTC (rev 13123)
@@ -1,22 +1,24 @@
-<classpath>
- <classpathentry kind="src" path="src/main/java"/>
- <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
- <classpathentry kind="src" path="src/test/java" output="target/test-classes"/>
- <classpathentry kind="src" path="src/test/resources" output="target/test-classes" excluding="**/*.java"/>
- <classpathentry kind="output" path="target/classes"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="var" path="M2_REPO/xpp3/xpp3/1.1.3.4.O/xpp3-1.1.3.4.O.jar"/>
- <classpathentry kind="src" path="/drools-core"/>
- <classpathentry kind="src" path="/drools-compiler"/>
- <classpathentry kind="var" path="M2_REPO/xerces/xercesImpl/2.4.0/xercesImpl-2.4.0.jar"/>
- <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2beta27/mvel14-1.2beta27.jar"/>
- <classpathentry kind="var" path="M2_REPO/jsr94/jsr94/1.1/jsr94-1.1.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/eclipse/jdt/core/3.2.3.v_686_R32x/core-3.2.3.v_686_R32x.jar"/>
- <classpathentry kind="var" path="M2_REPO/janino/janino/2.5.7/janino-2.5.7.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/antlr/antlr-runtime/3.0/antlr-runtime-3.0.jar"/>
- <classpathentry kind="var" path="M2_REPO/jsr94/jsr94-sigtest/1.1/jsr94-sigtest-1.1.jar"/>
- <classpathentry kind="var" path="M2_REPO/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar"/>
- <classpathentry kind="var" path="M2_REPO/xstream/xstream/1.1.3/xstream-1.1.3.jar"/>
- <classpathentry kind="var" path="M2_REPO/jsr94/jsr94-tck/1.0.3/jsr94-tck-1.0.3.jar"/>
-</classpath>
\ No newline at end of file
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry excluding="**/*.java" kind="src" path="src/main/resources"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+ <classpathentry excluding="**/*.java" kind="src" output="target/test-classes" path="src/test/resources"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="var" path="M2_REPO/xpp3/xpp3/1.1.3.4.O/xpp3-1.1.3.4.O.jar"/>
+ <classpathentry kind="src" path="/drools-core"/>
+ <classpathentry kind="src" path="/drools-compiler"/>
+ <classpathentry kind="var" path="M2_REPO/xerces/xercesImpl/2.4.0/xercesImpl-2.4.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2beta27/mvel14-1.2beta27.jar"/>
+ <classpathentry kind="var" path="M2_REPO/jsr94/jsr94/1.1/jsr94-1.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/eclipse/jdt/core/3.2.3.v_686_R32x/core-3.2.3.v_686_R32x.jar"/>
+ <classpathentry kind="var" path="M2_REPO/janino/janino/2.5.7/janino-2.5.7.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/antlr/antlr-runtime/3.0/antlr-runtime-3.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/jsr94/jsr94-sigtest/1.1/jsr94-sigtest-1.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/xstream/xstream/1.1.3/xstream-1.1.3.jar"/>
+ <classpathentry kind="var" path="M2_REPO/jsr94/jsr94-tck/1.0.3/jsr94-tck-1.0.3.jar"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/drools-decisiontables"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Modified: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/Constants.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/Constants.java 2007-07-05 22:12:15 UTC (rev 13122)
+++ labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/Constants.java 2007-07-05 22:36:43 UTC (rev 13123)
@@ -37,4 +37,18 @@
/** <code>RuleExecutionSet</code> description constant. */
public static final String RES_DESCRIPTION = "javax.rules.admin.RuleExecutionSet.description";
+
+ public static final String RES_SOURCE = "javax.rules.admin.RuleExecutionSet.source";
+
+ public static final String RES_SOURCE_TYPE_XML = "javax.rules.admin.RuleExecutionSet.source.xml";
+
+ public static final String RES_SOURCE_TYPE_DECISION_TABLE = "javax.rules.admin.RuleExecutionSet.source.decisiontable";
+
+ public static final String RES_DSRL = "javax.rules.admin.RuleExecutionSet.dsrl";
+
+ /** <code>RuleExecutionSet</code> rulebase config constant. */
+ public static final String RES_RULEBASE_CONFIG = "javax.rules.admin.RuleExecutionSet.ruleBaseConfiguration";
+
+ /** <code>RuleExecutionSet</code> package builder config constant. */
+ public static final String RES_PACKAGEBUILDER_CONFIG = "javax.rules.admin.RuleExecutionSet.ruleBaseConfiguration";
}
Modified: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/admin/LocalRuleExecutionSetProviderImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/admin/LocalRuleExecutionSetProviderImpl.java 2007-07-05 22:12:15 UTC (rev 13122)
+++ labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/admin/LocalRuleExecutionSetProviderImpl.java 2007-07-05 22:36:43 UTC (rev 13123)
@@ -30,6 +30,10 @@
import org.drools.IntegrationException;
import org.drools.compiler.DroolsParserException;
import org.drools.compiler.PackageBuilder;
+import org.drools.compiler.PackageBuilderConfiguration;
+import org.drools.decisiontable.InputType;
+import org.drools.decisiontable.SpreadsheetCompiler;
+import org.drools.jsr94.rules.Constants;
import org.drools.rule.Package;
/**
@@ -73,8 +77,23 @@
* @return The created <code>RuleExecutionSet</code>.
*/
public RuleExecutionSet createRuleExecutionSet(final InputStream ruleExecutionSetStream,
- final Map properties) throws RuleExecutionSetCreateException {
- return createRuleExecutionSet( new InputStreamReader( ruleExecutionSetStream ), properties);
+ final Map properties) throws RuleExecutionSetCreateException {
+ if ( properties != null ) {
+ String source = ( String ) properties.get( Constants.RES_SOURCE );
+ if ( source == null ) {
+ // support legacy name
+ source = ( String ) properties.get( "source" );
+ }
+ if ( source != null && source.equals( Constants.RES_SOURCE_TYPE_DECISION_TABLE ) ) {
+ final SpreadsheetCompiler converter = new SpreadsheetCompiler();
+ final String drl = converter.compile( ruleExecutionSetStream,
+ InputType.XLS );
+ return createRuleExecutionSet( new StringReader( drl ), properties );
+ } else {
+ return createRuleExecutionSet( new InputStreamReader( ruleExecutionSetStream ), properties);
+ }
+ } else
+ return createRuleExecutionSet( new InputStreamReader( ruleExecutionSetStream ), properties);
}
@@ -99,37 +118,56 @@
public RuleExecutionSet createRuleExecutionSet(final Reader ruleExecutionSetReader,
final Map properties) throws RuleExecutionSetCreateException {
try {
- final PackageBuilder builder = new PackageBuilder();
- Object dsl = null;
+ PackageBuilderConfiguration config= null;
+
+ if ( properties != null ) {
+ config = (PackageBuilderConfiguration) properties.get( Constants.RES_PACKAGEBUILDER_CONFIG );
+ }
+
+ PackageBuilder builder = null;
+ if ( config != null ) {
+ builder = new PackageBuilder(config);
+ } else {
+ builder = new PackageBuilder();
+ }
+
+ Object dsrl = null;
String source = null;
if ( properties != null ) {
- dsl = properties.get( "dsl" );
- source = ( String ) properties.get( "source" );
+ dsrl = properties.get( Constants.RES_DSRL );
+ if ( dsrl == null ) {
+ // check for old legacy name ending
+ dsrl = properties.get( "dsl" );
+ }
+ source = ( String ) properties.get( Constants.RES_SOURCE );
+ if ( source == null ) {
+ // check for old legacy name ending
+ source = ( String ) properties.get( "source" );
+ }
}
if ( source == null ) {
source = "drl";
- }
+ }
-
- if ( dsl == null ) {
- if ( source.equals( "xml" ) ) {
+ if ( dsrl == null ) {
+ if ( source.equals( Constants.RES_SOURCE_TYPE_XML ) || source.equals( "xml" ) ) {
builder.addPackageFromXml( ruleExecutionSetReader );
} else {
builder.addPackageFromDrl( ruleExecutionSetReader );
}
} else {
- if ( source.equals( "xml" ) ) {
+ if ( source.equals( Constants.RES_SOURCE_TYPE_XML ) || source.equals( "xml" ) ) {
// xml cannot specify a dsl
builder.addPackageFromXml( ruleExecutionSetReader );
} else {
- if ( dsl instanceof Reader ) {
+ if ( dsrl instanceof Reader ) {
builder.addPackageFromDrl( ruleExecutionSetReader,
- (Reader) dsl );
+ (Reader) dsrl );
} else {
builder.addPackageFromDrl( ruleExecutionSetReader,
- new StringReader( (String) dsl ) );
+ new StringReader( (String) dsrl ) );
}
}
}
Modified: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/admin/RuleExecutionSetImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/admin/RuleExecutionSetImpl.java 2007-07-05 22:12:15 UTC (rev 13122)
+++ labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/admin/RuleExecutionSetImpl.java 2007-07-05 22:36:43 UTC (rev 13123)
@@ -26,9 +26,11 @@
import org.drools.IntegrationException;
import org.drools.RuleBase;
+import org.drools.RuleBaseConfiguration;
import org.drools.RuleIntegrationException;
import org.drools.StatefulSession;
import org.drools.StatelessSession;
+import org.drools.jsr94.rules.Constants;
import org.drools.jsr94.rules.Jsr94FactHandleFactory;
import org.drools.rule.Package;
import org.drools.rule.Rule;
@@ -114,9 +116,17 @@
}
this.pkg = pkg;
this.description = pkg.getName();//..getDocumentation( );
-
- final org.drools.reteoo.ReteooRuleBase ruleBase = new org.drools.reteoo.ReteooRuleBase( UUIDGenerator.getInstance().generateRandomBasedUUID().toString(),
- new Jsr94FactHandleFactory() );
+
+ RuleBaseConfiguration config = ( RuleBaseConfiguration ) this.properties.get( Constants.RES_RULEBASE_CONFIG );
+ org.drools.reteoo.ReteooRuleBase ruleBase;
+ if ( config != null ) {
+ ruleBase = new org.drools.reteoo.ReteooRuleBase( UUIDGenerator.getInstance().generateRandomBasedUUID().toString(),
+ config,
+ new Jsr94FactHandleFactory() );
+ } else {
+ ruleBase = new org.drools.reteoo.ReteooRuleBase( UUIDGenerator.getInstance().generateRandomBasedUUID().toString(),
+ new Jsr94FactHandleFactory() );
+ }
ruleBase.addPackage( pkg );
this.ruleBase = ruleBase;
Added: labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/decisiontable/Cheese.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/decisiontable/Cheese.java (rev 0)
+++ labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/decisiontable/Cheese.java 2007-07-05 22:36:43 UTC (rev 13123)
@@ -0,0 +1,45 @@
+package org.drools.decisiontable;
+
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class Cheese {
+ private String type;
+ private int price;
+
+ public Cheese() {
+
+ }
+ public Cheese(final String type,
+ final int price) {
+ super();
+ this.type = type;
+ this.price = price;
+ }
+
+ public int getPrice() {
+ return this.price;
+ }
+
+ public String getType() {
+ return this.type;
+ }
+
+ public void setPrice(final int price) {
+ this.price = price;
+ }
+
+}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/decisiontable/Person.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/decisiontable/Person.java (rev 0)
+++ labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/decisiontable/Person.java 2007-07-05 22:36:43 UTC (rev 13123)
@@ -0,0 +1,93 @@
+package org.drools.decisiontable;
+
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class Person {
+ private String name;
+ private String likes;
+ private int age;
+
+ private char sex;
+
+ private boolean alive;
+
+ private String status;
+
+ public Person() {
+
+ }
+ public Person(final String name) {
+ this( name,
+ "",
+ 0 );
+ }
+
+ public Person(final String name,
+ final String likes) {
+ this( name,
+ likes,
+ 0 );
+ }
+
+ public Person(final String name,
+ final String likes,
+ final int age) {
+ this.name = name;
+ this.likes = likes;
+ this.age = age;
+ }
+
+ public String getStatus() {
+ return this.status;
+ }
+
+ public void setStatus(final String status) {
+ this.status = status;
+ }
+
+ public String getLikes() {
+ return this.likes;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public int getAge() {
+ return this.age;
+ }
+
+ public boolean isAlive() {
+ return this.alive;
+ }
+
+ public void setAlive(final boolean alive) {
+ this.alive = alive;
+ }
+
+ public char getSex() {
+ return this.sex;
+ }
+
+ public void setSex(final char sex) {
+ this.sex = sex;
+ }
+
+ public String toString() {
+ return "[Person name='" + this.name + "']";
+ }
+}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/decisiontable/SpreadsheetIntegrationTest.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/decisiontable/SpreadsheetIntegrationTest.java (rev 0)
+++ labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/decisiontable/SpreadsheetIntegrationTest.java 2007-07-05 22:36:43 UTC (rev 13123)
@@ -0,0 +1,91 @@
+package org.drools.decisiontable;
+
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.rules.RuleRuntime;
+import javax.rules.RuleServiceProvider;
+import javax.rules.RuleServiceProviderManager;
+import javax.rules.RuleSession;
+import javax.rules.StatefulRuleSession;
+import javax.rules.admin.LocalRuleExecutionSetProvider;
+import javax.rules.admin.RuleAdministrator;
+import javax.rules.admin.RuleExecutionSet;
+
+import junit.framework.TestCase;
+
+import org.acme.insurance.launcher.PricingRuleLauncher;
+import org.drools.RuleBase;
+import org.drools.RuleBaseFactory;
+import org.drools.WorkingMemory;
+import org.drools.compiler.PackageBuilder;
+import org.drools.jsr94.rules.Constants;
+import org.drools.jsr94.rules.ExampleRuleEngineFacade;
+import org.drools.jsr94.rules.RuleEngineTestBase;
+import org.drools.jsr94.rules.RuleServiceProviderImpl;
+import org.drools.rule.Package;
+
+public class SpreadsheetIntegrationTest extends TestCase {
+
+ public void testExecute() throws Exception {
+ Map properties = new HashMap();
+ properties.put( Constants.RES_SOURCE,
+ Constants.RES_SOURCE_TYPE_DECISION_TABLE );
+
+ RuleServiceProviderManager.registerRuleServiceProvider( ExampleRuleEngineFacade.RULE_SERVICE_PROVIDER,
+ RuleServiceProviderImpl.class );
+
+ RuleServiceProvider ruleServiceProvider = RuleServiceProviderManager.getRuleServiceProvider( ExampleRuleEngineFacade.RULE_SERVICE_PROVIDER );
+ RuleAdministrator ruleAdministrator = ruleServiceProvider.getRuleAdministrator();
+ LocalRuleExecutionSetProvider ruleSetProvider = ruleAdministrator.getLocalRuleExecutionSetProvider( null );
+
+ RuleExecutionSet ruleExecutionSet = ruleSetProvider.createRuleExecutionSet( SpreadsheetIntegrationTest.class.getResourceAsStream( "IntegrationExampleTest.xls" ),
+ properties );
+
+ ruleAdministrator.registerRuleExecutionSet( "IntegrationExampleTest.xls",
+ ruleExecutionSet,
+ properties );
+
+ properties.clear();
+ final List list = new ArrayList();
+ properties.put( "list",
+ list );
+
+ RuleRuntime ruleRuntime = ruleServiceProvider.getRuleRuntime();
+ StatefulRuleSession session = (StatefulRuleSession) ruleRuntime.createRuleSession( "IntegrationExampleTest.xls",
+ properties,
+ RuleRuntime.STATEFUL_SESSION_TYPE );
+
+ //ASSERT AND FIRE
+ session.addObject( new Cheese( "stilton",
+ 42 ) );
+ session.addObject( new Person( "michael",
+ "stilton",
+ 42 ) );
+
+ session.executeRules();
+ assertEquals( 1,
+ list.size() );
+
+ }
+
+}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/jsr94/rules/ExampleRuleEngineFacade.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/jsr94/rules/ExampleRuleEngineFacade.java 2007-07-05 22:12:15 UTC (rev 13122)
+++ labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/jsr94/rules/ExampleRuleEngineFacade.java 2007-07-05 22:36:43 UTC (rev 13123)
@@ -86,7 +86,7 @@
this.ruleAdministrator = this.ruleServiceProvider.getRuleAdministrator();
this.ruleSetProvider = this.ruleAdministrator.getLocalRuleExecutionSetProvider( null );
- }
+ }
public void addRuleExecutionSet(final String bindUri,
final InputStream resourceAsStream) throws Exception {
Added: labs/jbossrules/trunk/drools-jsr94/src/test/resources/org/drools/decisiontable/IntegrationExampleTest.xls
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/trunk/drools-jsr94/src/test/resources/org/drools/decisiontable/IntegrationExampleTest.xls
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
More information about the jboss-svn-commits
mailing list