⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultrulesheetlistener.java

📁 jboss规则引擎
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    private void processNonRuleCell(final int row,
                                    final int column,
                                    final String value) {
        if ( value.startsWith( DefaultRuleSheetListener.RULE_TABLE_TAG ) ) {
            initRuleTable( row,
                           column,
                           value );
        } else {
            this._propertiesListner.newCell( row,
                                        column,
                                        value, SheetListener.NON_MERGED);
        }
    }

    private void processRuleCell(final int row,
                                 final int column,
                                 final String value,
                                 final int mergedColStart) {
        if ( value.startsWith( DefaultRuleSheetListener.RULE_TABLE_TAG ) ) {
            finishRuleTable();
            initRuleTable( row,
                           column,
                           value );
            return;
        }

        // Ignore any comments cells preceeding the first rule table column
        if ( column < this._ruleStartColumn ) {
            return;
        }

        // Ignore any further cells from the rule def row
        if ( row == this._ruleStartRow ) {
            return;
        }

        switch ( row - this._ruleStartRow ) {
            case ACTION_ROW :
                ActionType.addNewActionType( this._actions,
                                             value,
                                             column,
                                             row );
                break;
            case OBJECT_TYPE_ROW :
            	objectTypeRow( row, 
                               column,
                               value,
                               mergedColStart);
            	break;
            case CODE_ROW :
                codeRow( row,
                         column,
                         value );
                break;
            case LABEL_ROW :
                labelRow( row,
                          column,
                          value );
                break;                
            default :
                nextDataCell( row,
                          column,
                          value );
                break;
        }
    }

    /**
     * This is for handling a row where an object declaration may appear,
     * this is the row immediately above the snippets.
     * It may be blank, but there has to be a row here.
     * 
     * Merged cells have "special meaning" which is why this is so freaking hard.
     * A future refactor may be to move away from an "event" based listener.
     */
    private void objectTypeRow(final int row,
                         final int column,
                         final String value,
                         final int mergedColStart) {
        if (value.indexOf( "$param" ) > -1 || value.indexOf( "$1" ) > -1) {
            throw new DecisionTableParseException("It looks like you have snippets in the row that is " +
                                    "meant for column declarations." +
                                    " Please insert an additional row before the snippets." +
                                    " Row number: " + (row + 1));
        }
        ActionType action = getActionForColumn( row, column );
        if (mergedColStart == SheetListener.NON_MERGED) {
            if (action.type == ActionType.CONDITION) {
                SourceBuilder src = new LhsBuilder(value);
                action.setSourceBuilder(src);
                this.sourceBuilders.add(src);
                
            } else if (action.type == ActionType.ACTION) {
                SourceBuilder src = new RhsBuilder(value);
                action.setSourceBuilder(src);
                this.sourceBuilders.add(src);
            }
        } else {
            if (column == mergedColStart) {
                if (action.type == ActionType.CONDITION) {                    
                    action.setSourceBuilder(new LhsBuilder(value));
                    this.sourceBuilders.add( action.getSourceBuilder() );
                } else if (action.type == ActionType.ACTION) {                    
                    action.setSourceBuilder(new RhsBuilder(value));
                    this.sourceBuilders.add( action.getSourceBuilder() );
                }
            } else {
                ActionType startOfMergeAction = getActionForColumn( row, mergedColStart );
                action.setSourceBuilder( startOfMergeAction.getSourceBuilder() );
            }
            
        }
    }
    
    private void codeRow(final int row,
                         final int column,
                         final String value) {
        final ActionType actionType = getActionForColumn( row, column );
        if (actionType.getSourceBuilder() == null) {
            if (actionType.type == ActionType.CONDITION) {
                actionType.setSourceBuilder( new LhsBuilder(null) );
                this.sourceBuilders.add( actionType.getSourceBuilder() );
            } else if (actionType.type == ActionType.ACTION) {
                actionType.setSourceBuilder( new RhsBuilder(null) );
                this.sourceBuilders.add( actionType.getSourceBuilder() );
            }
        }
        if ( value.trim().equals( "" ) && (actionType.type == ActionType.ACTION || actionType.type == ActionType.CONDITION) ) {
            throw new DecisionTableParseException( "Code description - row:" + (row + 1) + " cell number:" + (column + 1) + " - does not contain any code specification. It should !" );
        }

        actionType.addTemplate(column, value);
    }

    private void labelRow(final int row,
                          final int column,
                          final String value) {
        final ActionType actionType = getActionForColumn( row,
                                                    column );

        if ( !value.trim().equals( "" ) && (actionType.type == ActionType.ACTION || actionType.type == ActionType.CONDITION) ) {
            this._cellComments.put( new Integer( column ),
                               value );
        } else {
            this._cellComments.put( new Integer( column ),
                               "From column: " + Rule.convertColNumToColName( column ) );
        }
    }

    private ActionType getActionForColumn(final int row,
                                          final int column) {
        final ActionType actionType = (ActionType) this._actions.get( new Integer( column ) );

        if ( actionType == null ) {
            throw new DecisionTableParseException( "Code description - row number:" + (row + 1) + " cell number:" + (column + 1) + " - does not have an 'ACTION' or 'CONDITION' column header." );
        }

        return actionType;
    }

    private void nextDataCell(final int row,
                          final int column,
                          final String value) {
        final ActionType actionType = getActionForColumn( row,
                                                    column );

        if ( row - this._ruleRow > 1 ) {
            // Encountered a row gap from the last rule.
            // This is not part of the ruleset.
            finishRuleTable();
            processNonRuleCell( row,
                                column,
                                value );
            return;
        }

        if ( row > this._ruleRow ) {
            // In a new row/rule
            this._currentRule = createNewRuleForRow( row );

            this._ruleList.add( this._currentRule );
            this._ruleRow++;
        }

        //if the rule set is not sequential and the actionType type is PRIORITY then set the current Rule's salience paramenter with the value got from the cell
        if ( actionType.type == ActionType.PRIORITY && !this._currentSequentialFlag ) {
            this._currentRule.setSalience( new Integer( value ) );
        } else if ( actionType.type == ActionType.NAME ) // if the actionType
        // type is PRIORITY then
        // set the current
        // Rule's name
        // paramenter with the
        // value got from the
        // cell
        {
            this._currentRule.setName( value );
        } else if ( actionType.type == ActionType.DESCRIPTION ) // if the
        // actionType
        // type is
        // DESCRIPTION
        // then set the
        // current
        // Rule's
        // description
        // paramenter
        // with the
        // value got
        // from the cell
        {
            this._currentRule.setDescription( value );
        } else if ( actionType.type == ActionType.ACTIVATIONGROUP ) // if the actionType
        // type is NOLOOP
        // then set the
        // current Rule's
        // no-loop
        // paramenter with
        // the value got
        // from the cell
        {
            this._currentRule.setActivationGroup( value );
        } else if ( actionType.type == ActionType.NOLOOP ) // if the actionType
        // type is NOLOOP
        // then set the
        // current Rule's
        // no-loop
        // paramenter with
        // the value got
        // from the cell
        {
            this._currentRule.setNoLoop( value );
        } else if ( actionType.type == ActionType.DURATION ) // if the actionType
        // type is DURATION
        // then creates a
        // new duration tag
        // with the value
        // got from the cell
        {
            createDuration( column,
                            value,
                            actionType );
        } else if ( actionType.type == ActionType.CONDITION || actionType.type == ActionType.ACTION ) {
            actionType.addCellValue( column, value );
        }

    }

    private Rule createNewRuleForRow(final int row) {

        
        Integer salience = null;
        if ( this._currentSequentialFlag ) {
            salience = new Integer( Rule.calcSalience( row ) );
        }
        final int spreadsheetRow = row + 1;
        final String name = this._currentRulePrefix + "_" + spreadsheetRow;
        final Rule rule = new Rule( name,
                              salience,
                              spreadsheetRow );
        rule.setComment( "From row number: " + (spreadsheetRow) );

        return rule;
        
    }


    // 08 - 16 - 2005 RIK: This function creates a new DURATION 
    private void createDuration(final int column,
                                final String value,
                                final ActionType actionType) {

        final Duration dur = new Duration();
        dur.setSnippet( value );
        dur.setComment( cellComment( column ) );
        this._currentRule.setDuration( dur );
    }


    private boolean isCellValueEmpty(final String value) {
        return value == null || "".equals( value.trim() );
    }

    private String cellComment(final int column) {
        return "From column: " + Rule.convertColNumToColName( column );
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -