New test.
[mono.git] / mcs / class / Microsoft.Web.Services / Microsoft.Web.Services.Addressing / RelatesTo.cs
1 //
2 // Microsoft.Web.Services.Addressing.RelatesTo.cs
3 //
4 // Author: Todd Berman <tberman@gentoo.org>
5 //
6 // (C) 2003 Todd Berman
7
8 using System;
9 using System.Xml;
10 using Microsoft.Web.Services.Xml;
11
12 namespace Microsoft.Web.Services.Addressing
13 {
14         public class RelatesTo : AttributedUri, IXmlElement
15         {
16                 private QualifiedName _type;
17
18                 public RelatesTo (XmlElement element) : base ()
19                 {
20                         _type = new QualifiedName ("wsa",
21                                                    "Response",
22                                                    "http://schemas.xmlsoap.org/ws/2003/03/addressing");
23                         LoadXml (element);
24                 }
25
26                 public RelatesTo (Uri uri) : base (uri)
27                 {
28                         _type = new QualifiedName ("wsa",
29                                                    "Response",
30                                                    "http://schemas.xmlsoap.org/ws/2003/03/addressing");
31                         if(uri == null) {
32                                 throw new ArgumentNullException ("related");
33                         }
34                 }
35
36                 public XmlElement GetXml (XmlDocument document)
37                 {
38                         if(document == null) {
39                                 throw new ArgumentNullException ("related");
40                         }
41                         XmlElement element = document.CreateElement ("wsa",
42                                                                      "RelatesTo",
43                                                                      "http://schemas.xmlsoap.org/ws/2003/03/addressing");
44                         if(_type != null) {
45                                 XmlAttribute attrib = document.CreateAttribute ("RelationshipType");
46
47                                 attrib.Value = _type.Value;
48
49                                 element.Attributes.Append (attrib);
50
51                                 if(_type.Namespace != "http://schemas.xmlsoap.org/ws/2003/03/addressing") {
52                                         element.Attributes.Append (_type.GetNamespaceDecl (document));
53                                 }
54                         }
55
56                         GetXmlUri (document, element);
57                         return element;
58                 }
59
60                 public void LoadXml (XmlElement element)
61                 {
62                         if(element == null) {
63                                 throw new ArgumentNullException ("element");
64                         }
65
66                         if(element.LocalName != "RelatesTo" || element.NamespaceURI != "http://schemas.xmlsoap.org/ws/2003/03/addressing") {
67                                 throw new ArgumentException ("Invalid Element Supplied");
68                         }
69
70                         ValidateSchema (element);
71
72                         _type = new QualifiedName ("wsa",
73                                                    "Response",
74                                                    "http://schemas.xmlsoap.org/ws/2003/03/addressing");
75
76                         foreach(XmlAttribute attrib in element.Attributes) {
77                                 if(attrib.LocalName == "RelationshipType") {
78                                         _type = QualifiedName.FromString (attrib.InnerText, element);
79                                 } else {
80                                         AnyAttributes.Add (attrib);
81                                 }
82                         }
83
84                         Value = new Uri (element.InnerText);
85                         
86                 }
87
88                 public static implicit operator RelatesTo (Uri uri)
89                 {
90                         return new RelatesTo (uri);
91                 }
92
93                 public static implicit operator Uri (RelatesTo obj)
94                 {
95                         if(obj == null) {
96                                 return null;
97                         }
98                         return obj.Value;
99                 }
100         }
101 }