Beispiel #1
0
        private static ExprBinaryOperator ProcessPredicateWithFullPath(Match match)
        {
            string fullPath = match.Groups["fullPath"].Value;

            if (string.IsNullOrEmpty(fullPath))
            {
                throw new ApplicationException("fullPath must not be null or empty.");
            }

            PathExpr     pathExpr             = ToPathExpr(fullPath);
            string       standardExprOperator = match.Groups["predicate_path_operator"].Value;
            OperatorKind operatorKind         = new OperatorKind(OperatorKind.GetOperatorKind(standardExprOperator));

            string predicateCriteria = match.Groups["predicate_criteria"].Value;

            if (string.IsNullOrEmpty(predicateCriteria))
            {
                throw new ApplicationException("predicateCriteria must not be null or empty.");
            }

            object             criteriaValue  = null;
            string             type           = GetCriteriaType(match, out criteriaValue);
            ExprLeaf           rightOperand   = new ExprLeaf(criteriaValue, type, "constraint");
            ExprBinaryOperator binaryOperator = new ExprBinaryOperator(pathExpr, rightOperand, type, operatorKind, false);

            return(binaryOperator);
        }
Beispiel #2
0
        private static ExprBinaryOperator ProcessMatchesExpr(Match match)
        {
            string matches = match.Groups["matchesExpr"].Value;

            if (string.IsNullOrEmpty(matches))
            {
                throw new ApplicationException("matches must not be null or empty.");
            }

            string   leftPath    = match.Groups["predicate_path"].Value;
            ExprLeaf leftOperand = null;

            if (string.IsNullOrEmpty(leftPath))
            {
                leftOperand = new ExprLeaf("/archetype_node_id", "String", "path");
            }
            else
            {
                leftOperand = new ExprLeaf(leftPath, "String", "path");
            }
            OperatorKind operatorKind = new OperatorKind(OperatorKind.op_matches);

            string pattern = match.Groups["regex_pattern"].Value;

            if (string.IsNullOrEmpty(pattern))
            {
                throw new ApplicationException("pattern must not be null or empty.");
            }

            ExprLeaf rightOperand = new ExprLeaf(pattern, "String", "pattern");

            ExprBinaryOperator binaryOperator = new ExprBinaryOperator(leftOperand, rightOperand, rightOperand.Type, operatorKind, false);

            return(binaryOperator);
        }
Beispiel #3
0
        private static ExprBinaryOperator ProcessStandardPredicateExpr(Match match)
        {
            string standardExpr = match.Groups["predicate_expre"].Value;

            if (string.IsNullOrEmpty(standardExpr))
            {
                throw new ApplicationException("standardExpr must not be null or empty.");
            }

            string path = match.Groups["predicate_path"].Value;

            if (string.IsNullOrEmpty(path))
            {
                throw new ApplicationException("predicate_path must not be null or empty");
            }

            ExprLeaf     lefOperand           = new ExprLeaf(path, "String", "Path");
            string       standardExprOperator = match.Groups["predicate_path_operator"].Value;
            OperatorKind operatorKind         = new OperatorKind(OperatorKind.GetOperatorKind(standardExprOperator));

            // default value
            object             criteriaValue  = null;
            string             type           = GetCriteriaType(match, out criteriaValue);
            ExprLeaf           rightOperand   = new ExprLeaf(criteriaValue, type, "constraint");
            ExprBinaryOperator binaryOperator = new ExprBinaryOperator(lefOperand, rightOperand, type, operatorKind, false);

            return(binaryOperator);
        }
Beispiel #4
0
        internal static ExprItem ExprItem(string typeName)
        {
            DesignByContract.Check.Require(!string.IsNullOrEmpty(typeName), string.Format(CommonStrings.XMustNotBeNullOrEmpty, "typeName"));

            ExprItem exprItem = null;

            switch (typeName)
            {
            case "EXPR_LEAF":
                exprItem = new ExprLeaf();
                break;

            case "EXPR_UNARY_OPERATOR":
                exprItem = new ExprUnaryOperator();
                break;

            case "EXPR_BINARY_OPERATOR":
                exprItem = new ExprBinaryOperator();
                break;

            default:
                throw new NotSupportedException("type not supported: " + typeName);
            }

            DesignByContract.Check.Ensure(exprItem != null, "exprItem must not be null.");

            return(exprItem);
        }
        internal static string AssertionRegExPattern(Assertion assertion)
        {
            Check.Require(assertion != null, "assertion must not be null.");

            string assertionRegex = string.Empty;

            ExprBinaryOperator expression = assertion.Expression as ExprBinaryOperator;
            if (expression != null)
            {
                ExprLeaf rightExpression = expression.RightOperand as ExprLeaf;
                if (rightExpression != null)
                {
                    CString stringConstraint = rightExpression.Item as CString;
                    Check.Assert(stringConstraint != null);
                    Check.Assert(!string.IsNullOrEmpty(stringConstraint.Pattern));
                    Check.Assert(!(stringConstraint.Pattern.StartsWith("/") &&
                        stringConstraint.Pattern.EndsWith("/")), "Regex is enclosed in forward slashes, as with the C_STRING produced by old version of the ADL Parser.");

                    // Cleanse regex of fullstops which are not either preceded by a backslash (\.) or followed by a star (.*)
                    assertionRegex = stringConstraint.Pattern
                        .Replace(".*", " * ")
                        .Replace(@"\.", @" \ ")
                        .Replace(".", @"\.")
                        .Replace(@" \ ", @"\.")
                        .Replace(" * ", ".*");
                }
            }
            return assertionRegex;
        }
Beispiel #6
0
        protected void Validate(ExprBinaryOperator binaryOperator)
        {
            this.ValidateBase((ExprOperator)binaryOperator);

            Invariant(binaryOperator.LeftOperand != null,
                      string.Format(CommonStrings.XMustNotBeNull, "binaryOperator.LeftOperand"));
            this.Validate(binaryOperator.LeftOperand);
            Invariant(binaryOperator.RightOperand != null,
                      string.Format(CommonStrings.XMustNotBeNull, "binaryOperator.RightOperand"));
            this.Validate(binaryOperator.RightOperand);
        }
Beispiel #7
0
        private static ExprBinaryOperator Map(this EXPR_BINARY_OPERATOR model)
        {
            var binary = new ExprBinaryOperator
            {
                IsPrecedenceOverriden = model.precedence_overridden,
                Operator     = (OperatorKind)((int)model.@operator),
                LeftOperand  = model.left_operand.Map(),
                RightOperand = model.right_operand.Map()
            };

            return(binary);
        }
Beispiel #8
0
        internal string GetValueCriteriaByPath(ExprItem exprItem, string requiredPath)
        {
            ExprLeaf leaf = exprItem as ExprLeaf;

            ExprBinaryOperator binary = exprItem as ExprBinaryOperator;

            if (binary != null)
            {
                switch (binary.Operator.Value)
                {
                case OperatorKind.op_eq:
                case OperatorKind.op_ne:
                {
                    string path = GetPredicateFullPath(binary.LeftOperand);
                    if (path != null && path.EndsWith(requiredPath, StringComparison.InvariantCultureIgnoreCase))
                    {
                        ExprLeaf rightOperand = binary.RightOperand as ExprLeaf;
                        if (rightOperand == null)
                        {
                            throw new ApplicationException("rightOperand must be typeof ExprLeaf when the leftOperand is name/value path.");
                        }

                        if (!rightOperand.ReferenceType.Equals("constraint"))
                        {
                            throw new NotSupportedException(rightOperand.ReferenceType + "rightOperand.ReferenceType is not supported.");
                        }

                        return(rightOperand.Item.ToString());
                    }
                    return(null);
                }

                case OperatorKind.op_or:
                case OperatorKind.op_and:
                case OperatorKind.op_not:
                    ExprItem left      = binary.LeftOperand;
                    ExprItem right     = binary.RightOperand;
                    string   nameValue = GetValueCriteriaByPath(right, requiredPath);
                    if (nameValue != null)
                    {
                        return(nameValue);
                    }
                    nameValue = GetValueCriteriaByPath(left, requiredPath);
                    return(nameValue);

                default:
                    return(null);
                }
            }

            return(null);
        }
Beispiel #9
0
        private static ExprBinaryOperator ProcessArchetypeNodeIdExpr(Match match)
        {
            string archetypeNodeId = match.Groups["archetype_node_id"].Value;

            if (string.IsNullOrEmpty(archetypeNodeId))
            {
                throw new ApplicationException("archetypeNodeId must not be null or empty.");
            }

            ExprLeaf           leftOperand    = new ExprLeaf("/archetype_node_id", "String", "path");
            ExprLeaf           rightOperand   = new ExprLeaf(archetypeNodeId, "String", "constraint");
            ExprBinaryOperator binaryOperator = new ExprBinaryOperator(leftOperand, rightOperand, "String", new OperatorKind(OperatorKind.op_eq),
                                                                       false);

            return(binaryOperator);
        }
Beispiel #10
0
        private static ExprBinaryOperator ProcessShortCutName(Match match)
        {
            string shortCutNameExpr = match.Groups["shortCutName"].Value;

            if (string.IsNullOrEmpty(shortCutNameExpr))
            {
                throw new ApplicationException("shortCutNameExpr must not be null or empty.");
            }

            string nameValue = match.Groups["stringCriteria"].Value;

            ExprLeaf           leftOperand    = new ExprLeaf("/name/value", "String", "path");
            ExprLeaf           rightOperand   = new ExprLeaf(nameValue, "String", "constraint");
            ExprBinaryOperator binaryOperator = new ExprBinaryOperator(leftOperand, rightOperand, "String",
                                                                       new OperatorKind(OperatorKind.op_eq), false);

            return(binaryOperator);
        }
Beispiel #11
0
        private static ExprBinaryOperator ProcessBoolExpr(Match match)
        {
            string boolExprString = match.Groups["genericExpr"].Value;

            if (string.IsNullOrEmpty(boolExprString))
            {
                throw new ApplicationException("boolExprString must not be null or empty.");
            }

            ExprBinaryOperator boolExpr          = null;
            string             leftOperandString = match.Groups["leftSimpleExpr"].Value;

            if (string.IsNullOrEmpty(leftOperandString))
            {
                throw new ApplicationException("leftOperandString must not be null or empty.");
            }

            ExprOperator leftOperand = ToExprOperator(leftOperandString);

            do
            {
                if (boolExpr != null)
                {
                    leftOperand = boolExpr;
                }

                string       boolOperatorStr = match.Groups["predicate_bool_operator"].Value;
                OperatorKind boolOperator    = new OperatorKind(OperatorKind.GetOperatorKind(boolOperatorStr));
                string       rightOperandStr = match.Groups["rightSimpleExpr"].Value;
                if (string.IsNullOrEmpty(rightOperandStr))
                {
                    throw new ApplicationException("rightOperandStr must not be null or empty.");
                }

                ExprOperator rightOperand = ToExprOperator(rightOperandStr);
                boolExpr = new ExprBinaryOperator(leftOperand, rightOperand, "Boolean", boolOperator, false);

                match = match.NextMatch();
            } while (match.Success);

            DesignByContract.Check.Ensure(boolExpr != null, "boolExpr must not be null.");

            return(boolExpr);
        }
Beispiel #12
0
        private static ExprBinaryOperator ProcessPositionExpr(Match match)
        {
            string positionString = match.Groups["position"].Value;

            if (string.IsNullOrEmpty(positionString))
            {
                throw new ApplicationException("positionString must not be null or empty.");
            }

            int position = int.Parse(positionString);

            if (position <= 0)
            {
                throw new ApplicationException("Position specified within openehr path must not <= 0.");
            }

            FunctionCall functionCall = new FunctionCall("position", null, null);
            ExprLeaf     rightOperand = new ExprLeaf(position, "Integer", "constraint");

            ExprBinaryOperator binaryOperator = new ExprBinaryOperator(functionCall, rightOperand,
                                                                       rightOperand.Type, new OperatorKind(OperatorKind.op_eq), false);

            return(binaryOperator);
        }
Beispiel #13
0
        protected void Validate(ExprBinaryOperator binaryOperator)
        {
            this.ValidateBase((ExprOperator)binaryOperator);

            Invariant(binaryOperator.LeftOperand != null,
                string.Format(CommonStrings.XMustNotBeNull, "binaryOperator.LeftOperand"));
            this.Validate(binaryOperator.LeftOperand);
            Invariant(binaryOperator.RightOperand != null,
                string.Format(CommonStrings.XMustNotBeNull, "binaryOperator.RightOperand"));
            this.Validate(binaryOperator.RightOperand);
        }
Beispiel #14
0
        internal static ExprItem ExprItem(string typeName)
        {
            DesignByContract.Check.Require(!string.IsNullOrEmpty(typeName), string.Format(CommonStrings.XMustNotBeNullOrEmpty, "typeName"));

            ExprItem exprItem = null;
            switch (typeName)
            {
                case "EXPR_LEAF":
                    exprItem = new ExprLeaf();
                    break;
                case "EXPR_UNARY_OPERATOR":
                    exprItem = new ExprUnaryOperator();
                    break;
                case "EXPR_BINARY_OPERATOR":
                    exprItem = new ExprBinaryOperator();
                    break;
                default:
                    throw new NotSupportedException("type not supported: " + typeName);
            }

            DesignByContract.Check.Ensure(exprItem != null, "exprItem must not be null.");

            return exprItem;
        }
Beispiel #15
0
        private void WriteXml(ExprBinaryOperator exprBinaryOperator)
        {
            Check.Require(exprBinaryOperator != null, string.Format(CommonStrings.XMustNotBeNull, "exprBinaryOperator"));
            Check.Require(exprBinaryOperator.LeftOperand != null, string.Format(CommonStrings.XMustNotBeNull, "exprBinaryOperator.LeftOperand"));
            Check.Require(exprBinaryOperator.RightOperand != null, string.Format(CommonStrings.XMustNotBeNull, "exprBinaryOperator.RightOperand"));

            this.WriteXmlBase((ExprOperator)exprBinaryOperator);

            writer.WriteStartElement(UseOpenEhrPrefix(writer), "left_operand", OpenEhrNamespace);
            string leftOperandType = AmType.GetName(exprBinaryOperator.LeftOperand);
            writer.WriteAttributeString(UseXsiPrefix(writer), "type", XsiNamespace, leftOperandType);
            this.WriteXml(exprBinaryOperator.LeftOperand);
            writer.WriteEndElement();

            writer.WriteStartElement(UseOpenEhrPrefix(writer), "right_operand", OpenEhrNamespace);
            string rightOperandType = AmType.GetName(exprBinaryOperator.RightOperand);
            writer.WriteAttributeString(UseXsiPrefix(writer), "type", XsiNamespace, rightOperandType);
            this.WriteXml(exprBinaryOperator.RightOperand);
            writer.WriteEndElement();
        }
Beispiel #16
0
        private void ReadXml(ExprBinaryOperator exprBinaryOperator)
        {
            reader.ReadStartElement();
            reader.MoveToContent();

            this.ReadXmlBase((ExprOperator)exprBinaryOperator);

            if (reader.LocalName != "left_operand")
                throw new InvalidXmlException("left_operand" + reader.LocalName);
            string leftOperandType = reader.GetAttribute("type", XsiNamespace);
            Check.Assert(!string.IsNullOrEmpty(leftOperandType), "leftOperandType must not be null or empty.");
            exprBinaryOperator.LeftOperand = AmFactory.ExprItem(leftOperandType);
            this.ReadXml(exprBinaryOperator.LeftOperand);

            if (reader.LocalName != "right_operand")
                throw new InvalidXmlException("right_operand" + reader.LocalName);
            string rightOperandType = reader.GetAttribute("type", XsiNamespace);
            Check.Assert(!string.IsNullOrEmpty(rightOperandType), "rightOperandType must not be null or empty.");
            exprBinaryOperator.RightOperand = AmFactory.ExprItem(rightOperandType);
            this.ReadXml(exprBinaryOperator.RightOperand);

            DesignByContract.Check.Assert(reader.NodeType == System.Xml.XmlNodeType.EndElement,
              "Expected endElement of AssertionVairable");
            reader.ReadEndElement();
            reader.MoveToContent();
        }