1 //------------------------------------------------------------------------------
2 // <copyright file="XmlUrlResolver.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
8 using System.Threading;
9 using System.Security.Permissions;
11 using System.Net.Cache;
12 using System.Runtime.Versioning;
14 namespace System.Xml {
16 // Resolves external XML resources named by a Uniform Resource Identifier (URI).
17 public partial class XmlUrlResolver : XmlResolver {
18 private static object s_DownloadManager;
19 private ICredentials _credentials;
20 private IWebProxy _proxy;
21 private RequestCachePolicy _cachePolicy;
23 static XmlDownloadManager DownloadManager {
25 if ( s_DownloadManager == null ) {
26 object dm = new XmlDownloadManager();
27 Interlocked.CompareExchange<object>( ref s_DownloadManager, dm, null );
29 return (XmlDownloadManager)s_DownloadManager;
35 // Creates a new instance of the XmlUrlResolver class.
36 public XmlUrlResolver() {
39 public override ICredentials Credentials {
40 set { _credentials = value; }
43 public IWebProxy Proxy {
44 set { _proxy = value; }
47 public RequestCachePolicy CachePolicy {
48 set { _cachePolicy = value; }
51 // Resource resolution
53 // Maps a URI to an Object containing the actual resource.
54 [ResourceConsumption(ResourceScope.Machine)]
55 [ResourceExposure(ResourceScope.Machine)]
56 public override Object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn) {
57 if (ofObjectToReturn == null || ofObjectToReturn == typeof(System.IO.Stream) || ofObjectToReturn == typeof(System.Object)) {
58 return DownloadManager.GetStream(absoluteUri, _credentials, _proxy, _cachePolicy);
61 throw new XmlException(Res.Xml_UnsupportedClass, string.Empty);
65 [PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust")]
66 [ResourceConsumption(ResourceScope.Machine)]
67 [ResourceExposure(ResourceScope.Machine)]
68 public override Uri ResolveUri(Uri baseUri, string relativeUri){
69 return base.ResolveUri(baseUri, relativeUri);