[jboss-svn-commits] JBL Code SVN: r24316 - in labs/jbossrules/trunk/drools-examples/drools-examples-drl/src/main: rules/org/drools/examples and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Dec 9 03:52:10 EST 2008
Author: Rikkola
Date: 2008-12-09 03:52:09 -0500 (Tue, 09 Dec 2008)
New Revision: 24316
Modified:
labs/jbossrules/trunk/drools-examples/drools-examples-drl/src/main/java/org/drools/examples/HelloWorldExample.java
labs/jbossrules/trunk/drools-examples/drools-examples-drl/src/main/java/org/drools/examples/HonestPoliticianExample.java
labs/jbossrules/trunk/drools-examples/drools-examples-drl/src/main/java/org/drools/examples/PetStore.java
labs/jbossrules/trunk/drools-examples/drools-examples-drl/src/main/rules/org/drools/examples/HelloWorld.drl
Log:
Updated the examples and documents about examples.
Modified: labs/jbossrules/trunk/drools-examples/drools-examples-drl/src/main/java/org/drools/examples/HelloWorldExample.java
===================================================================
--- labs/jbossrules/trunk/drools-examples/drools-examples-drl/src/main/java/org/drools/examples/HelloWorldExample.java 2008-12-09 03:48:14 UTC (rev 24315)
+++ labs/jbossrules/trunk/drools-examples/drools-examples-drl/src/main/java/org/drools/examples/HelloWorldExample.java 2008-12-09 08:52:09 UTC (rev 24316)
@@ -20,85 +20,87 @@
*/
public class HelloWorldExample {
- public static final void main(final String[] args) throws Exception {
- final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+ public static final void main(final String[] args) throws Exception {
+ final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
+ .newKnowledgeBuilder();
- //this will parse and compile in one step
- kbuilder.add( ResourceFactory.newClassPathResource( "HelloWorld.drl",
- HelloWorldExample.class ),
- ResourceType.DRL );
+ // this will parse and compile in one step
+ kbuilder.add(ResourceFactory.newClassPathResource("HelloWorld.drl",
+ HelloWorldExample.class), ResourceType.DRL);
- // Check the builder for errors
- if ( kbuilder.hasErrors() ) {
- System.out.println( kbuilder.getErrors().toString() );
- throw new RuntimeException( "Unable to compile \"HelloWorld.drl\"." );
- }
+ // Check the builder for errors
+ if (kbuilder.hasErrors()) {
+ System.out.println(kbuilder.getErrors().toString());
+ throw new RuntimeException("Unable to compile \"HelloWorld.drl\".");
+ }
- //get the compiled package (which is serializable)
- final Collection<KnowledgePackage> pkgs = kbuilder.getKnowledgePackages();
+ // get the compiled packages (which are serializable)
+ final Collection<KnowledgePackage> pkgs = kbuilder
+ .getKnowledgePackages();
- //add the package to a rulebase (deploy the rule package).
- final KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
- kbase.addKnowledgePackages( pkgs );
+ // add the packages to a knowledgebase (deploy the knowledge packages).
+ final KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
+ kbase.addKnowledgePackages(pkgs);
- final StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
- ksession.setGlobal( "list",
- new ArrayList<Object>() );
+ final StatefulKnowledgeSession ksession = kbase
+ .newStatefulKnowledgeSession();
+ ksession.setGlobal("list", new ArrayList<Object>());
- // session.addEventListener( new DebugAgendaEventListener() );
- // session.addEventListener( new DebugWorkingMemoryEventListener() );
+ // ksession.addEventListener( new DebugAgendaEventListener() );
+ // ksession.addEventListener( new DebugWorkingMemoryEventListener() );
- KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "log/helloworld");
+ // setup the audit logging
+ KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory
+ .newFileLogger(ksession, "log/helloworld");
+
+ final Message message = new Message();
+ message.setMessage("Hello World");
+ message.setStatus(Message.HELLO);
+ ksession.insert(message);
- final Message message = new Message();
- message.setMessage( "Hello World" );
- message.setStatus( Message.HELLO );
- ksession.insert( message );
+ ksession.fireAllRules();
- ksession.fireAllRules();
+ logger.close();
- logger.close();
+ ksession.dispose();
+ }
- ksession.dispose();
- }
+ public static class Message {
+ public static final int HELLO = 0;
+ public static final int GOODBYE = 1;
- public static class Message {
- public static final int HELLO = 0;
- public static final int GOODBYE = 1;
+ private String message;
- private String message;
+ private int status;
- private int status;
+ public Message() {
- public Message() {
+ }
- }
+ public String getMessage() {
+ return this.message;
+ }
- public String getMessage() {
- return this.message;
- }
+ public void setMessage(final String message) {
+ this.message = message;
+ }
- public void setMessage(final String message) {
- this.message = message;
- }
+ public int getStatus() {
+ return this.status;
+ }
- public int getStatus() {
- return this.status;
- }
+ public void setStatus(final int status) {
+ this.status = status;
+ }
- public void setStatus(final int status) {
- this.status = status;
- }
+ public static Message doSomething(Message message) {
+ return message;
+ }
- public static Message doSomething(Message message) {
- return message;
- }
+ public boolean isSomething(String msg, List<Object> list) {
+ list.add(this);
+ return this.message.equals(msg);
+ }
+ }
- public boolean isSomething(String msg,
- List<Object> list) {
- list.add( this );
- return this.message.equals( msg );
- }
- }
-
}
Modified: labs/jbossrules/trunk/drools-examples/drools-examples-drl/src/main/java/org/drools/examples/HonestPoliticianExample.java
===================================================================
--- labs/jbossrules/trunk/drools-examples/drools-examples-drl/src/main/java/org/drools/examples/HonestPoliticianExample.java 2008-12-09 03:48:14 UTC (rev 24315)
+++ labs/jbossrules/trunk/drools-examples/drools-examples-drl/src/main/java/org/drools/examples/HonestPoliticianExample.java 2008-12-09 08:52:09 UTC (rev 24316)
@@ -32,16 +32,12 @@
final StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
- KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "log/honest-politician");
+ KnowledgeRuntimeLogger klogger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "log/honest-politician");
- final Politician blair = new Politician( "blair",
- true );
- final Politician bush = new Politician( "bush",
- true );
- final Politician chirac = new Politician( "chirac",
- true );
- final Politician schroder = new Politician( "schroder",
- true );
+ final Politician blair = new Politician( "blair", true );
+ final Politician bush = new Politician( "bush", true );
+ final Politician chirac = new Politician( "chirac", true );
+ final Politician schroder = new Politician( "schroder", true );
ksession.insert( blair );
ksession.insert( bush );
@@ -50,7 +46,7 @@
ksession.fireAllRules();
- logger.close();
+ klogger.close();
ksession.dispose();
}
Modified: labs/jbossrules/trunk/drools-examples/drools-examples-drl/src/main/java/org/drools/examples/PetStore.java
===================================================================
--- labs/jbossrules/trunk/drools-examples/drools-examples-drl/src/main/java/org/drools/examples/PetStore.java 2008-12-09 03:48:14 UTC (rev 24315)
+++ labs/jbossrules/trunk/drools-examples/drools-examples-drl/src/main/java/org/drools/examples/PetStore.java 2008-12-09 08:52:09 UTC (rev 24316)
@@ -48,7 +48,6 @@
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
//RuleB
-
Vector<Product> stock = new Vector<Product>();
stock.add( new Product( "Gold Fish",
5 ) );
Modified: labs/jbossrules/trunk/drools-examples/drools-examples-drl/src/main/rules/org/drools/examples/HelloWorld.drl
===================================================================
--- labs/jbossrules/trunk/drools-examples/drools-examples-drl/src/main/rules/org/drools/examples/HelloWorld.drl 2008-12-09 03:48:14 UTC (rev 24315)
+++ labs/jbossrules/trunk/drools-examples/drools-examples-drl/src/main/rules/org/drools/examples/HelloWorld.drl 2008-12-09 08:52:09 UTC (rev 24316)
@@ -11,8 +11,7 @@
then
System.out.println( message );
modify ( m ) { message = "Goodbyte cruel world",
- status = Message.GOODBYE };
- System.out.println( message );
+ status = Message.GOODBYE };
end
rule "Good Bye"
More information about the jboss-svn-commits
mailing list