Project

Profile

Help

How to connect?
Download (52.3 KB) Statistics
| Branch: | Tag: | Revision:

he / tags / 9.6.0.7 / hen / csource / api / Saxon.Api / Configuration.cs @ aa733b18

1
using System;
2
using System.IO;
3
using System.Xml;
4
using System.Collections;
5
using System.Collections.Specialized;
6
using System.Reflection;
7
using System.Globalization;
8
using javax.xml.transform;
9
using javax.xml.transform.stream;
10
using JClass = java.lang.Class;
11
using JBoolean = java.lang.Boolean;
12
using JResult = javax.xml.transform.Result;
13
using JSource = javax.xml.transform.Source;
14
using JProperties = java.util.Properties;
15
using JBufferedReader = java.io.BufferedReader;
16
using JStringReader = java.io.StringReader;
17
using JConfiguration = net.sf.saxon.Configuration;
18
using JFeatureKeys = net.sf.saxon.lib.FeatureKeys;
19
using JVersion = net.sf.saxon.Version;
20
using JDotNetNodeWrapper = net.sf.saxon.dotnet.DotNetNodeWrapper;
21
using JLogger = net.sf.saxon.lib.Logger;
22
using JDotNetDocumentWrapper = net.sf.saxon.dotnet.DotNetDocumentWrapper;
23
using JDotNetObjectModel = net.sf.saxon.dotnet.DotNetObjectModel;
24
using JNodeInfo = net.sf.saxon.om.NodeInfo;
25
using JDocumentInfo = net.sf.saxon.om.DocumentInfo;
26
using JSequence = net.sf.saxon.om.Sequence;
27
using JPipelineConfiguration = net.sf.saxon.@event.PipelineConfiguration;
28
using JXPathContext = net.sf.saxon.expr.XPathContext;
29
using JSequenceExtent = net.sf.saxon.value.SequenceExtent;
30
using AugmentedSource = net.sf.saxon.lib.AugmentedSource;
31
using NodeName = net.sf.saxon.om.NodeName;
32
using FingerprintedQName = net.sf.saxon.om.FingerprintedQName;
33
using Whitespace = net.sf.saxon.value.Whitespace;
34
using StaticQueryContext = net.sf.saxon.query.StaticQueryContext;
35
using JReceiver = net.sf.saxon.@event.Receiver;
36
using JTreeReceiver = net.sf.saxon.@event.TreeReceiver;
37
using JNamespaceReducer = net.sf.saxon.@event.NamespaceReducer;
38
using JValidation = net.sf.saxon.lib.Validation;
39
using JXPathException = net.sf.saxon.trans.XPathException;
40
using JProcessor = net.sf.saxon.s9api.Processor;
41
using net.sf.saxon.om;
42
using net.sf.saxon.pull;
43
using net.sf.saxon.dotnet;
44

    
45

    
46
namespace Saxon.Api
47
{
48

    
49
    /// <summary>
50
    /// The Processor class serves three purposes: it allows global Saxon configuration
51
    /// options to be set; it acts as a factory for generating XQuery, XPath, and XSLT
52
    /// compilers; and it owns certain shared resources such as the Saxon NamePool and 
53
    /// compiled schemas. This is the first object that a Saxon application should create. Once
54
    /// established, a Processor may be used in multiple threads.
55
    /// </summary>
56

    
57
    [Serializable]
58
    public class Processor 
59
    {
60
        
61
        //Transformation data variables
62
        private SchemaManager schemaManager = null;
63
        /*internal JConfiguration config;
64
       */
65
        private TextWriter textWriter = Console.Error;
66
        private JProcessor processor;
67
        /// <summary>
68
        /// Create a new Processor. This Processor will have capabilities that depend on the version
69
        /// of the software that has been loaded, and on the features that have been licensed.
70
        /// </summary>
71

    
72
        public Processor()
73
        {
74
            
75
            /*config = JConfiguration.newConfiguration();
76
            config.registerExternalObjectModel(new DotNetObjectModelDefinition());
77
            config.setProcessor(this);*/
78
            processor = new JProcessor(false);
79
            processor.getUnderlyingConfiguration().registerExternalObjectModel(new DotNetObjectModelDefinition());
80
        }
81

    
82
        /// <summary>
83
        /// Create a Processor.
84
        /// </summary>
85
        /// <param name="licensedEdition">Set to true if the Processor is to use a licensed edition of Saxon
86
        /// (that is, Saxon-PE or Saxon-EE). If true, the Processor will attempt to enable the capabilities
87
        /// of the licensed edition of Saxon, according to the version of the software that is loaded, and will
88
        /// verify the license key. If false, the Processor will load a default Configuration that gives restricted
89
        /// capability and does not require a license, regardless of which version of the software is actually being run.</param>
90

    
91
        public Processor(bool licensedEdition) 
92
            // newline needed by documentation stylesheet
93
            : this(licensedEdition, false) { }
94

    
95
        /// <summary>
96
        /// Create a Processor.
97
        /// </summary>
98
        /// <param name="licensedEdition">Set to true if the Processor is to use a licensed edition of Saxon
99
        /// (that is, Saxon-PE or Saxon-EE). If true, the Processor will attempt to enable the capabilities
100
        /// of the licensed edition of Saxon, according to the version of the software that is loaded, and will
101
        /// verify the license key. If false, the Processor will load a default Configuration that gives restricted
102
        /// capability and does not require a license, regardless of which version of the software is actually being run.</param>
103
        /// <param name="loadLocally">This option has no effect at this release.</param>
104

    
105
        public Processor(bool licensedEdition, bool loadLocally)
106
        {
107
            processor = new JProcessor(licensedEdition);
108
			processor.getUnderlyingConfiguration ().registerExternalObjectModel (new DotNetObjectModelDefinition());
109
            /*if (licensedEdition)
110
            {
111
                
112
                config = JConfiguration.newConfiguration();
113
                schemaManager = new SchemaManager(config);
114
            }
115
            else
116
            {
117
                config = new JConfiguration();
118
            }
119
            config.registerExternalObjectModel(new DotNetObjectModelDefinition());
120
            config.setProcessor(this);*/
121
        }
122

    
123
        /// <summary>
124
        /// Create a Processor, based on configuration information supplied in a configuration file.
125
        /// </summary>
126
        /// <remarks>
127
        /// Not fully supported in this release: for experimental use only.
128
        /// </remarks>
129
        /// <param name="configurationFile">A stream holding the text of the XML configuration file. Details of the file format
130
        /// can be found in the Saxon documentation.</param>
131
        /// 
132

    
133
        public Processor(Stream configurationFile)
134
        {
135
            StreamSource ss = new StreamSource(new DotNetInputStream(configurationFile));
136
            JConfiguration config = JConfiguration.readConfiguration(ss);
137
            config.registerExternalObjectModel(new DotNetObjectModelDefinition());
138
            //config.setProcessor(this);
139
            processor = new JProcessor(config);
140
        }
141

    
142

    
143
        /// <summary>
144
        /// Get the full name of the Saxon product version implemented by this Processor
145
        /// </summary>
146

    
147
        public string ProductTitle
148
        {
149
            get { return JVersion.getProductTitle(); }
150
        }
151

    
152
        /// <summary>
153
        /// Get the Saxon product version number (for example, "9.2.0.2")
154
        /// </summary>
155

    
156
        public string ProductVersion
157
        {
158
            get { return JVersion.getProductVersion(); }
159
        }
160

    
161
        /// <summary>
162
        /// Get the Saxon product edition (for example, "EE" for Enterprise Edition)
163
        /// </summary>
164
        /// 
165

    
166
        public string Edition
167
        {
168
            get { return processor.getUnderlyingConfiguration().getEditionCode(); }
169
        }
170

    
171

    
172

    
173
        /// <summary>
174
        /// Gets the SchemaManager for the Processor. Returns null
175
        /// if the Processor is not schema-aware.
176
        /// </summary>
177

    
178
        public SchemaManager SchemaManager
179
        {
180
            get {
181
                if (schemaManager == null)
182
                {
183
                    schemaManager = new SchemaManager(this);
184
                }
185
                
186
                return schemaManager; }
187
        }
188

    
189
        /// <summary>
190
        /// An XmlResolver, which will be used while compiling and running queries, 
191
        /// XPath expressions, and stylesheets, if no other XmlResolver is nominated
192
        /// </summary>
193
        /// <remarks>
194
        /// <para>By default an <c>XmlUrlResolver</c> is used. This means that the responsibility
195
        /// for resolving and dereferencing URIs rests with the .NET platform, not with the
196
        /// GNU Classpath.</para>
197
        /// <para>When Saxon invokes a user-written <c>XmlResolver</c>, the <c>GetEntity</c> method
198
        /// may return any of: a <c>System.IO.Stream</c>; a <c>System.IO.TextReader</c>; or a
199
        /// <c>java.xml.transform.Source</c>.</para>
200
        /// </remarks>
201

    
202
        public XmlResolver XmlResolver
203
        {
204
            get
205
            {
206
				if (processor.getUnderlyingConfiguration ().getURIResolver () is DotNetURIResolver) {
207
					return ((DotNetURIResolver)processor.getUnderlyingConfiguration ().getURIResolver ()).getXmlResolver ();
208
				} else {
209
					return new XmlUrlResolver();
210
				}
211
            }
212
            set
213
            {
214
                processor.getUnderlyingConfiguration().setURIResolver(new DotNetURIResolver(value));
215
            }
216
        }
217

    
218

    
219
        /// <summary>
220
        /// A TextWriter used to get and set the errors from the standard output Writer
221
        /// </summary>
222
        /// <remarks>
223
        /// <para>By default the <c>Console.Error</c> is used on the .NET platform.</para>
224
        /// <para>A user can supply their own TextWriter to redirect error messages from the standard output.</para>
225
        /// </remarks>
226
        public TextWriter ErrorWriter 
227
        {
228

    
229
            get 
230
            {
231
                return textWriter;
232
            
233
            }
234
            set 
235
            {
236
                textWriter = value;
237
				StandardLogger logger = new StandardLogger (value); 
238
				processor.getUnderlyingConfiguration ().setLogger (logger);
239
            }
240
        
241
        
242
        }
243

    
244
        /// <summary>
245
        /// Create a new <c>DocumentBuilder</c>, which may be used to build XDM documents from
246
        /// a variety of sources.
247
        /// </summary>
248
        /// <returns>A new <c>DocumentBuilder</c></returns>
249

    
250
        public DocumentBuilder NewDocumentBuilder()
251
        {
252
            DocumentBuilder builder = new DocumentBuilder(this);
253
            builder.XmlResolver = XmlResolver;
254
            return builder;
255
        }
256

    
257
        /// <summary>
258
        /// Create a new XQueryCompiler, which may be used to compile XQuery queries.
259
        /// </summary>
260
        /// <remarks>
261
        /// The returned XQueryCompiler retains a live link to the Processor, and
262
        /// may be affected by subsequent changes to the Processor.
263
        /// </remarks>
264
        /// <returns>A new XQueryCompiler</returns>
265

    
266
        public XQueryCompiler NewXQueryCompiler()
267
        {
268
            return new XQueryCompiler(this);
269
        }
270

    
271
        /// <summary>
272
        /// Create a new XsltCompiler, which may be used to compile XSLT stylesheets.
273
        /// </summary>
274
        /// <remarks>
275
        /// The returned XsltCompiler retains a live link to the Processor, and
276
        /// may be affected by subsequent changes to the Processor.
277
        /// </remarks>
278
        /// <returns>A new XsltCompiler</returns>
279

    
280
        public XsltCompiler NewXsltCompiler()
281
        {
282
            return new XsltCompiler(this);
283
        }
284

    
285
        /// <summary>
286
        /// Create a new XPathCompiler, which may be used to compile XPath expressions.
287
        /// </summary>
288
        /// <remarks>
289
        /// The returned XPathCompiler retains a live link to the Processor, and
290
        /// may be affected by subsequent changes to the Processor.
291
        /// </remarks>
292
        /// <returns>A new XPathCompiler</returns>
293

    
294
        public XPathCompiler NewXPathCompiler()
295
        {
296
            return new XPathCompiler(this);
297
        }
298

    
299
        /// <summary>
300
        /// Create a Serializer
301
        /// </summary>
302
        ///  <returns> a new Serializer </returns>
303
        public Serializer NewSerializer() {
304
            Serializer s = new Serializer();
305
            s.SetProcessor(this);
306
            return s;
307
        }
308

    
309
        /// <summary>
310
        /// Create a Serializer initialized to write to a given Writer.
311
        /// Closing the writer after use is the responsibility of the caller.
312
        /// </summary>
313
        /// <param name="textWriter">writer The TextWriter to which the Serializer will write</param>
314
        ///  <returns> a new Serializer </returns>
315
        public Serializer NewSerializer(TextWriter textWriter)
316
        {
317
            Serializer s = new Serializer();
318
            s.SetProcessor(this);
319
            s.SetOutputWriter(textWriter);
320
            return s;
321
        }
322

    
323
        /// <summary>
324
        /// Create a Serializer initialized to write to a given OutputStream.
325
        /// Closing the output stream after use is the responsibility of the caller.
326
        /// </summary>
327
        /// <param name="stream">stream The OutputStream to which the Serializer will write</param>
328
        ///  <returns> a new Serializer </returns>
329
        public Serializer NewSerializer(Stream stream)
330
        {
331
            Serializer s = new Serializer();
332
            s.SetProcessor(this);
333
            s.SetOutputStream(stream);
334
            return s;
335
        }
336

    
337
        /// <summary>
338
        /// The XML version used in this <c>Processor</c> (for example, this determines what characters
339
        /// are permitted in a name)
340
        /// </summary>
341
        /// <remarks>
342
        /// The value must be 1.0 or 1.1, as a <c>decimal</c>. The default version is currently 1.0, but may
343
        /// change in the future.
344
        /// </remarks>
345

    
346
        public decimal XmlVersion
347
        {
348
            get
349
            {
350
                return (processor.getUnderlyingConfiguration().getXMLVersion() == JConfiguration.XML10 ? 1.0m : 1.1m);
351
            }
352
            set
353
            {
354
                if (value == 1.0m)
355
                {
356
                    processor.setXmlVersion("1.0");
357
                }
358
                else if (value == 1.1m)
359
                {
360
                    processor.setXmlVersion("1.1");
361
                }
362
                else
363
                {
364
                    throw new ArgumentException("Invalid XML version: " + value);
365
                }
366
            }
367
        }
368

    
369
        /// <summary>
370
        /// Register a named collection. A collection is identified by a URI (the collection URI),
371
        /// and its content is represented by an <c>IEnumerable</c> that enumerates the contents
372
        /// of the collection. The values delivered by this enumeration are Uri values, which 
373
        /// can be mapped to nodes using the registered <c>XmlResolver</c>.
374
        /// </summary>
375
        /// <param name="collectionUri">The URI used to identify the collection in a call
376
        /// of the XPath <c>collection()</c> function. The default collection is registered
377
        /// by supplying null as the value of this argument (this is the collection returned
378
        /// when the XPath <c>collection()</c> function is called with no arguments).</param> 
379
        /// <param name="contents">An enumerable object that represents the contents of the
380
        /// collection, as a sequence of document URIs. The enumerator returned by this
381
        /// IEnumerable object must return instances of the Uri class.</param>
382
        /// <remarks>
383
        /// <para>Collections should be stable: that is, two calls to retrieve the same collection URI
384
        /// should return the same sequence of document URIs. This requirement is imposed by the
385
        /// W3C specifications, but in the case of a user-defined collection it is not enforced by
386
        /// the Saxon product.</para>
387
        /// <para>A collection may be "unregistered" by providing null as the value of the
388
        /// contents argument. A collection may be replaced by specifying the URI of an existing
389
        /// collection.</para>
390
        /// <para>Collections registered with a processor are available to all queries and stylesheets
391
        /// running under the control of that processor. Collections should not normally be registered
392
        /// while queries and transformations are in progress.</para>
393
        /// </remarks>
394
        /// 
395

    
396
        public void RegisterCollection(Uri collectionUri, IEnumerable contents)
397
        {
398
            String u = (collectionUri == null ? null : collectionUri.ToString());
399
            DotNetCollectionURIResolver resolver =
400
                (DotNetCollectionURIResolver)processor.getUnderlyingConfiguration().getCollectionURIResolver();
401
            resolver.registerCollection(u, contents);
402
        }
403

    
404
        /// <summary>
405
        /// Register an extension function with the Processor
406
        /// </summary>
407
        /// <param name="function">
408
        /// An object that defines the extension function, including its name, arity, arguments types, and
409
        /// a reference to the class that implements the extension function call.
410
        /// </param>
411

    
412
        public void RegisterExtensionFunction(ExtensionFunctionDefinition function)
413
        {
414
            WrappedExtensionFunctionDefinition f = new WrappedExtensionFunctionDefinition(function);
415
            processor.registerExtensionFunction(f);
416
        }
417

    
418
        /// <summary>
419
        /// Copy an XdmValue to an XmlDestination
420
        /// </summary>
421
        /// <remarks>
422
        /// This method can be used to copy any kind of <c>XdmValue</c> to any kind
423
        /// of <c>XdmDestination</c>. The supplied <c>XdmValue</c> is first converted
424
        /// to an XML document according to the rules of the XSLT/XQuery serialization
425
        /// specification (for example, if the <c>XdmValue</c> is a sequence of atomic
426
        /// values, they will be turned in a text node in which the values are converted
427
        /// to strings and separated by single spaces). The resulting document is then
428
        /// written to the supplied <c>XmlDestination</c>.</remarks>
429
        /// <param name="sequence">The value to be written</param>
430
        /// <param name="destination">The destination to which the value should be written</param>
431
        /// 
432

    
433
        public void WriteXdmValue(XdmValue sequence, XmlDestination destination)
434
        {
435
            try
436
            {
437
				JPipelineConfiguration pipe = processor.getUnderlyingConfiguration().makePipelineConfiguration();
438
				JResult result = destination.GetReceiver(pipe);
439
				JReceiver r = processor.getUnderlyingConfiguration().getSerializerFactory().getReceiver(result,
440
                    pipe, destination.GetOutputProperties());
441
                r = new JNamespaceReducer(r);
442
                JTreeReceiver tree = new JTreeReceiver(r);
443
                tree.open();
444
                tree.startDocument(0);
445
                foreach (XdmItem it in sequence)
446
                {
447
                    tree.append((Item)it.Unwrap(), 0, JNodeInfo.__Fields.ALL_NAMESPACES);
448
                }
449
                tree.endDocument();
450
                tree.close();
451
            } catch(JXPathException err) {
452
                throw new DynamicError(err);
453
            }
454
        }
455

    
456

    
457
        /// <summary>
458
        /// The underlying Configuration object in the Saxon implementation
459
        /// </summary>
460
        /// <remarks>
461
        /// <para>This property provides access to internal methods in the Saxon engine that are
462
        /// not specifically exposed in the .NET API. In general these methods should be
463
        /// considered to be less stable than the classes in the Saxon.Api namespace.</para> 
464
        /// <para>The internal methods follow
465
        /// Java naming conventions rather than .NET conventions.</para>
466
        /// <para>Information about the returned object (and the objects it provides access to)
467
        /// is included in the Saxon JavaDoc docmentation, available 
468
        /// <link href="http://www.saxonica.com/documentation/javadoc/index.html">online</link>.
469
        /// </para>
470
        /// </remarks>
471

    
472
        public net.sf.saxon.Configuration Implementation
473
        {
474
            get { return processor.getUnderlyingConfiguration(); }
475
        }
476

    
477
        public net.sf.saxon.s9api.Processor JProcessor
478
        {
479
            get { return processor;}
480
        }
481

    
482
        /// <summary>
483
        /// Set a configuration property
484
        /// </summary>
485
        /// <remarks>
486
        /// <para>This method provides the ability to set named properties of the configuration.
487
        /// The property names are set as strings, whose values can be found in the Java
488
        /// class <c>net.sf.saxon.FeatureKeys</c>. The property values are always strings. 
489
        /// Properties whose values are other types are not available via this interface:
490
        /// however all properties have an effective equivalent whose value is a string.
491
        /// Note that on/off properties are set using the strings "true" and "false".</para>
492
        /// <para><i>Method added in Saxon 9.1</i></para>
493
        /// </remarks>
494
        /// <param name="name">The property name</param>
495
        /// <param name="value">The property value</param>
496

    
497
        public void SetProperty(String name, String value)
498
        {
499
            processor.setConfigurationProperty(name, value);
500
        }
501

    
502
        /// <summary>
503
        /// Get the value of a configuration property
504
        /// </summary>
505
        /// <remarks>
506
        /// <para>This method provides the ability to get named properties of the configuration.
507
        /// The property names are supplied as strings, whose values can be found in the Java
508
        /// class <c>net.sf.saxon.FeatureKeys</c>. The property values are always returned as strings. 
509
        /// Properties whose values are other types are returned by converting the value to a string.
510
        /// Note that on/off properties are returned using the strings "true" and "false".</para>
511
        /// <para><i>Method added in Saxon 9.1</i></para>
512
        /// </remarks>
513
        /// <param name="name">The property name</param>
514
        /// <returns>The property value, as a string; or null if the property is unset.</returns>
515

    
516
        public String GetProperty(String name)
517
        {
518
            Object obj = processor.getConfigurationProperty(name);
519
            return (obj == null ? null : obj.ToString());
520
        }
521

    
522
    }
523

    
524
    /// <summary>
525
    /// The <c>DocumentBuilder</c> class enables XDM documents to be built from various sources.
526
    /// The class is always instantiated using the <c>NewDocumentBuilder</c> method
527
    /// on the <c>Processor</c> object.
528
    /// </summary>
529

    
530
    [Serializable]
531
    public class DocumentBuilder
532
    {
533

    
534
        private Processor processor;
535
        private JConfiguration config;
536
        private XmlResolver xmlResolver;
537
        private SchemaValidationMode validation;
538
        private bool dtdValidation;
539
        private bool lineNumbering;
540
        private WhitespacePolicy whitespacePolicy;
541
        private Uri baseUri;
542
        private QName topLevelElement;
543
        private TreeModel treeModel = TreeModel.Unspecified;
544
		private XQueryExecutable projectionQuery;
545

    
546
        internal DocumentBuilder(Processor processor)
547
        {
548
            this.processor = processor;
549
            this.config = processor.Implementation;
550
            this.xmlResolver = new XmlUrlResolver();
551
        }
552

    
553
        /// <summary>
554
        /// An XmlResolver, which will be used to resolve URIs of documents being loaded
555
        /// and of references to external entities within those documents (including any external DTD).
556
        /// </summary>
557
        /// <remarks>
558
        /// <para>By default an <c>XmlUrlResolver</c> is used. This means that the responsibility
559
        /// for resolving and dereferencing URIs rests with the .NET platform (and not with the
560
        /// GNU Classpath).</para>
561
        /// <para>When Saxon invokes a user-written <c>XmlResolver</c>, the <c>GetEntity</c> method
562
        /// may return any of: a <c>System.IO.Stream</c>; a <c>System.IO.TextReader</c>; or a
563
        /// <c>java.xml.transform.Source</c>. However, if the <c>XmlResolver</c> is called
564
        /// by the XML parser to resolve external entity references, then it must return an 
565
        /// instance of <c>System.IO.Stream</c>.</para>
566
        /// </remarks>
567

    
568
        public XmlResolver XmlResolver
569
        {
570
            get
571
            {
572
                return xmlResolver;
573
            }
574
            set
575
            {
576
                xmlResolver = value;
577
            }
578
        }
579

    
580
        /// <summary>
581
        /// Determines whether line numbering is enabled for documents loaded using this
582
        /// <c>DocumentBuilder</c>.
583
        /// </summary>
584
        /// <remarks>
585
        /// <para>By default, line numbering is disabled.</para>
586
        /// <para>Line numbering is not available for all kinds of source: in particular,
587
        /// it is not available when loading from an existing XmlDocument.</para>
588
        /// <para>The resulting line numbers are accessible to applications using the
589
        /// extension function saxon:line-number() applied to a node.</para>  
590
        /// <para>Line numbers are maintained only for element nodes; the line number
591
        /// returned for any other node will be that of the most recent element.</para> 
592
        /// </remarks>
593

    
594
        public bool IsLineNumbering
595
        {
596
            get
597
            {
598
                return lineNumbering;
599
            }
600
            set
601
            {
602
                lineNumbering = value;
603
            }
604
        }
605

    
606
        /// <summary>
607
        /// Determines whether schema validation is applied to documents loaded using this
608
        /// <c>DocumentBuilder</c>, and if so, whether it is strict or lax.
609
        /// </summary>
610
        /// <remarks>
611
        /// <para>By default, no schema validation takes place.</para>
612
        /// <para>This option requires the schema-aware version of the Saxon product (Saxon-SA).</para>
613
        /// </remarks>
614

    
615
        public SchemaValidationMode SchemaValidationMode
616
        {
617
            get
618
            {
619
                return validation;
620
            }
621
            set
622
            {
623
                validation = value;
624
            }
625
        }
626

    
627
        /// <summary>
628
        /// The required name of the top level element in a document instance being validated
629
        /// against a schema.
630
        /// </summary>
631
        /// <remarks>
632
        /// <para>If this property is set, and if schema validation is requested, then validation will
633
        /// fail unless the outermost element of the document has the required name.</para>
634
        /// <para>This option requires the schema-aware version of the Saxon product (Saxon-SA).</para>
635
        /// </remarks> 
636

    
637
        public QName TopLevelElementName
638
        {
639
            get
640
            {
641
                return topLevelElement;
642
            }
643
            set
644
            {
645
                topLevelElement = value;
646
            }
647
        }
648

    
649
        /// <summary>
650
        /// Determines whether DTD validation is applied to documents loaded using this
651
        /// <c>DocumentBuilder</c>.
652
        /// </summary>
653
        /// <remarks>
654
        ///
655
        /// <para>By default, no DTD validation takes place.</para>
656
        /// 
657
        /// </remarks>
658

    
659
        public bool DtdValidation
660
        {
661
            get
662
            {
663
                return dtdValidation;
664
            }
665
            set
666
            {
667
                dtdValidation = value;
668
            }
669
        }
670

    
671
        /// <summary>
672
        /// Determines the whitespace stripping policy applied when loading a document
673
        /// using this <c>DocumentBuilder</c>.
674
        /// </summary>
675
        /// <remarks>
676
        /// <para>By default, whitespace text nodes appearing in element-only content
677
        /// are stripped, and all other whitespace text nodes are retained.</para>
678
        /// </remarks>
679

    
680
        public WhitespacePolicy WhitespacePolicy
681
        {
682
            get
683
            {
684
                return whitespacePolicy;
685
            }
686
            set
687
            {
688
                whitespacePolicy = value;
689
            }
690
        }
691

    
692
        ///<summary>
693
        /// The Tree Model implementation to be used for the constructed document. By default
694
        /// the TinyTree is used. The main reason for using the LinkedTree alternative is if
695
        /// updating is required (the TinyTree is not updateable).
696
        ///</summary>
697

    
698
        public TreeModel TreeModel
699
        {
700
            get
701
            {
702
                return treeModel;
703
            }
704
            set
705
            {
706
                treeModel = value;
707
            }
708
        }
709

    
710
        /// <summary>
711
        /// The base URI of a document loaded using this <c>DocumentBuilder</c>.
712
        /// This is used for resolving any relative URIs appearing
713
        /// within the document, for example in references to DTDs and external entities.
714
        /// </summary>
715
        /// <remarks>
716
        /// This information is required when the document is loaded from a source that does not
717
        /// provide an intrinsic URI, notably when loading from a Stream or a TextReader.
718
        /// </remarks>
719

    
720

    
721
        public Uri BaseUri
722
        {
723
            get { return baseUri; }
724
            set { baseUri = value; }
725
        }
726

    
727

    
728
		///<summary>
729
     	/// Set a compiled query to be used for implementing document projection. The effect of using
730
     	/// this option is that the tree constructed by the DocumentBuilder contains only those parts
731
    	/// of the source document that are needed to answer this query. Running this query against
732
    	/// the projected document should give the same results as against the raw document, but the
733
     	/// projected document typically occupies significantly less memory. It is permissible to run
734
    	/// other queries against the projected document, but unless they are carefully chosen, they
735
    	/// will give the wrong answer, because the document being used is different from the original.
736
		/// </summary>
737
    	/// <para>The query should be written to use the projected document as its initial context item.
738
    	/// For example, if the query is <code>//ITEM[COLOR='blue')</code>, then only <code>ITEM</code>
739
    	/// elements and their <code>COLOR</code> children will be retained in the projected document.</para>
740
    	/// <para>This facility is only available in Saxon-EE; if the facility is not available,
741
    	/// calling this method has no effect.</para>
742
		///<para>query the compiled query used to control document projection</para>
743
    	/// @since 9.6
744
    
745

    
746
		public XQueryExecutable DocumentProjectionQuery {
747
			get { return projectionQuery;}
748
			set { projectionQuery = value;}
749

    
750
		}
751

    
752
        /// <summary>
753
        /// Load an XML document, retrieving it via a URI.
754
        /// </summary>
755
        /// <remarks>
756
        /// <para>Note that the type <c>Uri</c> requires an absolute URI.</para>
757
        /// <para>The URI is dereferenced using the registered <c>XmlResolver</c>.</para>
758
        /// <para>This method takes no account of any fragment part in the URI.</para>
759
        /// <para>The <c>role</c> passed to the <c>GetEntity</c> method of the <c>XmlResolver</c> 
760
        /// is "application/xml", and the required return type is <c>System.IO.Stream</c>.</para>
761
        /// <para>The document located via the URI is parsed using the <c>System.Xml</c> parser.</para>
762
        /// <para>Note that the Microsoft <c>System.Xml</c> parser does not report whether attributes are
763
        /// defined in the DTD as being of type <c>ID</c> and <c>IDREF</c>. This is true whether or not
764
        /// DTD-based validation is enabled. This means that such attributes are not accessible to the 
765
        /// <c>id()</c> and <c>idref()</c> functions.</para>
766
        /// </remarks>
767
        /// <param name="uri">The URI identifying the location where the document can be
768
        /// found. This will also be used as the base URI of the document (regardless
769
        /// of the setting of the <c>BaseUri</c> property).</param>
770
        /// <returns>An <c>XdmNode</c>. This will be
771
        ///  the document node at the root of the tree of the resulting in-memory document. 
772
        /// </returns>
773

    
774
        public XdmNode Build(Uri uri)
775
        {
776
            Object obj = XmlResolver.GetEntity(uri, "application/xml", Type.GetType("System.IO.Stream"));
777
            if (obj is Stream)
778
            {
779
                try
780
                {
781
                    return Build((Stream)obj, uri);
782
                }
783
                finally
784
                {
785
                    ((Stream)obj).Close();
786
                }
787
            }
788
            else
789
            {
790
                throw new ArgumentException("Invalid type of result from XmlResolver.GetEntity: " + obj);
791
            }
792
        }
793

    
794
        /// <summary>
795
        /// Load an XML document supplied as raw (lexical) XML on a Stream.
796
        /// </summary>
797
        /// <remarks>
798
        /// <para>The document is parsed using the Microsoft <c>System.Xml</c> parser if the
799
        /// "http://saxon.sf.net/feature/preferJaxpParser" property on the <c>Processor</c> is set to false;
800
        /// otherwise it is parsed using the Apache Xerces XML parser.</para>
801
        /// <para>Before calling this method, the <c>BaseUri</c> property must be set to identify the
802
        /// base URI of this document, used for resolving any relative URIs contained within it.</para>
803
        /// <para>Note that the Microsoft <c>System.Xml</c> parser does not report whether attributes are
804
        /// defined in the DTD as being of type <c>ID</c> and <c>IDREF</c>. This is true whether or not
805
        /// DTD-based validation is enabled. This means that such attributes are not accessible to the 
806
        /// <c>id()</c> and <c>idref()</c> functions.</para>         
807
        /// </remarks>
808
        /// <param name="input">The Stream containing the XML source to be parsed</param>
809
        /// <returns>An <c>XdmNode</c>, the document node at the root of the tree of the resulting
810
        /// in-memory document
811
        /// </returns>
812

    
813
        public XdmNode Build(Stream input)
814
        {
815
            if (baseUri == null)
816
            {
817
                throw new ArgumentException("No base URI supplied");
818
            }
819
            return Build(input, baseUri);
820
        }
821

    
822
        // Build a document from a given stream, with the base URI supplied
823
        // as an extra argument
824

    
825
        internal XdmNode Build(Stream input, Uri baseUri)
826
        {
827
            Source source;
828
            if (processor.GetProperty("http://saxon.sf.net/feature/preferJaxpParser") == "true")
829
            {
830
                source = new StreamSource(new DotNetInputStream(input), baseUri.ToString());
831
                source = AugmentedSource.makeAugmentedSource(source);
832
                ((AugmentedSource)source).setEntityResolver(new DotNetURIResolver(XmlResolver));
833
            }
834
            else
835
            {
836

    
837
                XmlReaderSettings settings = new XmlReaderSettings();
838
				settings.DtdProcessing = DtdProcessing.Parse;   // must expand entity references
839

    
840

    
841
                //((XmlTextReader)parser).Normalization = true;
842
                switch (whitespacePolicy)
843
                {
844
                    case WhitespacePolicy.PreserveAll:
845
                        settings.IgnoreWhitespace = false;
846
                        //((XmlTextReader)parser).WhitespaceHandling = WhitespaceHandling.All;
847
                        break;
848
                    case WhitespacePolicy.StripAll:
849
                        settings.IgnoreWhitespace = true;
850
                        //((XmlTextReader)parser).WhitespaceHandling = WhitespaceHandling.None;
851
                        break;
852
                    case WhitespacePolicy.StripIgnorable:
853
                        settings.IgnoreWhitespace = true;
854
                        //((XmlTextReader)parser).WhitespaceHandling = WhitespaceHandling.Significant;
855
                        break;
856
                }
857
                if (xmlResolver != null)
858
                {
859
                    settings.XmlResolver = xmlResolver;
860
                }
861
                
862
                settings.ValidationType = (dtdValidation ? ValidationType.DTD : ValidationType.None);
863
                
864
                XmlReader parser = XmlReader.Create(input, settings, baseUri.ToString());
865
                source = new PullSource(new DotNetPullProvider(parser));
866
                source.setSystemId(baseUri.ToString());
867
            }
868
            source = augmentSource(source);
869
            DocumentInfo doc = config.buildDocument(source);
870
            return (XdmNode)XdmValue.Wrap(doc);
871
        }
872

    
873
        /// <summary>
874
        /// Load an XML document supplied using a TextReader.
875
        /// </summary>
876
        /// <remarks>
877
        /// <para>The document is parsed using the Microsoft <c>System.Xml</c> parser if the
878
        /// "http://saxon.sf.net/feature/preferJaxpParser" property on the <c>Processor</c> is set to false;
879
        /// otherwise it is parsed using the Apache Xerces XML parser.</para>
880
        /// <para>Before calling this method, the <c>BaseUri</c> property must be set to identify the
881
        /// base URI of this document, used for resolving any relative URIs contained within it.</para>
882
        /// <para>Note that the Microsoft <c>System.Xml</c> parser does not report whether attributes are
883
        /// defined in the DTD as being of type <c>ID</c> and <c>IDREF</c>. This is true whether or not
884
        /// DTD-based validation is enabled. This means that such attributes are not accessible to the 
885
        /// <c>id()</c> and <c>idref()</c> functions.</para>         
886
        /// </remarks>
887
        /// <param name="input">The <c>TextReader</c> containing the XML source to be parsed</param>
888
        /// <returns>An <c>XdmNode</c>, the document node at the root of the tree of the resulting
889
        /// in-memory document
890
        /// </returns>
891

    
892
        public XdmNode Build(TextReader input)
893
        {
894
            if (baseUri == null)
895
            {
896
                throw new ArgumentException("No base URI supplied");
897
            }
898
            return Build(input, baseUri);
899
        }
900

    
901
        // Build a document from a given stream, with the base URI supplied
902
        // as an extra argument
903

    
904
        internal XdmNode Build(TextReader input, Uri baseUri)
905
        {
906
            Source source;
907
            if (processor.GetProperty("http://saxon.sf.net/feature/preferJaxpParser") == "true")
908
            {
909
                source = new StreamSource(new DotNetReader(input), baseUri.ToString());
910
                source = AugmentedSource.makeAugmentedSource(source);
911
                ((AugmentedSource)source).setEntityResolver(new DotNetURIResolver(XmlResolver));
912
            }
913
            else
914
            {
915

    
916
                XmlReaderSettings settings = new XmlReaderSettings();
917
				settings.DtdProcessing = DtdProcessing.Parse;   // must expand entity references
918

    
919

    
920
                //((XmlTextReader)parser).Normalization = true;
921
                switch (whitespacePolicy)
922
                {
923
                    case WhitespacePolicy.PreserveAll:
924
                        settings.IgnoreWhitespace = false;
925
                        //((XmlTextReader)parser).WhitespaceHandling = WhitespaceHandling.All;
926
                        break;
927
                    case WhitespacePolicy.StripAll:
928
                        settings.IgnoreWhitespace = true;
929
                        //((XmlTextReader)parser).WhitespaceHandling = WhitespaceHandling.None;
930
                        break;
931
                    case WhitespacePolicy.StripIgnorable:
932
                        settings.IgnoreWhitespace = true;
933
                        //((XmlTextReader)parser).WhitespaceHandling = WhitespaceHandling.Significant;
934
                        break;
935
                }
936
                if (xmlResolver != null)
937
                {
938
                    settings.XmlResolver = xmlResolver;
939
                }
940

    
941
                settings.ValidationType = (dtdValidation ? ValidationType.DTD : ValidationType.None);
942

    
943
                XmlReader parser = XmlReader.Create(input, settings, baseUri.ToString());
944
                source = new PullSource(new DotNetPullProvider(parser));
945
                source.setSystemId(baseUri.ToString());
946
            }
947
            source = augmentSource(source);
948
            DocumentInfo doc = config.buildDocument(source);
949
            return (XdmNode)XdmValue.Wrap(doc);
950
        }
951

    
952
        private Source augmentSource(Source source)
953
        {
954
            if (validation != SchemaValidationMode.None)
955
            {
956
                source = AugmentedSource.makeAugmentedSource(source);
957
                if (validation == SchemaValidationMode.Strict)
958
                {
959
                    ((AugmentedSource)source).setSchemaValidationMode(JValidation.STRICT);
960
                }
961
                else if (validation == SchemaValidationMode.Lax)
962
                {
963
                    ((AugmentedSource)source).setSchemaValidationMode(JValidation.LAX);
964
                }
965
                else if (validation == SchemaValidationMode.None)
966
                {
967
                    ((AugmentedSource)source).setSchemaValidationMode(JValidation.STRIP);
968
                }
969
                else if (validation == SchemaValidationMode.Preserve)
970
                {
971
                    ((AugmentedSource)source).setSchemaValidationMode(JValidation.PRESERVE);
972
                }
973
            }
974
            if (topLevelElement != null)
975
            {
976
                source = AugmentedSource.makeAugmentedSource(source);
977
                ((AugmentedSource)source).setTopLevelElement(
978
                    new FingerprintedQName(
979
                        topLevelElement.Prefix, topLevelElement.Uri, topLevelElement.LocalName));
980
            }
981

    
982
            if (whitespacePolicy != WhitespacePolicy.PreserveAll)
983
            {
984
                source = AugmentedSource.makeAugmentedSource(source);
985
                if (whitespacePolicy == WhitespacePolicy.StripIgnorable)
986
                {
987
                    ((AugmentedSource)source).setStripSpace(Whitespace.IGNORABLE);
988
                }
989
                else
990
                {
991
                    ((AugmentedSource)source).setStripSpace(Whitespace.ALL);
992
                }
993
            }
994
            if (treeModel != TreeModel.Unspecified)
995
            {
996
                source = AugmentedSource.makeAugmentedSource(source);
997
                if (treeModel == TreeModel.TinyTree)
998
                {
999
                    ((AugmentedSource)source).setModel(net.sf.saxon.om.TreeModel.TINY_TREE);
1000
                }
1001
                else if (treeModel == TreeModel.TinyTreeCondensed)
1002
                {
1003
                    ((AugmentedSource)source).setModel(net.sf.saxon.om.TreeModel.TINY_TREE_CONDENSED);
1004
                }
1005
                else
1006
                {
1007
                    ((AugmentedSource)source).setModel(net.sf.saxon.om.TreeModel.LINKED_TREE);
1008
                }
1009
            }
1010
            if (lineNumbering)
1011
            {
1012
                source = AugmentedSource.makeAugmentedSource(source);
1013
                ((AugmentedSource)source).setLineNumbering(true);
1014
            }
1015
            if (dtdValidation)
1016
            {
1017
                source = AugmentedSource.makeAugmentedSource(source);
1018
                ((AugmentedSource)source).setDTDValidationMode(JValidation.STRICT);
1019
            }
1020
			if (projectionQuery != null) {
1021
				net.sf.saxon.query.XQueryExpression exp = projectionQuery.getUnderlyingCompiledQuery();
1022
				net.sf.saxon.@event.FilterFactory ff = config.makeDocumentProjector(exp);
1023
				if (ff != null) {
1024
					source = AugmentedSource.makeAugmentedSource(source);
1025
					((AugmentedSource)source).addFilter (ff);
1026
				}
1027
			}
1028
            return source;
1029
        }
1030

    
1031
        /// <summary>
1032
        /// Load an XML document, delivered using an XmlReader.
1033
        /// </summary>
1034
        /// <remarks>
1035
        /// <para>The XmlReader is responsible for parsing the document; this method builds a tree
1036
        /// representation of the document (in an internal Saxon format) and returns its document node.
1037
        /// The XmlReader is not required to perform validation but it must expand any entity references.
1038
        /// Saxon uses the properties of the <c>XmlReader</c> as supplied.</para>
1039
        /// <para>Use of a plain <c>XmlTextReader</c> is discouraged, because it does not expand entity
1040
        /// references. This should only be used if you know in advance that the document will contain
1041
        /// no entity references (or perhaps if your query or stylesheet is not interested in the content
1042
        /// of text and attribute nodes). Instead, with .NET 1.1 use an <c>XmlValidatingReader</c> (with <c>ValidationType</c>
1043
        /// set to <c>None</c>). The constructor for <c>XmlValidatingReader</c> is obsolete in .NET 2.0,
1044
        /// but the same effect can be achieved by using the <c>Create</c> method of <c>XmlReader</c> with
1045
        /// appropriate <c>XmlReaderSettings</c></para>
1046
        /// <para>Conformance with the W3C specifications requires that the <c>Normalization</c> property
1047
        /// of an <c>XmlTextReader</c> should be set to <c>true</c>. However, Saxon does not insist
1048
        /// on this.</para>
1049
        /// <para>If the <c>XmlReader</c> performs schema validation, Saxon will ignore any resulting type
1050
        /// information. Type information can only be obtained by using Saxon's own schema validator, which
1051
        /// will be run if the <c>SchemaValidationMode</c> property is set to <c>Strict</c> or <c>Lax</c></para>
1052
        /// <para>Note that the Microsoft <c>System.Xml</c> parser does not report whether attributes are
1053
        /// defined in the DTD as being of type <c>ID</c> and <c>IDREF</c>. This is true whether or not
1054
        /// DTD-based validation is enabled. This means that such attributes are not accessible to the 
1055
        /// <c>id()</c> and <c>idref()</c> functions.</para>
1056
        /// <para>Note that setting the <c>XmlResolver</c> property of the <c>DocumentBuilder</c>
1057
        /// has no effect when this method is used; if an <c>XmlResolver</c> is required, it must
1058
        /// be set on the <c>XmlReader</c> itself.</para>
1059
        /// </remarks>
1060
        /// <param name="reader">The XMLReader that supplies the parsed XML source</param>
1061
        /// <returns>An <c>XdmNode</c>, the document node at the root of the tree of the resulting
1062
        /// in-memory document
1063
        /// </returns>
1064

    
1065
        public XdmNode Build(XmlReader reader)
1066
        {
1067
            PullProvider pp = new DotNetPullProvider(reader);
1068
            pp.setPipelineConfiguration(config.makePipelineConfiguration());
1069
            // pp = new PullTracer(pp);  /* diagnostics */
1070
            Source source = new PullSource(pp);
1071
            source.setSystemId(reader.BaseURI);
1072
            source = augmentSource(source);
1073
            DocumentInfo doc = config.buildDocument(source);
1074
            return (XdmNode)XdmValue.Wrap(doc);
1075
        }
1076

    
1077
        /// <summary>
1078
        /// Load an XML DOM document, supplied as an <c>XmlNode</c>, into a Saxon XdmNode.
1079
        /// </summary>
1080
        /// <remarks>
1081
        /// <para>
1082
        /// The returned document will contain only the subtree rooted at the supplied node.
1083
        /// </para>
1084
        /// <para>
1085
        /// This method copies the DOM tree to create a Saxon tree. See the <c>Wrap</c> method for
1086
        /// an alternative that creates a wrapper around the DOM tree, allowing it to be modified in situ.
1087
        /// </para>
1088
        /// </remarks>
1089
        /// <param name="source">The DOM Node to be copied to form a Saxon tree</param>
1090
        /// <returns>An <c>XdmNode</c>, the document node at the root of the tree of the resulting
1091
        /// in-memory document
1092
        /// </returns>
1093

    
1094
        public XdmNode Build(XmlNode source)
1095
        {
1096
            return Build(new XmlNodeReader(source));
1097
        }
1098

    
1099
        public XdmNode Build(XdmNode source)
1100
        {
1101
            return (XdmNode)XdmNode.Wrap(config.buildDocument(source.Implementation));
1102
        }
1103

    
1104
        /// <summary>
1105
        /// Wrap an XML DOM document, supplied as an <c>XmlNode</c>, as a Saxon XdmNode.
1106
        /// </summary>
1107
        /// <remarks>
1108
        /// <para>
1109
        /// This method must be applied at the level of the Document Node. Unlike the
1110
        /// <c>Build</c> method, the original DOM is not copied. This saves memory and
1111
        /// time, but it also means that it is not possible to perform operations such as
1112
        /// whitespace stripping and schema validation.
1113
        /// </para>
1114
        /// </remarks>
1115
        /// <param name="doc">The DOM document node to be wrapped</param>
1116
        /// <returns>An <c>XdmNode</c>, the Saxon document node at the root of the tree of the resulting
1117
        /// in-memory document
1118
        /// </returns>
1119

    
1120
        public XdmNode Wrap(XmlDocument doc)
1121
        {
1122
            String baseu = (baseUri == null ? null : baseUri.ToString());
1123
            JDotNetDocumentWrapper wrapper = new JDotNetDocumentWrapper(doc, baseu, config);
1124
            return (XdmNode)XdmValue.Wrap(wrapper);
1125
        }
1126

    
1127

    
1128
    }
1129

    
1130
    public class StandardLogger : JLogger {
1131
        
1132
       private TextWriter outi = Console.Error;
1133
       DotNetWriter writer;
1134
		int threshold = JLogger.INFO;
1135
		java.io.PrintStream stream;
1136

    
1137
       public StandardLogger() {
1138
           writer = new DotNetWriter(outi);
1139
       }
1140

    
1141
       public StandardLogger(TextWriter w) {
1142
       	writer = new DotNetWriter(w);
1143

    
1144
       }
1145

    
1146
		public DotNetWriter UnderylingTextWriter {
1147
			set {
1148
				writer = value;
1149
			}
1150
			get {
1151
				return writer;
1152
			}
1153

    
1154

    
1155
		}
1156

    
1157

    
1158
	//
1159
	// <summary> Set the minimum threshold for the severity of messages to be output. Defaults to
1160
    // {@link Logger#INFO}. Messages whose severity is below this threshold will be ignored </summary>
1161
    // <param> threshold the minimum severity of messages to be output. </param>
1162
     
1163
		public int Threshold {
1164

    
1165
			set { 
1166
				threshold = value;
1167
			}
1168

    
1169
			get { 
1170
				return threshold;
1171
			}
1172

    
1173
		}
1174

    
1175
        public override StreamResult asStreamResult()
1176
        {
1177
            
1178
			return new StreamResult(writer);
1179
        }
1180

    
1181
        public override void println(string str, int severity)
1182
        {
1183
			if (severity >= threshold) {
1184
				writer.write (str);
1185
			}
1186
        }
1187
    }
1188

    
1189

    
1190
    /// <summary>
1191
    /// Enumeration identifying the various Schema validation modes
1192
    /// </summary>
1193

    
1194
    public enum SchemaValidationMode
1195
    {
1196
        /// <summary>No validation (or strip validation, which removes existing type annotations)</summary> 
1197
        None,
1198
        /// <summary>Strict validation</summary>
1199
        Strict,
1200
        /// <summary>Lax validation</summary>
1201
        Lax,
1202
        /// <summary>Validation mode preserve, which preserves any existing type annotations</summary>
1203
        Preserve,
1204
        /// <summary>Unspecified validation: this means that validation is defined elsewhere, for example in the
1205
        /// Saxon Configuration</summary>
1206
        Unspecified
1207
    }
1208

    
1209
    /// <summary>
1210
    /// Enumeration identifying the various Whitespace stripping policies
1211
    /// </summary>
1212

    
1213
    public enum WhitespacePolicy
1214
    {
1215
        /// <summary>No whitespace is stripped</summary> 
1216
        PreserveAll,
1217
        /// <summary>Whitespace text nodes appearing in element-only content are stripped</summary>
1218
        StripIgnorable,
1219
        /// <summary>All whitespace text nodes are stripped</summary>
1220
        StripAll
1221
    }
1222

    
1223
    /// <summary>
1224
    /// Enumeration identifying the different tree model implementations
1225
    /// </summary>
1226
    /// 
1227
    public enum TreeModel
1228
    {
1229
        /// <summary>
1230
        /// Saxon TinyTree. This is the default model and is suitable for most purposes.
1231
        /// </summary>
1232
        TinyTree,
1233
        /// <summary>
1234
        /// Saxon Condensed TinyTree. This is a variant of the TinyTree that shares storage for 
1235
        /// duplicated text and attribute nodes. It gives a further saving in space occupied, at the cost
1236
        /// of some increase in the time taken for tree construction.
1237
        /// </summary>
1238
        TinyTreeCondensed,
1239
        /// <summary>
1240
        /// Saxon LinkedTree. This tree model is primarily useful when using XQuery Update, since it is the
1241
        /// only standard tree model to support updates.
1242
        /// </summary>
1243
        LinkedTree,
1244
        /// <summary>
1245
        /// Unspecified tree model. This value is used to indicate that there is no preference for any specific
1246
        /// tree model, which allows the choice to fall back to other interfaces.
1247
        /// </summary>
1248
        Unspecified
1249
    }
1250

    
1251
    internal class DotNetObjectModelDefinition : JDotNetObjectModel
1252
    {
1253

    
1254
        public override bool isXdmValue(object obj)
1255
        {
1256
            return obj is XdmValue;
1257
        }
1258

    
1259
        public override bool isXdmAtomicValueType(Type type)
1260
        {
1261
            return typeof(XdmAtomicValue).IsAssignableFrom(type);
1262
        }
1263

    
1264
        public override bool isXdmValueType(Type type)
1265
        {
1266
            return typeof(XdmValue).IsAssignableFrom(type);
1267
        }
1268

    
1269
        public override JSequence unwrapXdmValue(object obj)
1270
        {
1271
            return ((XdmValue)obj).Unwrap();
1272
        }
1273

    
1274
        public override object wrapAsXdmValue(JSequence value)
1275
        {
1276
            return XdmValue.Wrap(value);
1277
        }
1278

    
1279
        public override bool isXmlNodeType(Type type)
1280
        {
1281
            return typeof(System.Xml.XmlNode).IsAssignableFrom(type);
1282
        }
1283

    
1284
    }
1285

    
1286
}
1287

    
1288
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1289
// Copyright (c) 2013 Saxonica Limited.
1290
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
1291
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
1292
// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
1293
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
(1-1/13)