Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012 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.
  */
 package org.drools.workbench.models.guided.dtable.shared.model;
 
 import java.util.List;
 import java.util.Set;
 
A RuleModel that can provide details of bound Facts and Fields from an associated Decision Table. This allows columns using BRL fragments to integrate with Decision Table columns
 
 public class BRLRuleModel extends RuleModel {
 
     private static final long serialVersionUID = 540l;
 
     private GuidedDecisionTable52 dtable;
 
     public BRLRuleModel() {
     }
 
     public BRLRuleModelfinal GuidedDecisionTable52 dtable ) {
         PortablePreconditions.checkNotNull"dtable",
                                             dtable );
         this. = dtable;
     }
 
     @Override
     public List<StringgetLHSBoundFacts() {
         final Set<Stringfacts = new HashSet<String>();
         for ( CompositeColumn<? extends BaseColumncol : .getConditions() ) {
             if ( col instanceof Pattern52 ) {
                 final Pattern52 p = (Pattern52col;
                 if ( p.isBound() ) {
                     facts.addp.getBoundName() );
                 }
             } else if ( col instanceof BRLConditionColumn ) {
                 final BRLConditionColumn brl = (BRLConditionColumncol;
                 for ( IPattern p : brl.getDefinition() ) {
                     if ( p instanceof FactPattern ) {
                         final FactPattern fp = (FactPatternp;
                         if ( fp.isBound() ) {
                             facts.addfp.getBoundName() );
                         }
                     }
                 }
             }
         }
         facts.addAllsuper.getLHSBoundFacts() );
         return new ArrayList<String>( facts );
     }
 
     @Override
     public FactPattern getLHSBoundFactfinal String var ) {
         for ( CompositeColumn<? extends BaseColumncol : .getConditions() ) {
             if ( col instanceof Pattern52 ) {
                 final Pattern52 p = (Pattern52col;
                 if ( p.isBound() && p.getBoundName().equalsvar ) ) {
                     return new Pattern52FactPatternAdaptorp );
                 }
             } else if ( col instanceof BRLConditionColumn ) {
                 final BRLConditionColumn brl = (BRLConditionColumncol;
                 for ( IPattern p : brl.getDefinition() ) {
                     if ( p instanceof FactPattern ) {
                         final FactPattern fp = (FactPatternp;
                         if ( fp.isBound() && fp.getBoundName().equalsvar ) ) {
                             return fp;
                        }
                    }
                }
            }
        }
        return super.getLHSBoundFactvar );
    }
    @Override
    public FieldConstraint getLHSBoundFieldfinal String var ) {
        for ( CompositeColumn<? extends BaseColumncol : .getConditions() ) {
            if ( col instanceof Pattern52 ) {
                final Pattern52 p = (Pattern52col;
                for ( ConditionCol52 cc : p.getChildColumns() ) {
                    if ( cc.isBound() && cc.getBinding().equalsvar ) ) {
                        return new ConditionCol52FieldConstraintAdaptorcc );
                    }
                }
            } else if ( col instanceof BRLConditionColumn ) {
                final BRLConditionColumn brl = (BRLConditionColumncol;
                for ( IPattern p : brl.getDefinition() ) {
                    if ( p instanceof FactPattern ) {
                        final FactPattern fp = (FactPatternp;
                        for ( FieldConstraint fc : fp.getFieldConstraints() ) {
                            final List<StringfieldBindings = getFieldBindingfc );
                            if ( fieldBindings.containsvar ) ) {
                                return fc;
                            }
                        }
                    }
                }
            }
        }
        return super.getLHSBoundFieldvar );
    }
    @Override
    public String getLHSBindingTypefinal String var ) {
        for ( CompositeColumn<? extends BaseColumncol : .getConditions() ) {
            if ( col instanceof Pattern52 ) {
                final Pattern52 p = (Pattern52col;
                if ( p.isBound() && p.getBoundName().equalsvar ) ) {
                    return p.getFactType();
                }
                for ( ConditionCol52 cc : p.getChildColumns() ) {
                    if ( cc.isBound() && cc.getBinding().equalsvar ) ) {
                        return cc.getFieldType();
                    }
                }
            } else if ( col instanceof BRLConditionColumn ) {
                final BRLConditionColumn brl = (BRLConditionColumncol;
                for ( IPattern p : brl.getDefinition() ) {
                    if ( p instanceof FactPattern ) {
                        final FactPattern fp = (FactPatternp;
                        if ( fp.isBound() && fp.getBoundName().equalsvar ) ) {
                            return fp.getFactType();
                        }
                        for ( FieldConstraint fc : fp.getFieldConstraints() ) {
                            final String type = getFieldBindingfc,
                                                                 var );
                            if ( type != null ) {
                                return type;
                            }
                        }
                    }
                }
            }
        }
        return super.getLHSBindingTypevar );
    }
    @Override
    public FactPattern getLHSParentFactPatternForBindingfinal String var ) {
        for ( CompositeColumn<? extends BaseColumncol : .getConditions() ) {
            if ( col instanceof Pattern52 ) {
                final Pattern52 p = (Pattern52col;
                if ( p.isBound() && p.getBoundName().equalsvar ) ) {
                    return new Pattern52FactPatternAdaptorp );
                }
                for ( ConditionCol52 cc : p.getChildColumns() ) {
                    if ( cc.isBound() && cc.getBinding().equalsvar ) ) {
                        return new Pattern52FactPatternAdaptorp );
                    }
                }
            } else if ( col instanceof BRLConditionColumn ) {
                final BRLConditionColumn brl = (BRLConditionColumncol;
                for ( IPattern p : brl.getDefinition() ) {
                    if ( p instanceof FactPattern ) {
                        final FactPattern fp = (FactPatternp;
                        if ( fp.isBound() && var.equalsfp.getBoundName() ) ) {
                            return fp;
                        }
                        for ( FieldConstraint fc : fp.getFieldConstraints() ) {
                            final List<StringfieldBindings = getFieldBindingfc );
                            if ( fieldBindings.containsvar ) ) {
                                return fp;
                            }
                        }
                    }
                }
            }
        }
        return super.getLHSParentFactPatternForBindingvar );
    }
    @Override
    public List<StringgetAllVariables() {
        final Set<Stringvariables = new HashSet<String>();
        variables.addAllgetAllLHSVariables() );
        variables.addAllgetAllRHSVariables() );
        return new ArrayList<String>( variables );
    }
    @Override
    public List<StringgetAllLHSVariables() {
        final Set<Stringvariables = new HashSet<String>();
        for ( CompositeColumn<? extends BaseColumncol : .getConditions() ) {
            if ( col instanceof Pattern52 ) {
                final Pattern52 p = (Pattern52col;
                if ( p.isBound() ) {
                    variables.addp.getBoundName() );
                }
                for ( ConditionCol52 cc : p.getChildColumns() ) {
                    if ( cc.isBound() ) {
                        variables.addcc.getBinding() );
                    }
                }
            } else if ( col instanceof BRLConditionColumn ) {
                final BRLConditionColumn brl = (BRLConditionColumncol;
                for ( IPattern p : brl.getDefinition() ) {
                    if ( p instanceof FactPattern ) {
                        final FactPattern fp = (FactPatternp;
                        if ( fp.isBound() ) {
                            variables.addfp.getBoundName() );
                        }
                        for ( FieldConstraint fc : fp.getFieldConstraints() ) {
                            if ( fc instanceof SingleFieldConstraintEBLeftSide ) {
                                final SingleFieldConstraintEBLeftSide exp = (SingleFieldConstraintEBLeftSidefc;
                                if ( exp.getExpressionLeftSide() != null && exp.getExpressionLeftSide().isBound() ) {
                                    variables.addexp.getExpressionLeftSide().getBinding() );
                                }
                            } else if ( fc instanceof SingleFieldConstraint ) {
                                final SingleFieldConstraint sfc = (SingleFieldConstraintfc;
                                if ( sfc.isBound() ) {
                                    variables.addsfc.getFieldBinding() );
                                }
                                if ( sfc.getExpressionValue() != null && sfc.getExpressionValue().isBound() ) {
                                    variables.addsfc.getExpressionValue().getBinding() );
                                }
                            }
                        }
                    }
                }
            }
        }
        variables.addAllsuper.getAllLHSVariables() );
        return new ArrayList<String>( variables );
    }
    @Override
    public List<StringgetAllRHSVariables() {
        final Set<Stringvariables = new HashSet<String>();
        for ( ActionCol52 col : .getActionCols() ) {
            if ( col instanceof ActionInsertFactCol52 ) {
                final ActionInsertFactCol52 action = (ActionInsertFactCol52col;
                variables.addaction.getBoundName() );
            } else if ( col instanceof BRLActionColumn ) {
                final BRLActionColumn brl = (BRLActionColumncol;
                for ( IAction a : brl.getDefinition() ) {
                    if ( a instanceof ActionInsertFact ) {
                        final ActionInsertFact action = (ActionInsertFacta;
                        if ( action.isBound() ) {
                            variables.addaction.getBoundName() );
                        }
                    }
                }
            }
        }
        variables.addAllsuper.getAllRHSVariables() );
        return new ArrayList<String>( variables );
    }
    @Override
    public boolean isBoundFactUsedfinal String binding ) {
        for ( ActionCol52 col : .getActionCols() ) {
            if ( col instanceof ActionInsertFactCol52 ) {
                final ActionInsertFactCol52 action = (ActionInsertFactCol52col;
                if ( action.getBoundName().equalsbinding ) ) {
                    return true;
                }
            } else if ( col instanceof ActionRetractFactCol52 ) {
                if ( col instanceof LimitedEntryActionRetractFactCol52 ) {
                    //Check whether Limited Entry retraction is bound to Pattern
                    final LimitedEntryActionRetractFactCol52 ler = (LimitedEntryActionRetractFactCol52col;
                    if ( ler.getValue().getStringValue().equalsbinding ) ) {
                        return false;
                    }
                } else {
                    //Check whether data for column contains Pattern binding
                    final int colIndex = .getExpandedColumns().indexOfcol );
                    for ( List<DTCellValue52row : .getData() ) {
                        DTCellValue52 cell = row.getcolIndex );
                        if ( cell != null && cell.getStringValue().equalsbinding ) ) {
                            return true;
                        }
                    }
                }
            } else if ( col instanceof BRLActionColumn ) {
                final BRLActionColumn brl = (BRLActionColumncol;
                for ( IAction a : brl.getDefinition() ) {
                    if ( a instanceof ActionSetField ) {
                        final ActionSetField action = (ActionSetFielda;
                        if ( action.getVariable().equalsbinding ) ) {
                            return true;
                        }
                    } else if ( a instanceof ActionRetractFact ) {
                        final ActionRetractFact action = (ActionRetractFacta;
                        if ( action.getVariableName().equalsbinding ) ) {
                            return true;
                        }
                    }
                }
            }
        }
        return super.isBoundFactUsedbinding );
    }
    @Override
        final Set<Stringvariables = new HashSet<String>();
        for ( CompositeColumn<? extends BaseColumncol : .getConditions() ) {
            if ( col instanceof Pattern52 ) {
                final Pattern52 p = (Pattern52col;
                if ( p.isBound() ) {
                    variables.addp.getBoundName() );
                }
                for ( ConditionCol52 cc : p.getChildColumns() ) {
                    if ( cc.isBound() ) {
                        variables.addcc.getBinding() );
                    }
                }
            } else if ( col instanceof BRLConditionColumn ) {
                //Delegate to super class's implementation
                final RuleModel rm = new RuleModel();
                final BRLConditionColumn brl = (BRLConditionColumncol;
                rm.lhs = brl.getDefinition().toArraynew IPatternbrl.getDefinition().size() ] );
                variables.addAllrm.getBoundVariablesInScopecon ) );
            }
        }
        variables.addAllsuper.getBoundVariablesInScopecon ) );
        return new ArrayList<String>( variables );
    }
    @Override
    public boolean isVariableNameUsedString s ) {
        return super.isVariableNameUseds );
    }
    @Override
    public List<StringgetRHSBoundFacts() {
        final Set<Stringvariables = new HashSet<String>();
        for ( ActionCol52 col : .getActionCols() ) {
            if ( col instanceof ActionInsertFactCol52 ) {
                final ActionInsertFactCol52 action = (ActionInsertFactCol52col;
                variables.addaction.getBoundName() );
            } else if ( col instanceof BRLActionColumn ) {
                final BRLActionColumn brl = (BRLActionColumncol;
                for ( IAction a : brl.getDefinition() ) {
                    if ( a instanceof ActionInsertFact ) {
                        final ActionInsertFact action = (ActionInsertFacta;
                        if ( action.isBound() ) {
                            variables.addaction.getBoundName() );
                        }
                    }
                }
            }
        }
        variables.addAllsuper.getRHSBoundFacts() );
        return new ArrayList<String>( variables );
    }
    @Override
    public ActionInsertFact getRHSBoundFactfinal String var ) {
        for ( ActionCol52 col : .getActionCols() ) {
            if ( col instanceof ActionInsertFactCol52 ) {
                final ActionInsertFactCol52 action = (ActionInsertFactCol52col;
                if ( action.getBoundName().equalsvar ) ) {
                    if ( action.isInsertLogical() ) {
                        return new ActionInsertFactCol52ActionInsertLogicalFactAdaptoraction );
                    }
                    return new ActionInsertFactCol52ActionInsertFactAdaptoraction );
                }
            } else if ( col instanceof BRLActionColumn ) {
                final BRLActionColumn brl = (BRLActionColumncol;
                for ( IAction a : brl.getDefinition() ) {
                    if ( a instanceof ActionInsertFact ) {
                        final ActionInsertFact action = (ActionInsertFacta;
                        if ( action.isBound() ) {
                            if ( action.getBoundName().equalsvar ) ) {
                                return action;
                            }
                        }
                    }
                }
            }
        }
        return super.getRHSBoundFactvar );
    }
New to GrepCode? Check out our FAQ X