Exemplo n.º 1
0
      public Send(SaxonItemFactory itemFactory) {

         this.itemFactory = itemFactory;
         this._FunctionName = new QName(XPathSmtpClient.Namespace, "send");
         this._ArgumentTypes = new[] {
            new XdmSequenceType(XdmNodeKind.Element, ' ')
         };
         this.resultType = new XdmSequenceType(XdmNodeKind.Element, ' ');
      }
Exemplo n.º 2
0
      public SendRequest(SaxonItemFactory itemFactory) {

         this.itemFactory = itemFactory;
         this._FunctionName = new QName(XPathHttpClient.Namespace, "send-request");
         this._ArgumentTypes = new[] {
            new XdmSequenceType(XdmNodeKind.Element, '?'),
            new XdmSequenceType(XdmAtomicType.BuiltInAtomicType(QName.XS_STRING), '?'),
            new XdmSequenceType(XdmAnyItemType.Instance, '*')
         };
         this.resultType = new XdmSequenceType(XdmAnyItemType.Instance, '+');
      }
Exemplo n.º 3
0
      public ValidateWithSchematron(SaxonItemFactory itemFactory) {

         this.itemFactory = itemFactory;
         this._FunctionName = new QName(ValidationModule.Namespace, "validate-with-schematron");
         this._ArgumentTypes = new[] { 
            new XdmSequenceType(XdmAtomicType.BuiltInAtomicType(QName.XS_STRING), ' '),
            new XdmSequenceType(XdmAnyNodeType.Instance, ' '),
            new XdmSequenceType(XdmAtomicType.BuiltInAtomicType(QName.XS_STRING), '?'),
            new XdmSequenceType(XdmAnyNodeType.Instance, '*'),
         };
         this.resultType = new XdmSequenceType(XdmNodeKind.Document, ' ');
      }
Exemplo n.º 4
0
      void RegisterExtensionFunctions(Processor processor, SaxonItemFactory itemFactory) {

         IEnumerable<IEnumerable<Type>> builtInFunctions = 
            new IEnumerable<Type>[] { 
               new modules.exslt.common.Index(),
               new modules.request.Index(),
               new modules.response.Index(),
               new modules.session.Index(),
               new modules.util.Index(),
               new modules.validation.Index(),
               new modules.smtpclient.Index(),
               new modules.expath.httpclient.Index(),
            };

         IEnumerable<IEnumerable<Type>> importedFunctions =
            (from m in XPathModules.GetModuleAdaptersForProcessor(this.GetType())
             let t = m.AdapterType
             let isCollection = typeof(IEnumerable<Type>).IsAssignableFrom(t)
             select (isCollection) ? 
               (IEnumerable<Type>)Activator.CreateInstance(t)
               : new Type[] { t });

         Type itemFactoryType = itemFactory.GetType();

         foreach (var types in Enumerable.Concat(builtInFunctions, importedFunctions)) {

            var functions =
               from t in types
               let ctor = t.GetConstructors().First()
               let param = ctor.GetParameters()
               let args = param.Select(p => p.ParameterType.IsAssignableFrom(itemFactoryType) ? (object)itemFactory : null).ToArray()
               select (ExtensionFunctionDefinition)ctor.Invoke(args);

            if (functions.Select(f => f.FunctionName.Uri).Distinct().Count() > 1) 
               throw new InvalidOperationException("Functions in module must belog to the same namespace.");

            foreach (var fn in functions)
               processor.RegisterExtensionFunction(fn);
         }
      }
Exemplo n.º 5
0
 public Serialize(SaxonItemFactory itemFactory)
 {
     this.itemFactory = itemFactory;
 }
Exemplo n.º 6
0
 public SaxonProcessor()
 {
     processor = new Processor();
      _ItemFactory = new SaxonItemFactory(processor);
      RegisterExtensionFunctions(processor, _ItemFactory);
 }
Exemplo n.º 7
0
        void RegisterExtensionFunctions(Processor processor, SaxonItemFactory itemFactory)
        {
            ExtensionFunctionDefinition[] precompiledFunctions =
            extensions.exslt.common.Index.GetFunctions()
            .Concat(extensions.w3c.xpath.math.Index.GetFunctions())
            .Concat(extensions.saxon.Index.GetFunctions(itemFactory))
            .ToArray();

             bool[] funcAvailable = FunctionsAvailable(precompiledFunctions.Select(d => d.FunctionName).ToArray(), processor, itemFactory);

             for (int i = 0; i < precompiledFunctions.Length; i++) {

            if (!funcAvailable[i]) {
               processor.RegisterExtensionFunction(precompiledFunctions[i]);
            }
             }

             Type itemFactoryType = itemFactory.GetType();

             var fnGen = new IntegratedExtensionFunctionGenerator();

             foreach (Type t in fnGen.Generate(XPathModules.Modules)) {

            ConstructorInfo ctor = t.GetConstructors().First();

            object[] args = ctor.GetParameters().Select(p =>
               p.ParameterType.IsAssignableFrom(typeof(SaxonProcessor)) ? (object)this
               : p.ParameterType.IsAssignableFrom(itemFactoryType) ? (object)itemFactory
               : null
            ).ToArray();

            var def = (ExtensionFunctionDefinition)ctor.Invoke(args);

            processor.RegisterExtensionFunction(def);
             }
        }
Exemplo n.º 8
0
 public Parse(SaxonItemFactory itemFactory)
 {
     this.itemFactory = itemFactory;
 }
Exemplo n.º 9
0
      public static XdmNode ToXdmNode(this XPathNavigator value, SaxonItemFactory itemFactory) {

         if (value == null) throw new ArgumentNullException("navigator");

         XdmNode node;

         if (!TryGetXdmNode(value, out node)) 
            return MoveToElementOrReturnUnchanged(value, itemFactory.CreateXdmNode(value.ReadSubtree()));

         return node;
      }
Exemplo n.º 10
0
      public static XdmNode ToXdmNode(this IXPathNavigable value, SaxonItemFactory itemFactory) {

         if (value == null) throw new ArgumentNullException("value");

         return ToXdmNode(value.CreateNavigator(), itemFactory);
      }
Exemplo n.º 11
0
      public static XdmValue ToXdmValue(this IEnumerable<XPathItem> value, SaxonItemFactory itemFactory) {

         if (value == null)
            return XdmEmptySequence.INSTANCE;

         return new XdmValue(value.Select(i => ToXdmValue(i, itemFactory)));
      }
Exemplo n.º 12
0
 public Serialize(SaxonItemFactory itemFactory)
 {
     this.itemFactory = itemFactory;
 }
Exemplo n.º 13
0
 public Parse(SaxonItemFactory itemFactory)
 {
     this.itemFactory = itemFactory;
 }
Exemplo n.º 14
0
      public static XdmItem ToXdmItem(this XPathItem value, SaxonItemFactory itemFactory) {

         if (value == null) throw new ArgumentNullException("item");

         return (value.IsNode) ?
            (XdmItem)ToXdmNode((XPathNavigator)value, itemFactory)
            : ToXdmAtomicValue(value, itemFactory);
      }
Exemplo n.º 15
0
      public static XdmItem ToXdmItem(this object value, SaxonItemFactory itemFactory) {

         if (value == null) throw new ArgumentNullException("value");

         var xdmItem = value as XdmItem;

         if (xdmItem != null)
            return xdmItem;

         var item = value as XPathItem;

         if (item != null)
            return ToXdmItem(item, itemFactory);

         var nav = value as IXPathNavigable;

         if (nav != null)
            return ToXdmNode(nav, itemFactory);

         Type type = value.GetType();
         TypeCode typeCode = Type.GetTypeCode(type);

         switch (typeCode) {
            case TypeCode.Boolean:
            case TypeCode.Int16:
            case TypeCode.Int32:
            case TypeCode.Int64:
            case TypeCode.Byte:
            case TypeCode.SByte:
            case TypeCode.UInt16:
            case TypeCode.UInt32:
            case TypeCode.UInt64:
            case TypeCode.Char:
            case TypeCode.String:
            case TypeCode.DateTime:
            case TypeCode.Decimal:
            case TypeCode.Double:
            case TypeCode.Single:
               return ToXdmAtomicValue(value, type, typeCode, itemFactory.processor);

            case TypeCode.DBNull:
            case TypeCode.Empty:
               throw new ArgumentException("value cannot be null or empty.", "value");

            default:
            case TypeCode.Object:
               break;
         }

         if (typeof(Uri).IsAssignableFrom(type))
            return ToXdmAtomicValue((Uri)value);

         if (typeof(XmlQualifiedName).IsAssignableFrom(type))
            return ToXdmAtomicValue((XmlQualifiedName)value);

         if (typeof(QName).IsAssignableFrom(type))
            return ToXdmAtomicValue((QName)value);

         return ToXdmNode(itemFactory.CreateDocument(value), itemFactory);
      }
Exemplo n.º 16
0
      public static XdmValue ToXdmValue(this IXPathNavigable value, SaxonItemFactory itemFactory) {

         if (value == null)
            return XdmEmptySequence.INSTANCE;

         return ToXdmItem(value, itemFactory);
      }
Exemplo n.º 17
0
 public static XdmValue ToXdmValue(this XPathItem value, SaxonItemFactory itemFactory) {
    return (value != null) ? (XdmValue)ToXdmItem(value, itemFactory) : XdmEmptySequence.INSTANCE;
 }
Exemplo n.º 18
0
      public static XdmValue ToXdmValue(this IEnumerable value, SaxonItemFactory itemFactory) {

         if (value == null)
            return XdmEmptySequence.INSTANCE;

         XdmValue result = XdmEmptySequence.INSTANCE;

         IEnumerator en = value.GetEnumerator();

         while (en.MoveNext())
            result = result.Append(ToXdmValue(en.Current, itemFactory));

         return result;
      }
Exemplo n.º 19
0
 public FunctionCall(SaxonItemFactory itemFactory)
 {
     this.itemFactory = itemFactory;
 }
Exemplo n.º 20
0
 public static XdmItem ToXdmItem(this IXPathNavigable value, SaxonItemFactory itemFactory) {
    return ToXdmNode(value, itemFactory);
 }
Exemplo n.º 21
0
      public static XdmValue ToXdmValue(this object value, SaxonItemFactory itemFactory) {

         if (value == null)
            return XdmEmptySequence.INSTANCE;

         // Must check for string before checking for IEnumerable
         var str = value as string;

         if (str != null)
            return ToXdmAtomicValue(str);

         var xdmVal = value as XdmValue;

         if (xdmVal != null)
            return xdmVal;

         var item = value as XPathItem;

         if (item != null)
            return ToXdmItem(item, itemFactory);

         var nav = value as IXPathNavigable;

         if (nav != null)
            return ToXdmNode(nav, itemFactory);

         Type type = value.GetType();

         if (type.IsArray || typeof(IEnumerable).IsAssignableFrom(type)) 
            return ToXdmValue((IEnumerable)value, itemFactory);

         return ToXdmItem(value, itemFactory);
      }
Exemplo n.º 22
0
 public FunctionCall(SaxonItemFactory itemFactory)
 {
     this.itemFactory = itemFactory;
 }
Exemplo n.º 23
0
 public static XdmAtomicValue ToXdmAtomicValue(this XPathItem value, SaxonItemFactory itemFactory) {
    return ToXdmAtomicValue(value, itemFactory.processor);
 }
Exemplo n.º 24
0
        public static IEnumerable <ExtensionFunctionDefinition> GetFunctions(SaxonItemFactory itemFactory)
        {
            yield return(new Parse(itemFactory));

            yield return(new Serialize(itemFactory));
        }
Exemplo n.º 25
0
      public static XdmNode ToXdmNode(this XPathItem value, SaxonItemFactory itemFactory) {

         if (value == null) throw new ArgumentNullException("value");

         if (value.IsNode)
            return ToXdmNode((XPathNavigator)value, itemFactory);

         return ToXdmNode(itemFactory.CreateDocument(value.TypedValue), itemFactory);
      }