Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Xml / System / Xml / XmlUrlResolver.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="XmlUrlResolver.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
7
8 using System.Threading;
9 using System.Security.Permissions;
10 using System.Net;
11 using System.Net.Cache;
12 using System.Runtime.Versioning;
13
14 namespace System.Xml {
15
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;
22
23         static XmlDownloadManager DownloadManager {
24             get {
25                 if ( s_DownloadManager == null ) {
26                     object dm = new XmlDownloadManager();
27                     Interlocked.CompareExchange<object>( ref s_DownloadManager, dm, null );
28                 }
29                 return (XmlDownloadManager)s_DownloadManager;
30             }
31         }
32
33         // Construction
34
35         // Creates a new instance of the XmlUrlResolver class.
36         public XmlUrlResolver() {
37         }
38
39         public override ICredentials Credentials {
40             set { _credentials = value; }
41         }
42
43         public IWebProxy Proxy {
44             set { _proxy = value; }
45         }
46
47         public RequestCachePolicy CachePolicy {
48             set { _cachePolicy = value; }
49         }
50
51         // Resource resolution
52
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);
59             }
60             else {
61                 throw new XmlException(Res.Xml_UnsupportedClass, string.Empty);
62             }
63         }
64
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);
70         }
71     }
72 }