**** Merged from MCS ****
[mono-project.git] / mcs / class / Microsoft.Web.Services / Microsoft.Web.Services.Addressing / RelatesTo.cs
blob80fec335361959592d4363d7e990e46c20019dd7
1 //
2 // Microsoft.Web.Services.Addressing.RelatesTo.cs
3 //
4 // Author: Todd Berman <tberman@gentoo.org>
5 //
6 // (C) 2003 Todd Berman
8 using System;
9 using System.Xml;
10 using Microsoft.Web.Services.Xml;
12 namespace Microsoft.Web.Services.Addressing
14 public class RelatesTo : AttributedUri, IXmlElement
16 private QualifiedName _type;
18 public RelatesTo (XmlElement element) : base ()
20 _type = new QualifiedName ("wsa",
21 "Response",
22 "http://schemas.xmlsoap.org/ws/2003/03/addressing");
23 LoadXml (element);
26 public RelatesTo (Uri uri) : base (uri)
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");
36 public XmlElement GetXml (XmlDocument document)
38 if(document == null) {
39 throw new ArgumentNullException ("related");
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");
47 attrib.Value = _type.Value;
49 element.Attributes.Append (attrib);
51 if(_type.Namespace != "http://schemas.xmlsoap.org/ws/2003/03/addressing") {
52 element.Attributes.Append (_type.GetNamespaceDecl (document));
56 GetXmlUri (document, element);
57 return element;
60 public void LoadXml (XmlElement element)
62 if(element == null) {
63 throw new ArgumentNullException ("element");
66 if(element.LocalName != "RelatesTo" || element.NamespaceURI != "http://schemas.xmlsoap.org/ws/2003/03/addressing") {
67 throw new ArgumentException ("Invalid Element Supplied");
70 ValidateSchema (element);
72 _type = new QualifiedName ("wsa",
73 "Response",
74 "http://schemas.xmlsoap.org/ws/2003/03/addressing");
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);
84 Value = new Uri (element.InnerText);
88 public static implicit operator RelatesTo (Uri uri)
90 return new RelatesTo (uri);
93 public static implicit operator Uri (RelatesTo obj)
95 if(obj == null) {
96 return null;
98 return obj.Value;