Ejemplo n.º 1
0
 protected override XPathItem NextItem()
 {
     if (_index <= _max)
     {
         if (_item == null)
             _item = new XQueryItem();
         _item.RawValue = _index;
         _index++;
         return _item;
     }
     return null;
 }
Ejemplo n.º 2
0
 public override XPathItem Clone()
 {
     XQueryItem clone = new XQueryItem();
     clone._value = _value;
     clone._xmlType = _xmlType;
     return clone;
 }
Ejemplo n.º 3
0
 public static object CastTo([Implict] Executive engine, object value, XQuerySequenceType destType, Type exprType)
 {
     XQueryContext context = (XQueryContext)engine.Owner;
     if (destType == XQuerySequenceType.Item)
         return value;
     if (value == Undefined.Value)
     {
         if (destType.Cardinality == XmlTypeCardinality.ZeroOrMore)
             return EmptyIterator.Shared;
         if (destType.TypeCode != XmlTypeCode.None && destType.Cardinality != XmlTypeCardinality.ZeroOrOne)
             throw new XQueryException(Properties.Resources.XPTY0004, "empty-sequence()", destType);
         return Undefined.Value;
     }
     if (destType.Cardinality == XmlTypeCardinality.One ||
         destType.Cardinality == XmlTypeCardinality.ZeroOrOne)
     {
         XPathItem res;
         XQueryNodeIterator iter = value as XQueryNodeIterator;
         if (iter != null)
         {
             iter = iter.Clone();
             if (!iter.MoveNext())
             {
                 if (destType.TypeCode != XmlTypeCode.None && 
                     (destType.Cardinality == XmlTypeCardinality.One || destType.Cardinality == XmlTypeCardinality.OneOrMore))
                     throw new XQueryException(Properties.Resources.XPTY0004, "empty-sequence()", destType);
                 return Undefined.Value;
             }
             if (exprType != null && exprType != typeof(System.String))
             {
                 if ((destType.TypeCode == XmlTypeCode.QName && iter.Current.XmlType.TypeCode != XmlTypeCode.QName) ||
                     (destType.TypeCode == XmlTypeCode.Notation && iter.Current.XmlType.TypeCode != XmlTypeCode.Notation))
                     throw new XQueryException(Properties.Resources.XPTY0004_CAST, destType);
             }
             res = iter.Current.ChangeType(destType, context);
             if (iter.MoveNext())
                 throw new XQueryException(Properties.Resources.MoreThanOneItem);
             if (destType.IsNode)
                 return res;                    
             return res.TypedValue;
         }
         XPathItem item = value as XPathItem;
         if (item == null)
             item = new XQueryItem(value);
         if (exprType != null && exprType != typeof(System.String))
         {
             if ((destType.TypeCode == XmlTypeCode.QName && item.XmlType.TypeCode != XmlTypeCode.QName) ||
                 (destType.TypeCode == XmlTypeCode.Notation && item.XmlType.TypeCode != XmlTypeCode.Notation))
                 throw new XQueryException(Properties.Resources.XPTY0004_CAST, destType);
         }
         res = item.ChangeType(destType, context);
         if (destType.IsNode)
             return res;
         return res.TypedValue;
     }
     else
         return new NodeIterator(XPathFactory.ConvertIterator(XQueryNodeIterator.Create(value), destType, context));
 }
Ejemplo n.º 4
0
 public static bool InstanceOf([Implict] Executive engine, object value, XQuerySequenceType destType)
 {
     XQueryContext context = (XQueryContext)engine.Owner;
     if (value == Undefined.Value)
         return destType.Cardinality == XmlTypeCardinality.ZeroOrOne ||
             destType.Cardinality == XmlTypeCardinality.ZeroOrMore;
     if (value == null)
         value = CoreServices.Generation.RuntimeOps.False;
     XQueryNodeIterator iter = value as XQueryNodeIterator;
     if (iter != null)
     {
         int num = 0;
         foreach (XPathItem item in iter)
         {
             if (num == 1)
             {
                 if (destType.Cardinality == XmlTypeCardinality.ZeroOrOne ||
                     destType.Cardinality == XmlTypeCardinality.One)
                     return false;
             }
             if (!destType.Match(item, context))
                 return false;
             num++;
         }
         if (num == 0)
         {
             if (destType.TypeCode != XmlTypeCode.None && (destType.Cardinality == XmlTypeCardinality.One ||
                  destType.Cardinality == XmlTypeCardinality.OneOrMore))
                 return false;
         }
         return true;
     }
     else                
     {
         if (destType.ItemType == value.GetType())
             return true;
         XPathItem item = value as XPathItem;
         if (item == null)
             item = new XQueryItem(value);
         return destType.Match(item, context);
     }
 }
Ejemplo n.º 5
0
 private IEnumerable<XPathItem> CreateEnumerator(object[] args,  MemoryPool pool,
     XQueryExprBase expr, XQueryNodeIterator baseIter)
 {
     XQueryNodeIterator iter = baseIter.Clone();
     XQueryExpr numexpr = expr as XQueryExpr;
     if (numexpr != null && numexpr.m_expr.Length == 1
         && numexpr.m_expr[0] is Integer)
     {
         Integer pos = (Integer)numexpr.m_expr[0];
         foreach (XPathItem item in iter)
         {
             if (pos == 1)
             {
                 yield return item;
                 break;
             }
             else
                 pos--;
         }
     }
     else
     {
         ContextProvider provider = new ContextProvider(iter);
         object res = Undefined.Value;
         while (iter.MoveNext())
         {
             if (m_contextSensitive || res == Undefined.Value)
                 res = expr.Execute(provider, args, pool);
             if (res == Undefined.Value)
             {
                 if (!m_contextSensitive)
                     break;
                 continue;
             }                            
             XQueryNodeIterator iter2 = res as XQueryNodeIterator;
             XPathItem item;
             if (iter2 != null)
             {
                 iter2 = iter2.Clone();
                 if (!iter2.MoveNext())
                     continue;
                 item = iter2.Current.Clone();
                 if (!item.IsNode && iter2.MoveNext())
                     throw new XQueryException(Properties.Resources.FORG0006, "fn:boolean()",
                         new XQuerySequenceType(XmlTypeCode.AnyAtomicType, XmlTypeCardinality.OneOrMore));
             }
             else
             {
                 item = res as XPathItem;
                 if (item == null)
                     item = new XQueryItem(res);
             }
             if (item.IsNode)
                 yield return iter.Current;
             else
             {
                 if (ValueProxy.IsNumeric(item.ValueType))
                 {
                     if (QueryContext.Engine.OperatorEq(iter.CurrentPosition + 1, item.TypedValue) != null)
                     {
                         yield return iter.Current;
                         if (!m_contextSensitive)
                             break;
                     }
                 }
                 else
                     if (Core.BooleanValue(item))
                         yield return iter.Current;
             }
         }                
     }
 }