Esempio n. 1
0
        private static PathExpr ToPathExpr(string pathString)
        {
            MatchCollection matchCollection = Regex.Matches(pathString, PathPartPattern, RegexOptions.Compiled | RegexOptions.Singleline);

            List <PathStep> pathSteps     = new List <PathStep>();
            PathStep        precedingStep = null;

            foreach (Match stepMatch in matchCollection)
            {
                List <PredicateExpr> predicateExprs    = null;
                CaptureCollection    predicateCaptures = stepMatch.Groups["predicate"].Captures;
                foreach (Capture capture in predicateCaptures)
                {
                    if (predicateExprs == null)
                    {
                        predicateExprs = new List <PredicateExpr>();
                    }

                    string        predicateExprString = capture.Value;
                    ExprOperator  predicate           = ToExprOperator(predicateExprString);
                    PredicateExpr predicateExpr       = new PredicateExpr(predicate);
                    predicateExprs.Add(predicateExpr);
                }

                PathStep thisStep = new PathStep(stepMatch, precedingStep, predicateExprs);
                pathSteps.Add(thisStep);
                precedingStep = thisStep;
            }

            PathExpr pathExpr = new PathExpr(pathString, pathSteps);

            return(pathExpr);
        }
Esempio n. 2
0
        private AssertionContext ProcessPathPartWithWildcardForArId(AssertionContext contextObj, PathStep pathStep)
        {
            DesignByContract.Check.Require(pathStep.Attribute == "//*", "anyAttribute value must be //*.");

            Locatable locatable = contextObj.Data as Locatable;

            if (locatable != null)
            {
                ArchetypedPathProcessor archetypePathProcessor = new ArchetypedPathProcessor(locatable);
                string archetypePathWithWildcardKey            = null;
                if (!string.IsNullOrEmpty(pathStep.ArchetypeNodeId))
                {
                    archetypePathWithWildcardKey = pathStep.Attribute + "[" + pathStep.ArchetypeNodeId + "]";
                }
                else if (!string.IsNullOrEmpty(pathStep.NodePattern))
                {
                    archetypePathWithWildcardKey = pathStep.Attribute + "[{/" + pathStep.NodePattern + "/}]";
                }
                else
                {
                    throw new NotSupportedException(pathStep.Value + " path not supported");
                }
                object obj = null;
                if (!archetypePathProcessor.PathExists(archetypePathWithWildcardKey))
                {
                    return(null);
                }

                if (archetypePathProcessor.PathUnique(archetypePathWithWildcardKey))
                {
                    obj = archetypePathProcessor.ItemAtPath(archetypePathWithWildcardKey);
                }
                else
                {
                    obj = archetypePathProcessor.ItemsAtPath(archetypePathWithWildcardKey);
                }

                if (obj == null)
                {
                    throw new ApplicationException("obj must not be null.");
                }

                return(new AssertionContext(obj, contextObj));
            }

            AssumedTypes.IList ilist = contextObj.Data as AssumedTypes.IList;
            if (ilist == null)
            {
                throw new ApplicationException("only support either locatable or ilist");
            }
            AssumedTypes.List <object> results = new OpenEhr.AssumedTypes.List <object>();
            foreach (Locatable locatableItem in ilist)
            {
                AssertionContext assertionContext = new AssertionContext(locatableItem, contextObj);
                AssertionContext result           = ProcessPathPartWithWildcardForArId(assertionContext, pathStep);
                if (result != null && result.Data != null)
                {
                    results.Add(result.Data);
                }
            }

            if (results.Count > 0)
            {
                return(new AssertionContext(results, contextObj));
            }

            return(null);
        }
Esempio n. 3
0
        private AssertionContext ProcessPathPartWithAllProperties(AssertionContext rootObjContext, PathStep pathStep)
        {
            DesignByContract.Check.Require(rootObjContext != null && rootObjContext.Data != null,
                                           "attributeObjContext and attributeObjContext.Data must not be null.");

            object rootObj = rootObjContext.Data;

            AssumedTypes.List <object> objList = new OpenEhr.AssumedTypes.List <object>();

            // go through all properties
            System.Reflection.PropertyInfo[] allProperties = rootObj.GetType().GetProperties(System.Reflection.BindingFlags.Public
                                                                                             | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.DeclaredOnly
                                                                                             | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.Instance);
            foreach (System.Reflection.PropertyInfo property in allProperties)
            {
                object propertyValue = property.GetValue(rootObj, null);
                if (propertyValue != null)
                {
                    AssertionContext propertyContext = new AssertionContext(propertyValue, rootObjContext);
                    AssertionContext tempContext     = ProcessPathPartWithAttrObject(propertyContext, pathStep);
                    if (tempContext != null && tempContext.Data != null)
                    {
                        objList.Add(tempContext.Data);
                    }
                }
            }

            if (objList.Count == 0)
            {
                return(null);
            }
            if (objList.Count == 1)
            {
                return(new AssertionContext(objList[0], rootObjContext));
            }

            return(new AssertionContext(objList, rootObjContext));
        }
Esempio n. 4
0
        private AssertionContext ProcessPathPartWithAttrObject(AssertionContext attributeObjContext, PathStep pathStep)
        {
            DesignByContract.Check.Require(attributeObjContext != null && attributeObjContext.Data != null,
                                           "attributeObjContext and attributeObjContext.Data must not be null.");

            AssertionContext tempContext = attributeObjContext;

            if (pathStep.Predicates != null)
            {
                foreach (PredicateExpr predicate in pathStep.Predicates)
                {
                    AssertionContext predicateObj = predicate.Evaluate(tempContext);

                    if (predicateObj == null)
                    {
                        return(null);
                    }

                    tempContext = predicateObj;
                }
            }

            return(tempContext);
        }
Esempio n. 5
0
 internal PathStep(Match stepMatch, PathStep precedingStep, List <PredicateExpr> predicates)
 {
     this.stepMatch     = stepMatch;
     this.precedingStep = precedingStep;
     this.predicates    = predicates;
 }
Esempio n. 6
0
 internal PathStep(Match stepMatch, PathStep precedingStep)
 {
     this.stepMatch     = stepMatch;
     this.precedingStep = precedingStep;
 }