/// <summary> This methods processes the Compare nodes that may exist in the XML. /// <P> /// The best comparison works when the object implements Comparable. /// </P> /// <P> /// If the object does not do so, it eliminates the <,>,<=,>= /// functionality as we are left with .equals(), !.equals(), and /// exception /// </P> /// </summary> /// <param name="aNode">The Node to process /// </param> /// <param name="aMap"/> /// <returns> True if the If stmt passes, False otherwise /// /// </returns> private bool ProcessCompareNode(XPathNavigator aNode, Hashtable aMap) { bool resultBool = false; // This is required in the XML, so we shouldn't have to worry about nulls.... string leftId = aNode.GetAttribute(COMPARE_ATTRS.LEFTID, String.Empty); string rightId = aNode.GetAttribute(COMPARE_ATTRS.RIGHTID, String.Empty); string operatorId = aNode.GetAttribute(COMPARE_ATTRS.OPERATOR, String.Empty); IBREOperator ruleOperator = GetOperator(operatorId); if (ruleOperator != null) { // Get the results IBRERuleResult leftResult = (IBRERuleResult)ruleContext.GetResult(leftId); IBRERuleResult rightResult = (IBRERuleResult)ruleContext.GetResult(rightId); // If it does not, consider a null in left or right members as exceptions! if ((!ruleOperator.AcceptsNulls) && (leftResult == null)) { if (Logger.IsFlowEngineError) { Logger.FlowEngineSource.TraceEvent(TraceEventType.Error, 0, "RuleResult " + leftId + " not found in RuleContext"); } } else if ((!ruleOperator.AcceptsNulls) && (rightResult == null)) { if (Logger.IsFlowEngineError) { Logger.FlowEngineSource.TraceEvent(TraceEventType.Error, 0, "RuleResult " + rightId + " not found in RuleContext"); } } else { if (Logger.IsFlowEngineVerbose) { Logger.FlowEngineSource.TraceEvent(TraceEventType.Verbose, 0, "Retrieved results for comparison"); } object left = (leftResult == null)?null:leftResult.Result; object right = (rightResult == null)?null:rightResult.Result; try { if (Logger.IsFlowEngineVerbose) { Logger.FlowEngineSource.TraceEvent(TraceEventType.Verbose, 0, "BREOperator " + operatorId + " executing"); } resultBool = ruleOperator.ExecuteComparison(ruleContext, aMap, left, right); } catch (InvalidCastException ice) { if (Logger.IsFlowEngineCritical) { Logger.FlowEngineSource.TraceData(TraceEventType.Critical, 0, new BREException("Specified BREOperator " + operatorId + " not of type BREOperator or objects being compared are not" + " of the same type.\n" + "Left Object Name:" + leftId + "\nLeft Object Type:" + left.GetType().FullName + "\nRight Object Name:" + rightId + "\nRight Object Type:" + right.GetType().FullName + "\n", ice)); } } catch (Exception e) { if (Logger.IsFlowEngineCritical) { Logger.FlowEngineSource.TraceData(TraceEventType.Critical, 0, new BREException("Error when processing BREOperator " + operatorId + ".\n" + "Left Object Name:" + leftId + "\nLeft Object:" + left + "\nRight Object Name:" + rightId + "\nRight Object:" + right + "\n", e)); } } } } else { if (Logger.IsFlowEngineCritical) { Logger.FlowEngineSource.TraceData(TraceEventType.Critical, 0, new BREException("Operator could not be loaded from BRERuleContext")); } } if (Logger.IsFlowEngineVerbose) { Logger.FlowEngineSource.TraceEvent(TraceEventType.Verbose, 0, "Compare result: " + resultBool); } return(resultBool); }
/// <summary> This methods processes the Compare nodes that may exist in the XML. /// <P> /// The best comparison works when the object implements Comparable. /// </P> /// <P> /// If the object does not do so, it eliminates the <,>,<=,>= /// functionality as we are left with .equals(), !.equals(), and /// exception /// </P> /// </summary> /// <param name="aNode">The Node to process /// </param> /// <param name="aMap"/> /// <returns> True if the If stmt passes, False otherwise /// /// </returns> private Boolean ProcessCompareNode(XPathNavigator aNode, Hashtable aMap) { bool resultBool = false; // This is required in the XML, so we shouldn't have to worry about nulls.... string leftId = aNode.GetAttribute(COMPARE_ATTRS.LEFTID, String.Empty); string rightId = aNode.GetAttribute(COMPARE_ATTRS.RIGHTID, String.Empty); string operatorId = aNode.GetAttribute(COMPARE_ATTRS.OPERATOR, String.Empty); IBREOperator ruleOperator = GetOperator(operatorId); if (ruleOperator != null) { // Get the results IBRERuleResult leftResult = (IBRERuleResult)ruleContext.GetResult(leftId); IBRERuleResult rightResult = (IBRERuleResult)ruleContext.GetResult(rightId); // If it does not, consider a null in left or right members as exceptions! if ((!ruleOperator.AcceptsNulls) && (leftResult == null)) { DispatchException(new BREException("RuleResult " + leftId + " not found in RuleContext"), ExceptionEventImpl.ERROR); } else if ((!ruleOperator.AcceptsNulls) && (rightResult == null)) { DispatchException(new BREException("RuleResult " + rightId + " not found in RuleContext"), ExceptionEventImpl.ERROR); } else { DispatchLog("Retrieved results for comparison", LogEventImpl.DEBUG); object left = (leftResult == null)?null:leftResult.Result; object right = (rightResult == null)?null:rightResult.Result; try { DispatchLog("BREOperator " + operatorId + " executing.", LogEventImpl.DEBUG); resultBool = ruleOperator.ExecuteComparison(ruleContext, aMap, left, right); } catch (System.InvalidCastException) { DispatchException(new BREException("Specified BREOperator " + operatorId + " not of type BREOperator or objects being compared are not" + " of the same type.\n" + "Left Object Name:" + leftId + "\nLeft Object Type:" + left.GetType().FullName + "\nRight Object Name:" + rightId + "\nRight Object Type:" + right.GetType().FullName + "\n"), ExceptionEventImpl.FATAL); } catch (System.Exception e) { DispatchException(new BREException(e.ToString()), ExceptionEventImpl.FATAL); } } } else { DispatchException(new BREException("Operator could not be loaded from BRERuleContext"), ExceptionEventImpl.FATAL); } DispatchLog("Compare result: " + resultBool, LogEventImpl.DEBUG); return(resultBool); }