/** * If the kernel rule is using an input parameter and its value is already set do propagate this * value to the attribute context of multi rules. */ public void applyValueOfInputParameter() { final VarTuple vars = (VarTuple) this.getAttrContext().getVariables(); for (int i = 0; i < vars.getNumberOfEntries(); i++) { final VarMember v = vars.getVarMemberAt(i); if (v.isInputParameter() && v.isSet()) { VarMember vm = ((VarTuple) this.kernelRule.getAttrContext().getVariables()) .getVarMemberAt(v.getName()); if (vm != null && (vm.getExpr() == null || !v.getExprAsText().equals(vm.getExprAsText()))) { // vm.setExprAsText(v.getExprAsText()); vm.setExpr(v.getExpr()); } for (int j = 0; j < this.multiRules.size(); j++) { vm = ((VarTuple) this.multiRules.get(j).getAttrContext().getVariables()) .getVarMemberAt(v.getName()); if (vm != null && (vm.getExpr() == null || !v.getExprAsText().equals(vm.getExprAsText()))) { // vm.setExprAsText(v.getExprAsText()); vm.setExpr(v.getExpr()); } } } } // System.out.println("applyValueOfInputParameter... "+this.kernelRule.getName()); // ((VarTuple) this.kernelRule.getAttrContext().getVariables()).showVariables(); // for (int j=0; j<this.multiRules.size(); j++) { // System.out.println("applyValueOfInputParameter... "+this.multiRules.get(j).getName()); // ((VarTuple) this.multiRules.get(j).getAttrContext().getVariables()).showVariables(); // } }
// olga: propagate value of OUTPUT parameters of rule r1 to INPUT parameters of rule r2 void propagateOutParamToInParamOfRule(Hashtable<String, String> outPars, Rule r) { if (outPars != null && !outPars.isEmpty()) { VarTuple vars = (VarTuple) r.getAttrContext().getVariables(); for (int i = 0; i < vars.getNumberOfEntries(); i++) { VarMember var = vars.getVarMemberAt(i); String outVal = outPars.get(var.getName()); if (outVal != null && var.isInputParameter()) { var.setExprAsText(outVal); } } } }
void setInputParameter(Rule r) { VarTuple vars = (VarTuple) r.getAttrContext().getVariables(); for (int i = 0; i < vars.getNumberOfEntries(); i++) { VarMember var = (VarMember) vars.getMemberAt(i); if (var.isInputParameter()) System.out.println(var.getName() + " is already input parameter of rule: " + r.getName()); else { // this var should be an input parameter var.setInputParameter(true); System.out.println(var.getName() + " is now input parameter of rule: " + r.getName()); } } }
void setPars(Rule r) throws IOException { System.out.println("\n TAKING INPUTS to APPLY Rule: " + r.getName() + "\n"); List<String> list = r.getInputParameterNames(); System.out.println("The parameters for " + r.getName() + " are: " + list); // System.out.println("The parameters values for " + r.getName() + " are: " + // r.getInputParameters()); System.out.println("The parameters values:"); for (int i = 0; i < list.size(); i++) { String pname = list.get(i); VarMember var = (VarMember) ((VarTuple) r.getAttrContext().getVariables()).getMemberAt(pname); if (var.isSet()) System.out.println(pname + " is set to value: " + var.getExprAsText()); else System.out.println(pname + " is not set"); } VarTuple vars = (VarTuple) r.getAttrContext().getVariables(); for (int i = 0; i < vars.getNumberOfEntries(); i++) { VarMember var = (VarMember) vars.getMemberAt(i); if (var.isInputParameter()) { // olga: if (!var.isSet()) { System.out.println( var.getName() + " is already input parameter of rule: " + r.getName()); System.out.println( "\n \n Please Enter the value for input parameter for rule -- " + r.getName() + " --, parameter name -- " + var.getName() + " --: "); Scanner scan = new Scanner(System.in); String value = scan.nextLine(); System.out.println("The given input was: " + value); var.setInputParameter(true); var.setExprAsText(value); // in1.close(); System.out.println(var.getName() + " is now input parameter of rule: " + r.getName()); } else { System.out.println( var.getExprAsText() + " is value of the INPUT parameter: " + var.getName() + " of rule: " + r.getName()); } } } // in.close(); }
// olga List<VarMember> getOutputParameters(Rule r, List<VarMember> list) { if (list == null) list = new Vector<VarMember>(); else list.clear(); VarTuple vars = (VarTuple) r.getAttrContext().getVariables(); for (int i = 0; i < vars.getNumberOfEntries(); i++) { VarMember var = (VarMember) vars.getMemberAt(i); if (var.isOutputParameter()) { System.out.println(var.getName() + " is OUTPUT parameter of rule: " + r.getName()); list.add(var); } // else { // if this var should be an output parameter // var.setOutputParameter(true); // System.out.println(var.getName()+" is now OUTPUT parameter of rule: "+r.getName()); // } } return list; }