예제 #1
0
        public object ItemAtPath(object obj)
        {
            object itemAtPath = this.pathExpr.Evaluate(obj);

            AssumedTypes.IList iList = itemAtPath as AssumedTypes.IList;

            // if itemAtPath is not a list, return it.
            if (iList == null)
            {
                return(itemAtPath);
            }

            //// if itemAtPath is a list, generate LocatableList when the items are locatable.
            //// otherwise return the list
            LocatableList <Locatable> locatableList = null;


            AssumedTypes.List <object> items = iList as AssumedTypes.List <object>;
            if (items != null)
            {
                return(items);
            }
            else
            {
                items = new OpenEhr.AssumedTypes.List <object>();
            }

            foreach (object o in iList)
            {
                items.Add(o);
            }

            return(items);
        }
예제 #2
0
        private object GetAttributeObject(string attributeName, AssumedTypes.IList list)
        {
            if (list == null || list.Count == 0)
            {
                return(null);
            }

            AssumedTypes.List <object> attrObjects = new OpenEhr.AssumedTypes.List <object>();
            foreach (object obj in list)
            {
                object attributeObj = CallGetAttributeObject(attributeName, obj);
                if (attributeObj != null)
                {
                    attrObjects.Add(attributeObj);
                }
            }

            if (attrObjects.Count > 1)
            {
                return(attrObjects);
            }
            if (attrObjects.Count == 1)
            {
                return(attrObjects[0]);
            }

            return(null);
        }
예제 #3
0
        internal AssertionContext Evaluate(AssertionContext contextObj)
        {
            if (contextObj == null)
                return null;

            AssumedTypes.IList assumedIList = contextObj.Data as AssumedTypes.IList;
            if (assumedIList != null)
            {
                AssumedTypes.List<object> results = new OpenEhr.AssumedTypes.List<object>();
                foreach (object obj in assumedIList)
                {
                    AssertionContext assertObj = new AssertionContext(obj, contextObj);
                    AssertionContext evaluateResult = Evaluate(assertObj);
                    if (evaluateResult != null)
                    {
                        AssumedTypes.List<object> aList = evaluateResult.Data as AssumedTypes.List<object>;
                        if (aList == null)
                            results.Add(evaluateResult.Data);
                        else
                            foreach (object o in aList)
                                results.Add(o);
                    }
                }

                if (results.Count == 0)
                    return null;

                return new AssertionContext(results, contextObj);
            }

            System.Collections.IList list = contextObj.Data as System.Collections.IList;
            if (list == null)
            {
                return EvaluateSingleAttri(contextObj);
            }
            else
            {
                AssumedTypes.List<object> results = new AssumedTypes.List<object>();
                foreach (object obj in list)
                {
                    AssertionContext assertObj = new AssertionContext(obj, contextObj);
                    AssertionContext evaluateResult = Evaluate(assertObj);
                    if (evaluateResult != null)
                        results.Add(evaluateResult.Data);
                }

                if (results.Count == 0)
                    return null;

                return new AssertionContext(results, contextObj);
            }
        }
예제 #4
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));
        }
예제 #5
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);
        }
예제 #6
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;
        }
예제 #7
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);
        }
예제 #8
0
        private object GetAttributeObject(string attributeName, AssumedTypes.IList list)
        {
            if (list == null || list.Count == 0)
                return null;

            AssumedTypes.List<object> attrObjects = new OpenEhr.AssumedTypes.List<object>();
            foreach (object obj in list)
            {
                object attributeObj = CallGetAttributeObject(attributeName, obj);
                if (attributeObj != null)
                    attrObjects.Add(attributeObj);
            }

            if (attrObjects.Count > 1)
                return attrObjects;
            if (attrObjects.Count == 1)
                return attrObjects[0];

            return null;
        }
예제 #9
0
        internal AssertionContext Evaluate(AssertionContext contextObj)
        {
            if (contextObj == null)
            {
                return(null);
            }

            AssumedTypes.IList assumedIList = contextObj.Data as AssumedTypes.IList;
            if (assumedIList != null)
            {
                AssumedTypes.List <object> results = new OpenEhr.AssumedTypes.List <object>();
                foreach (object obj in assumedIList)
                {
                    AssertionContext assertObj      = new AssertionContext(obj, contextObj);
                    AssertionContext evaluateResult = Evaluate(assertObj);
                    if (evaluateResult != null)
                    {
                        AssumedTypes.List <object> aList = evaluateResult.Data as AssumedTypes.List <object>;
                        if (aList == null)
                        {
                            results.Add(evaluateResult.Data);
                        }
                        else
                        {
                            foreach (object o in aList)
                            {
                                results.Add(o);
                            }
                        }
                    }
                }

                if (results.Count == 0)
                {
                    return(null);
                }

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

            System.Collections.IList list = contextObj.Data as System.Collections.IList;
            if (list == null)
            {
                return(EvaluateSingleAttri(contextObj));
            }
            else
            {
                AssumedTypes.List <object> results = new AssumedTypes.List <object>();
                foreach (object obj in list)
                {
                    AssertionContext assertObj      = new AssertionContext(obj, contextObj);
                    AssertionContext evaluateResult = Evaluate(assertObj);
                    if (evaluateResult != null)
                    {
                        results.Add(evaluateResult.Data);
                    }
                }

                if (results.Count == 0)
                {
                    return(null);
                }

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