[jboss-svn-commits] JBL Code SVN: r6137 - in labs/jbossrules/trunk/drools-decisiontables/src: main/java/org/drools/decisiontable/parser test/java/org/drools/decisiontable/parser

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Sep 11 05:58:51 EDT 2006


Author: michael.neale at jboss.com
Date: 2006-09-11 05:58:46 -0400 (Mon, 11 Sep 2006)
New Revision: 6137

Added:
   labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/ActionTypeTest.java
Modified:
   labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/ActionType.java
Log:
JBRULES-482 - fix for activation group handling

Modified: labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/ActionType.java
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/ActionType.java	2006-09-11 09:49:38 UTC (rev 6136)
+++ labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/ActionType.java	2006-09-11 09:58:46 UTC (rev 6137)
@@ -56,14 +56,13 @@
 
     int                     type;
 
-    private SourceBuilder sourceBuilder = null;
+    private SourceBuilder   sourceBuilder   = null;
 
-//    private String                  value;
+    //    private String                  value;
 
     ActionType(final int actionType) {
         this.type = actionType;
     }
-        
 
     /**
      * This is only set for LHS or RHS building. 
@@ -71,15 +70,15 @@
     public void setSourceBuilder(SourceBuilder src) {
         this.sourceBuilder = src;
     }
-    
+
     public SourceBuilder getSourceBuilder() {
         return this.sourceBuilder;
     }
 
-//    String getSnippet(final String cellValue) {
-//        final SnippetBuilder builder = new SnippetBuilder( this.value );
-//        return builder.build( cellValue );
-//    }
+    //    String getSnippet(final String cellValue) {
+    //        final SnippetBuilder builder = new SnippetBuilder( this.value );
+    //        return builder.build( cellValue );
+    //    }
 
     /**
      * Create a new action type that matches this cell, and add it to the map,
@@ -89,12 +88,30 @@
                                         final String value,
                                         final int column,
                                         final int row) {
-        if ( value.toUpperCase().startsWith( "C" ) ) {
+        if ( value.toUpperCase().startsWith( "U" ) || value.toUpperCase().equals( "NO-LOOP" ) ) // if the title cell
+        // value starts with
+        // "U" then put a
+        // ActionType.NOLOOP
+        // to the _actions  
+        // list
+        {
             actionTypeMap.put( new Integer( column ),
-                               new ActionType( ActionType.CONDITION) );
+                               new ActionType( ActionType.NOLOOP ) );
+        } else if ( value.toUpperCase().startsWith( "X" ) || value.toUpperCase().equals( "ACTIVATION-GROUP" ) ) // if the title cell
+        // value starts with
+        // "X" then put a
+        // ActionType.XORGROUP
+        // to the _actions  
+        // list
+        {
+            actionTypeMap.put( new Integer( column ),
+                               new ActionType( ActionType.ACTIVATIONGROUP ) );
+        } else if ( value.toUpperCase().startsWith( "C" ) ) {
+            actionTypeMap.put( new Integer( column ),
+                               new ActionType( ActionType.CONDITION ) );
         } else if ( value.toUpperCase().startsWith( "A" ) ) {
             actionTypeMap.put( new Integer( column ),
-                               new ActionType( ActionType.ACTION) );
+                               new ActionType( ActionType.ACTION ) );
         } else if ( value.toUpperCase().startsWith( "P" ) ) // if the title cell
         // value starts with
         // "P" then put a
@@ -131,24 +148,6 @@
         {
             actionTypeMap.put( new Integer( column ),
                                new ActionType( ActionType.DESCRIPTION ) );
-        } else if ( value.toUpperCase().startsWith( "U" ) || value.toUpperCase().equals( "NO-LOOP" ) ) // if the title cell
-        // value starts with
-        // "U" then put a
-        // ActionType.NOLOOP
-        // to the _actions	
-        // list
-        {
-            actionTypeMap.put( new Integer( column ),
-                               new ActionType( ActionType.NOLOOP ) );
-        } else if ( value.toUpperCase().startsWith( "X" ) || value.toUpperCase().equals( "ACTIVATION-GROUP" ) ) // if the title cell
-        // value starts with
-        // "X" then put a
-        // ActionType.XORGROUP
-        // to the _actions	
-        // list
-        {
-            actionTypeMap.put( new Integer( column ),
-                               new ActionType( ActionType.ACTIVATIONGROUP ) );
         } else {
             throw new DecisionTableParseException( "Invalid column header (ACTION type), " + "should be CONDITION or ACTION (etc..) row number:" + (row + 1) + " cell number:" + (column + 1) + " - does not contain a leading C or A identifer." );
         }
@@ -157,17 +156,20 @@
     /**
      * This is where a code snippet template is added.
      */
-    public void addTemplate(int col, String content) {
-        this.sourceBuilder.addTemplate(  col, content );        
+    public void addTemplate(int col,
+                            String content) {
+        this.sourceBuilder.addTemplate( col,
+                                        content );
     }
-    
+
     /**
      * Values are added to populate the template.
      * The source builder contained needs to be "cleared" when the resultant snippet is extracted.
      */
-    public void addCellValue(int col, String content) {
-        this.sourceBuilder.addCellValue( col, content );
+    public void addCellValue(int col,
+                             String content) {
+        this.sourceBuilder.addCellValue( col,
+                                         content );
     }
-    
 
 }
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/ActionTypeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/ActionTypeTest.java	2006-09-11 09:49:38 UTC (rev 6136)
+++ labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/ActionTypeTest.java	2006-09-11 09:58:46 UTC (rev 6137)
@@ -0,0 +1,45 @@
+package org.drools.decisiontable.parser;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.drools.decisiontable.parser.ActionType;
+
+public class ActionTypeTest extends TestCase {
+
+    public void testChooseActionType() {
+        Map actionTypeMap = new HashMap();
+        ActionType.addNewActionType( actionTypeMap, "C", 0, 1 );
+        
+        ActionType type = (ActionType) actionTypeMap.get( new Integer(0) );
+        assertEquals(ActionType.CONDITION, type.type);
+        
+        
+        actionTypeMap = new HashMap();
+        ActionType.addNewActionType( actionTypeMap, "A", 0, 1 );
+        type = (ActionType) actionTypeMap.get( new Integer(0) );
+        assertEquals(ActionType.ACTION, type.type);
+        
+        actionTypeMap = new HashMap();
+        ActionType.addNewActionType( actionTypeMap, "X", 0, 1 );
+        type = (ActionType) actionTypeMap.get( new Integer(0) );
+        assertEquals(ActionType.ACTIVATIONGROUP, type.type);
+        
+        actionTypeMap = new HashMap();
+        ActionType.addNewActionType( actionTypeMap, "ACTIVATION-GROUP", 0, 1 );
+        type = (ActionType) actionTypeMap.get( new Integer(0) );
+        assertEquals(ActionType.ACTIVATIONGROUP, type.type);
+        
+        actionTypeMap = new HashMap();
+        ActionType.addNewActionType( actionTypeMap, "NO-LOOP", 0, 1 );
+        type = (ActionType) actionTypeMap.get( new Integer(0) );
+        assertEquals(ActionType.NOLOOP, type.type);
+
+        
+        
+        
+    }
+    
+}


Property changes on: labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/ActionTypeTest.java
___________________________________________________________________
Name: svn:eol-style
   + native




More information about the jboss-svn-commits mailing list