2004-04-22 Martin Baulig <martin@ximian.com>
[mono.git] / mcs / class / System.Security / System.Security.Cryptography.Xml / KeyInfoRetrievalMethod.cs
1 //
2 // KeyInfoRetrievalMethod.cs - KeyInfoRetrievalMethod implementation for XML Signature
3 //
4 // Author:
5 //      Sebastien Pouliot (spouliot@motus.com)
6 //      Tim Coleman (tim@timcoleman.com)
7 //
8 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
9 // Copyright (C) Tim Coleman, 2004
10 //
11
12 using System.Xml;
13
14 namespace System.Security.Cryptography.Xml {
15
16         public class KeyInfoRetrievalMethod : KeyInfoClause {
17
18                 private string URI;
19                 private XmlElement element;
20
21 #if NET_2_0
22                 string type;
23 #endif
24
25                 public KeyInfoRetrievalMethod () {}
26
27                 public KeyInfoRetrievalMethod (string strUri) 
28                 {
29                         URI = strUri;
30                 }
31
32 #if NET_2_0
33                 public KeyInfoRetrievalMethod (string strUri, string strType)
34                         : this (strUri)
35                 {
36                         Type = strType;
37                 }
38
39                 public string Type {
40                         get { return type; }
41                         set {
42                                 element = null;
43                                 type = value;
44                         }
45                 }
46 #endif
47
48                 public string Uri {
49                         get { return URI; }
50                         set {
51                                 element = null;
52                                 URI = value;
53                         }
54                 }
55
56
57                 public override XmlElement GetXml () 
58                 {
59                         if (element != null)
60                                 return element;
61
62                         XmlDocument document = new XmlDocument ();
63                         XmlElement xel = document.CreateElement (XmlSignature.ElementNames.RetrievalMethod, XmlSignature.NamespaceURI);
64                         if (URI != null)
65                                 xel.SetAttribute (XmlSignature.AttributeNames.URI, URI);
66 #if NET_2_0
67                         if (Type != null)
68                                 xel.SetAttribute (XmlSignature.AttributeNames.Type, Type);
69 #endif
70                         return xel;
71                 }
72
73                 public override void LoadXml (XmlElement value) 
74                 {
75                         if (value == null)
76                                 throw new ArgumentNullException ();
77
78                         if ((value.LocalName != XmlSignature.ElementNames.RetrievalMethod) || (value.NamespaceURI != XmlSignature.NamespaceURI)) {
79                                 URI = ""; // not null - so we return URI="" as attribute !!!
80                         } else {
81                                 URI = value.Attributes [XmlSignature.AttributeNames.URI].Value;
82 #if NET_2_0
83                                 if (value.HasAttribute (XmlSignature.AttributeNames.Type))
84                                         Type = value.Attributes [XmlSignature.AttributeNames.Type].Value;
85 #endif
86                                 element = value;
87                         }
88                 }
89         }
90 }