Ejemplo n.º 1
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);
        }
Ejemplo 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;
        }