Beispiel #1
0
        internal int GetNextState(XName inputSymbol, out XName matchingName, out WildCard matchingWildCard)
        {
            matchingWildCard = null;
            matchingName     = null;

            //first try name table, then match any
            int state = FSM.InvalidState;

            if (nameTransitions != null && nameTransitions.TryGetValue(inputSymbol, out state))
            {
                matchingName = inputSymbol;
            }
            else if (wildCardTransitions != null)
            {
                //We need to scan the wildcard dictionary because this is not "equality" based checking
                foreach (KeyValuePair <WildCard, int> pair in wildCardTransitions)
                {
                    if (pair.Key.Allows(inputSymbol))
                    {
                        matchingWildCard = pair.Key;
                        state            = pair.Value;
                    }
                }
            }

            return(state);
        }
Beispiel #2
0
        internal int FsmMakeTransition(int prevState, XName inputSymbol, out XName matchingName,
                                       out WildCard matchingWildCard)
        {
            Transitions currTrans = ValidationStates.Trans[prevState];

            return(currTrans.GetNextState(inputSymbol, out matchingName, out matchingWildCard));
        }
Beispiel #3
0
        internal XElement ExecuteFSMSubGroup(IEnumerator <XElement> enumerator, XName[] namesInList)
        {
            Debug.Assert(namesInList != null);

            XElement currElem         = null;
            WildCard matchingWildCard = null;
            XName    matchingName     = null;

            while (enumerator.MoveNext())
            {
                currElem     = enumerator.Current;
                currentState = FsmMakeTransition(currentState, currElem.Name, out matchingName, out matchingWildCard);

                if (currentState != FSM.InvalidState)
                {
                    if (matchingName != null)
                    {
                        for (int i = 0; i < namesInList.Length; i++)
                        {
                            if (namesInList.GetValue(i).Equals(currElem.Name))
                            {
                                return(currElem);
                            }
                        }
                    }
                }
                else  //Get stuck. No recovery attempt is provided for now.
                {
                    return(null);
                }
            }

            //No matching elements/wildcards are found
            return(null);
        }
Beispiel #4
0
        public override bool Equals(object obj)
        {
            bool     flag;
            WildCard symbol = obj as WildCard;

            flag = (symbol == null ? false : symbol.NsList.Equals(this.NsList));
            return(flag);
        }
Beispiel #5
0
        public override bool Equals(object obj)
        {
            WildCard symbol = obj as WildCard;

            if (symbol != null)
            {
                return(symbol.NsList.Equals(this.NsList));
            }
            return(false);
        }
Beispiel #6
0
 private XElement GetElement(XName requestingName, WildCard requestingWildCard)
 {
     if (ValidationStates == null)
     {
         Debug.Assert(requestingName != null);
         return(this.GetUntyped().Element(requestingName));
     }
     else
     {
         StartFsm();
         return(ExecuteFSM(GetUntyped().Elements().GetEnumerator(), requestingName, requestingWildCard));
     }
 }
        private XElement GetElement(XName requestingName, WildCard requestingWildCard)
        {
            XElement xElement;

            if (this.ValidationStates != null)
            {
                this.StartFsm();
                xElement = this.ExecuteFSM(this.GetUntyped().Elements().GetEnumerator(), requestingName, requestingWildCard);
            }
            else
            {
                Debug.Assert(requestingName != null);
                xElement = this.GetUntyped().Element(requestingName);
            }
            return(xElement);
        }
        internal XElement ExecuteFSMSubGroup(IEnumerator <XElement> enumerator, XName[] namesInList)
        {
            XElement xElement;

            Debug.Assert(namesInList != null);
            XElement currElem         = null;
            WildCard matchingWildCard = null;
            XName    matchingName     = null;

            while (true)
            {
                if (enumerator.MoveNext())
                {
                    currElem          = enumerator.Current;
                    this.currentState = this.FsmMakeTransition(this.currentState, currElem.Name, out matchingName, out matchingWildCard);
                    if (this.currentState == FSM.InvalidState)
                    {
                        xElement = null;
                        break;
                    }
                    else if (matchingName != null)
                    {
                        int i = 0;
                        while (i < (int)namesInList.Length)
                        {
                            if (!namesInList.GetValue(i).Equals(currElem.Name))
                            {
                                i++;
                            }
                            else
                            {
                                xElement = currElem;
                                return(xElement);
                            }
                        }
                    }
                }
                else
                {
                    xElement = null;
                    break;
                }
            }
            return(xElement);
        }
        internal XElement ExecuteFSM(IEnumerator <XElement> enumerator, XName requestingXName, WildCard requestingWildCard)
        {
            XElement xElement;
            XElement currElem         = null;
            WildCard matchingWildCard = null;
            XName    matchingName     = null;

            while (true)
            {
                if (enumerator.MoveNext())
                {
                    currElem          = enumerator.Current;
                    this.currentState = this.FsmMakeTransition(this.currentState, currElem.Name, out matchingName, out matchingWildCard);
                    if (this.currentState == FSM.InvalidState)
                    {
                        xElement = null;
                        break;
                    }
                    else if (!(requestingXName == null ? true : !(matchingName != null)))
                    {
                        if (requestingXName.Equals(currElem.Name))
                        {
                            xElement = currElem;
                            break;
                        }
                    }
                    else if ((requestingWildCard == null ? false : matchingWildCard != null))
                    {
                        if (requestingWildCard.Allows(currElem.Name))
                        {
                            xElement = currElem;
                            break;
                        }
                    }
                }
                else
                {
                    xElement = null;
                    break;
                }
            }
            return(xElement);
        }
Beispiel #10
0
        protected IEnumerable <XElement> GetWildCards(WildCard requestingWildCard)
        {
            IEnumerator <XElement> enumerator = this.GetUntyped().Elements().GetEnumerator();
            XElement elem = null;

            StartFsm();

            do
            {
                elem = ExecuteFSM(enumerator, null, requestingWildCard);
                if (elem != null)
                {
                    yield return(elem);
                }
                else
                {
                    yield break;
                }
            } while (elem != null);
        }
Beispiel #11
0
        internal XElement ExecuteFSM(IEnumerator <XElement> enumerator, XName requestingXName,
                                     WildCard requestingWildCard)
        {
            XElement currElem         = null;
            WildCard matchingWildCard = null;
            XName    matchingName     = null;

            while (enumerator.MoveNext())
            {
                currElem     = enumerator.Current;
                currentState = FsmMakeTransition(currentState, currElem.Name, out matchingName, out matchingWildCard);

                if (currentState != FSM.InvalidState)
                {
                    if ((requestingXName != null) && (matchingName != null))
                    {
                        if (requestingXName.Equals(currElem.Name))
                        {
                            return(currElem);
                        }
                    }
                    else if ((requestingWildCard != null) && (matchingWildCard != null))
                    {
                        //requesting for ANY
                        if (requestingWildCard.Allows(currElem.Name)
                            ) //Make sure current element is allowed by requesting ANY property
                        {
                            return(currElem);
                        }
                    }
                }
                else
                {
                    //Get stuck. No recovery attempt is provided for now.
                    return(null);
                }
            }

            //No matching elements/wildcards are found
            return(null);
        }
Beispiel #12
0
        internal int GetNextState(XName inputSymbol, out XName matchingName, out WildCard matchingWildCard)
        {
            matchingWildCard = null;
            matchingName     = null;
            int state = FSM.InvalidState;

            if (!(this.nameTransitions == null ? true : !this.nameTransitions.TryGetValue(inputSymbol, out state)))
            {
                matchingName = inputSymbol;
            }
            else if (this.wildCardTransitions != null)
            {
                foreach (KeyValuePair <WildCard, int> pair in this.wildCardTransitions)
                {
                    if (pair.Key.Allows(inputSymbol))
                    {
                        matchingWildCard = pair.Key;
                        state            = pair.Value;
                    }
                }
            }
            return(state);
        }
        protected IEnumerable <XElement> GetWildCards(WildCard requestingWildCard)
        {
            IEnumerator <XElement> enumerator = this.GetUntyped().Elements().GetEnumerator();
            XElement xElement = null;

            this.StartFsm();
            while (true)
            {
                xElement = this.ExecuteFSM(enumerator, null, requestingWildCard);
                if (xElement == null)
                {
                    break;
                }
                else
                {
                    yield return(xElement);

                    if (xElement == null)
                    {
                        break;
                    }
                }
            }
        }
 protected internal XElement GetElement(WildCard requestingWildCard)
 {
     return(this.GetElement(null, requestingWildCard));
 }
        //XML Query axes
        IEnumerable <T> IXTyped.Descendants <T>()
        {
            XTypedElement currentObject = this as XTypedElement;
            Type          lookupType    = typeof(T);

            //Metadata
            IXMetaData schemaMetaData = currentObject as IXMetaData;
            Dictionary <XName, System.Type> localElementsDict = null;
            ILinqToXsdTypeManager           typeManager       = schemaMetaData.TypeManager;
            Dictionary <XName, Type>        typeDictionary    = typeManager.GlobalTypeDictionary;

            //FSM
            XName    matchingName     = null;
            WildCard matchingWildCard = null;
            int      currentState     = FSM.InvalidState;

            XElement parentElement             = null;
            Stack <XTypedElement> elementStack = new Stack <XTypedElement>();

            while (true)
            {
                schemaMetaData = currentObject as IXMetaData;
                FSM fsm = currentObject.ValidationStates;
                if (fsm != null)
                {
                    StartFsm();
                    currentState = fsm.Start;
                }

                Debug.Assert(schemaMetaData != null);
                localElementsDict = schemaMetaData.LocalElementsDictionary;
                parentElement     = currentObject.Untyped;

                matchingName     = null;
                matchingWildCard = null;

                XTypedElement childObject  = null;
                bool          validContent = true;

                foreach (XElement childElement in parentElement.Elements())
                {
                    bool isTypeT = IsAnnoatedElemTypeOf <T>(childElement, out childObject);

                    if (fsm != null)
                    {
                        //Always execute FSM no matter whether we find an element of type T
                        currentState = FsmMakeTransition(currentState, childElement.Name, out matchingName,
                                                         out matchingWildCard);
                        if (currentState == FSM.InvalidState)
                        {
                            validContent = false;
                            break;
                        }
                    }

                    if (!isTypeT)
                    {
                        //check dictionary
                        if (fsm != null && matchingWildCard != null)
                        {
                            childObject = XTypedServices.ToXTypedElement(childElement, typeManager); //Auto-typing
                        }
                        else
                        {
                            childObject = TypeChildElement(childElement, localElementsDict, typeManager);
                        }

                        if (childObject != null)
                        {
                            Type runtimeType = childObject.GetType();
                            if (lookupType.IsAssignableFrom(runtimeType))
                            {
                                isTypeT = true;
                            }
                            else
                            {
                                //Check content type
                                Type contentType = null;
                                if (typeManager.RootContentTypeMapping.TryGetValue(runtimeType, out contentType) &&
                                    lookupType.IsAssignableFrom(contentType))
                                {
                                    childObject = GetContentType(childObject);
                                    isTypeT     = true;
                                }
                            }
                        }
                    }

                    if (isTypeT)
                    {
                        yield return((T)childObject);
                    }

                    if (childObject != null)
                    {
                        elementStack.Push(childObject);
                    }
                }

                if (validContent && elementStack.Count > 0)
                {
                    currentObject = elementStack.Pop();
                }
                else
                {
                    break;
                }
            }
        }
Beispiel #16
0
 public SingleTransition(XName name, int newState)
 {
     nameLabel = name;
     wcLabel   = null;
     nextState = newState;
 }
Beispiel #17
0
 internal void Add(WildCard wildCard, int nextState)
 {
     Add(ref this.wildCardTransitions, wildCard, nextState);
 }
 public SingleTransition(WildCard wildCard, int newState)
 {
     this.wcLabel   = wildCard;
     this.nameLabel = null;
     this.nextState = newState;
 }
 public SingleTransition(XName name, int newState)
 {
     this.nameLabel = name;
     this.wcLabel   = null;
     this.nextState = newState;
 }
Beispiel #20
0
 public SingleTransition(WildCard wildCard, int newState)
 {
     wcLabel   = wildCard;
     nameLabel = null;
     nextState = newState;
 }
        IEnumerable <T> Xml.Schema.Linq.IXTyped.Descendants <T>()
        {
            bool                     flag;
            bool                     flag1;
            bool                     flag2;
            XTypedElement            xTypedElement           = this;
            Type                     type                    = typeof(T);
            IXMetaData               xMetaDatum              = xTypedElement;
            Dictionary <XName, Type> localElementsDictionary = null;
            ILinqToXsdTypeManager    linqToXsdTypeManager    = xMetaDatum.TypeManager;
            Dictionary <XName, Type> globalTypeDictionary    = linqToXsdTypeManager.GlobalTypeDictionary;
            XName                    xName                   = null;
            WildCard                 wildCard                = null;
            int      invalidState = FSM.InvalidState;
            XElement untyped      = null;
            Stack <XTypedElement> xTypedElements = new Stack <XTypedElement>();

            while (true)
            {
                xMetaDatum = xTypedElement;
                FSM validationStates = xTypedElement.ValidationStates;
                if (validationStates != null)
                {
                    this.StartFsm();
                    invalidState = validationStates.Start;
                }
                Debug.Assert(xMetaDatum != null);
                localElementsDictionary = xMetaDatum.LocalElementsDictionary;
                untyped  = xTypedElement.Untyped;
                xName    = null;
                wildCard = null;
                XTypedElement          xTypedElement1 = null;
                bool                   flag3          = true;
                IEnumerator <XElement> enumerator     = untyped.Elements().GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        XElement current = enumerator.Current;
                        bool     flag4   = this.IsAnnoatedElemTypeOf <T>(current, out xTypedElement1);
                        if (validationStates != null)
                        {
                            invalidState = this.FsmMakeTransition(invalidState, current.Name, out xName, out wildCard);
                            if (invalidState == FSM.InvalidState)
                            {
                                goto Label0;
                            }
                        }
                        if (!flag4)
                        {
                            flag           = (validationStates == null ? true : wildCard == null);
                            xTypedElement1 = (flag ? this.TypeChildElement(current, localElementsDictionary, linqToXsdTypeManager) : XTypedServices.ToXTypedElement(current, linqToXsdTypeManager));
                            if (xTypedElement1 != null)
                            {
                                Type type1 = xTypedElement1.GetType();
                                if (!type.IsAssignableFrom(type1))
                                {
                                    Type type2 = null;
                                    flag1 = (!linqToXsdTypeManager.RootContentTypeMapping.TryGetValue(type1, out type2) ? true : !type.IsAssignableFrom(type2));
                                    if (!flag1)
                                    {
                                        xTypedElement1 = this.GetContentType(xTypedElement1);
                                        flag4          = true;
                                    }
                                }
                                else
                                {
                                    flag4 = true;
                                }
                            }
                        }
                        if (flag4)
                        {
                            yield return((T)xTypedElement1);
                        }
                        if (xTypedElement1 != null)
                        {
                            xTypedElements.Push(xTypedElement1);
                        }
                    }
                    goto Label1;
Label0:
                    flag3 = false;
                }
                finally
                {
                    if (enumerator != null)
                    {
                        enumerator.Dispose();
                    }
                }
Label1:
                flag2 = (!flag3 ? true : xTypedElements.Count <= 0);
                if (flag2)
                {
                    break;
                }
                xTypedElement = xTypedElements.Pop();
            }
        }
Beispiel #22
0
 static WildCard()
 {
     WildCard.DefaultWildCard = new WildCard("##any", "");
 }