DiscoveryDocumentSerializer.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. //
  2. // System.Web.Services.Protocols.DiscoveryDocumentSerializer.cs
  3. //
  4. // Author:
  5. // Lluis Sanchez Gual ([email protected])
  6. //
  7. // Copyright (C) Ximian,Inc., 2003
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.Xml;
  31. using System.Xml.Schema;
  32. using System.Xml.Serialization;
  33. using System.Text;
  34. using System.Collections;
  35. using System.Globalization;
  36. namespace System.Web.Services.Discovery
  37. {
  38. internal class DiscoveryDocumentReader : XmlSerializationReader
  39. {
  40. public object ReadRoot_DiscoveryDocument ()
  41. {
  42. Reader.MoveToContent();
  43. if (Reader.LocalName != "discovery" || Reader.NamespaceURI != "http://schemas.xmlsoap.org/disco/")
  44. throw CreateUnknownNodeException();
  45. return ReadObject_DiscoveryDocument (true, true);
  46. }
  47. public System.Web.Services.Discovery.DiscoveryDocument ReadObject_DiscoveryDocument (bool isNullable, bool checkType)
  48. {
  49. System.Web.Services.Discovery.DiscoveryDocument ob = null;
  50. if (isNullable && ReadNull()) return null;
  51. if (checkType)
  52. {
  53. System.Xml.XmlQualifiedName t = GetXsiType();
  54. if (t != null)
  55. {
  56. if (t.Name != "DiscoveryDocument" || t.Namespace != "http://schemas.xmlsoap.org/disco/")
  57. throw CreateUnknownTypeException(t);
  58. }
  59. }
  60. ob = new System.Web.Services.Discovery.DiscoveryDocument ();
  61. Reader.MoveToElement();
  62. while (Reader.MoveToNextAttribute())
  63. {
  64. if (IsXmlnsAttribute (Reader.Name)) {
  65. }
  66. else {
  67. UnknownNode (ob);
  68. }
  69. }
  70. Reader.MoveToElement();
  71. if (Reader.IsEmptyElement) {
  72. Reader.Skip ();
  73. return ob;
  74. }
  75. Reader.ReadStartElement();
  76. Reader.MoveToContent();
  77. bool b0=false, b1=false;
  78. System.Collections.ArrayList o3 = null;
  79. System.Collections.ArrayList o5 = null;
  80. int n2=0, n4=0;
  81. while (Reader.NodeType != System.Xml.XmlNodeType.EndElement)
  82. {
  83. if (Reader.NodeType == System.Xml.XmlNodeType.Element)
  84. {
  85. if (Reader.LocalName == "discoveryRef" && Reader.NamespaceURI == "http://schemas.xmlsoap.org/disco/" && !b0) {
  86. if (o3 == null)
  87. o3 = new System.Collections.ArrayList();
  88. o3.Add (ReadObject_DiscoveryDocumentReference (false, true));
  89. n2++;
  90. }
  91. else if (Reader.LocalName == "soap" && Reader.NamespaceURI == "http://schemas/xmlsoap.org/disco/schema/soap/" && !b1) {
  92. if (o5 == null)
  93. o5 = new System.Collections.ArrayList();
  94. o5.Add (ReadObject_SoapBinding (false, true));
  95. n4++;
  96. }
  97. else if (Reader.LocalName == "contractRef" && Reader.NamespaceURI == "http://schemas.xmlsoap.org/disco/scl/" && !b0) {
  98. if (o3 == null)
  99. o3 = new System.Collections.ArrayList();
  100. o3.Add (ReadObject_ContractReference (false, true));
  101. n2++;
  102. }
  103. else if (Reader.LocalName == "schemaRef" && Reader.NamespaceURI == "http://schemas.xmlsoap.org/disco/" && !b0) {
  104. if (o3 == null)
  105. o3 = new System.Collections.ArrayList();
  106. o3.Add (ReadObject_SchemaReference (false, true));
  107. n2++;
  108. }
  109. else {
  110. UnknownNode (ob);
  111. }
  112. }
  113. else
  114. UnknownNode(ob);
  115. Reader.MoveToContent();
  116. }
  117. ob.@references = o3;
  118. ob.@additionalInfo = o5;
  119. ReadEndElement();
  120. return ob;
  121. }
  122. public System.Web.Services.Discovery.DiscoveryDocumentReference ReadObject_DiscoveryDocumentReference (bool isNullable, bool checkType)
  123. {
  124. System.Web.Services.Discovery.DiscoveryDocumentReference ob = null;
  125. if (isNullable && ReadNull()) return null;
  126. if (checkType)
  127. {
  128. System.Xml.XmlQualifiedName t = GetXsiType();
  129. if (t != null)
  130. {
  131. if (t.Name != "DiscoveryDocumentReference" || t.Namespace != "http://schemas.xmlsoap.org/disco/")
  132. throw CreateUnknownTypeException(t);
  133. }
  134. }
  135. ob = new System.Web.Services.Discovery.DiscoveryDocumentReference ();
  136. Reader.MoveToElement();
  137. while (Reader.MoveToNextAttribute())
  138. {
  139. if (Reader.LocalName == "ref" && Reader.NamespaceURI == "") {
  140. ob.@Ref = Reader.Value;
  141. }
  142. else if (IsXmlnsAttribute (Reader.Name)) {
  143. }
  144. else {
  145. UnknownNode (ob);
  146. }
  147. }
  148. Reader.MoveToElement();
  149. if (Reader.IsEmptyElement) {
  150. Reader.Skip ();
  151. return ob;
  152. }
  153. Reader.ReadStartElement();
  154. Reader.MoveToContent();
  155. while (Reader.NodeType != System.Xml.XmlNodeType.EndElement)
  156. {
  157. if (Reader.NodeType == System.Xml.XmlNodeType.Element)
  158. {
  159. UnknownNode (ob);
  160. }
  161. else
  162. UnknownNode(ob);
  163. Reader.MoveToContent();
  164. }
  165. ReadEndElement();
  166. return ob;
  167. }
  168. public System.Web.Services.Discovery.SoapBinding ReadObject_SoapBinding (bool isNullable, bool checkType)
  169. {
  170. System.Web.Services.Discovery.SoapBinding ob = null;
  171. if (isNullable && ReadNull()) return null;
  172. if (checkType)
  173. {
  174. System.Xml.XmlQualifiedName t = GetXsiType();
  175. if (t != null)
  176. {
  177. if (t.Name != "SoapBinding" || t.Namespace != "http://schemas/xmlsoap.org/disco/schema/soap/")
  178. throw CreateUnknownTypeException(t);
  179. }
  180. }
  181. ob = new System.Web.Services.Discovery.SoapBinding ();
  182. Reader.MoveToElement();
  183. while (Reader.MoveToNextAttribute())
  184. {
  185. if (Reader.LocalName == "binding" && Reader.NamespaceURI == "") {
  186. ob.@Binding = ToXmlQualifiedName (Reader.Value);
  187. }
  188. else if (Reader.LocalName == "address" && Reader.NamespaceURI == "") {
  189. ob.@Address = Reader.Value;
  190. }
  191. else if (IsXmlnsAttribute (Reader.Name)) {
  192. }
  193. else {
  194. UnknownNode (ob);
  195. }
  196. }
  197. Reader.MoveToElement();
  198. if (Reader.IsEmptyElement) {
  199. Reader.Skip ();
  200. return ob;
  201. }
  202. Reader.ReadStartElement();
  203. Reader.MoveToContent();
  204. while (Reader.NodeType != System.Xml.XmlNodeType.EndElement)
  205. {
  206. if (Reader.NodeType == System.Xml.XmlNodeType.Element)
  207. {
  208. UnknownNode (ob);
  209. }
  210. else
  211. UnknownNode(ob);
  212. Reader.MoveToContent();
  213. }
  214. ReadEndElement();
  215. return ob;
  216. }
  217. public System.Web.Services.Discovery.ContractReference ReadObject_ContractReference (bool isNullable, bool checkType)
  218. {
  219. System.Web.Services.Discovery.ContractReference ob = null;
  220. if (isNullable && ReadNull()) return null;
  221. if (checkType)
  222. {
  223. System.Xml.XmlQualifiedName t = GetXsiType();
  224. if (t != null)
  225. {
  226. if (t.Name != "ContractReference" || t.Namespace != "http://schemas.xmlsoap.org/disco/scl/")
  227. throw CreateUnknownTypeException(t);
  228. }
  229. }
  230. ob = new System.Web.Services.Discovery.ContractReference ();
  231. Reader.MoveToElement();
  232. while (Reader.MoveToNextAttribute())
  233. {
  234. if (Reader.LocalName == "docRef" && Reader.NamespaceURI == "") {
  235. ob.@DocRef = Reader.Value;
  236. }
  237. else if (Reader.LocalName == "ref" && Reader.NamespaceURI == "") {
  238. ob.@Ref = Reader.Value;
  239. }
  240. else if (IsXmlnsAttribute (Reader.Name)) {
  241. }
  242. else {
  243. UnknownNode (ob);
  244. }
  245. }
  246. Reader.MoveToElement();
  247. if (Reader.IsEmptyElement) {
  248. Reader.Skip ();
  249. return ob;
  250. }
  251. Reader.ReadStartElement();
  252. Reader.MoveToContent();
  253. while (Reader.NodeType != System.Xml.XmlNodeType.EndElement)
  254. {
  255. if (Reader.NodeType == System.Xml.XmlNodeType.Element)
  256. {
  257. UnknownNode (ob);
  258. }
  259. else
  260. UnknownNode(ob);
  261. Reader.MoveToContent();
  262. }
  263. ReadEndElement();
  264. return ob;
  265. }
  266. public System.Web.Services.Discovery.SchemaReference ReadObject_SchemaReference (bool isNullable, bool checkType)
  267. {
  268. System.Web.Services.Discovery.SchemaReference ob = null;
  269. if (isNullable && ReadNull()) return null;
  270. if (checkType)
  271. {
  272. System.Xml.XmlQualifiedName t = GetXsiType();
  273. if (t != null)
  274. {
  275. if (t.Name != "SchemaReference" || t.Namespace != "http://schemas/xmlsoap.org/disco/schema/")
  276. throw CreateUnknownTypeException(t);
  277. }
  278. }
  279. ob = new System.Web.Services.Discovery.SchemaReference ();
  280. Reader.MoveToElement();
  281. while (Reader.MoveToNextAttribute())
  282. {
  283. if (Reader.LocalName == "targetNamespace" && Reader.NamespaceURI == "") {
  284. ob.@TargetNamespace = Reader.Value;
  285. }
  286. else if (Reader.LocalName == "ref" && Reader.NamespaceURI == "") {
  287. ob.@Ref = Reader.Value;
  288. }
  289. else if (IsXmlnsAttribute (Reader.Name)) {
  290. }
  291. else {
  292. UnknownNode (ob);
  293. }
  294. }
  295. Reader.MoveToElement();
  296. if (Reader.IsEmptyElement) {
  297. Reader.Skip ();
  298. return ob;
  299. }
  300. Reader.ReadStartElement();
  301. Reader.MoveToContent();
  302. while (Reader.NodeType != System.Xml.XmlNodeType.EndElement)
  303. {
  304. if (Reader.NodeType == System.Xml.XmlNodeType.Element)
  305. {
  306. UnknownNode (ob);
  307. }
  308. else
  309. UnknownNode(ob);
  310. Reader.MoveToContent();
  311. }
  312. ReadEndElement();
  313. return ob;
  314. }
  315. protected override void InitCallbacks ()
  316. {
  317. }
  318. protected override void InitIDs ()
  319. {
  320. }
  321. }
  322. internal class DiscoveryDocumentWriter : XmlSerializationWriter
  323. {
  324. public void WriteRoot_DiscoveryDocument (object o)
  325. {
  326. WriteStartDocument ();
  327. System.Web.Services.Discovery.DiscoveryDocument ob = (System.Web.Services.Discovery.DiscoveryDocument) o;
  328. TopLevelElement ();
  329. WriteObject_DiscoveryDocument (ob, "discovery", "http://schemas.xmlsoap.org/disco/", true, false, true);
  330. }
  331. void WriteObject_DiscoveryDocument (System.Web.Services.Discovery.DiscoveryDocument ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem)
  332. {
  333. if (ob == null)
  334. {
  335. if (isNullable)
  336. WriteNullTagLiteral(element, namesp);
  337. return;
  338. }
  339. if (writeWrappingElem) {
  340. WriteStartElement (element, namesp, ob);
  341. }
  342. if (needType) WriteXsiType("DiscoveryDocument", "http://schemas.xmlsoap.org/disco/");
  343. if (ob.@references != null) {
  344. for (int n6 = 0; n6 < [email protected]; n6++) {
  345. if (ob.@references[n6] == null) { }
  346. else if (ob.@references[n6].GetType() == typeof(System.Web.Services.Discovery.SchemaReference)) {
  347. WriteObject_SchemaReference (((System.Web.Services.Discovery.SchemaReference) ob.@references[n6]), "schemaRef", "http://schemas.xmlsoap.org/disco/", false, false, true);
  348. }
  349. else if (ob.@references[n6].GetType() == typeof(System.Web.Services.Discovery.DiscoveryDocumentReference)) {
  350. WriteObject_DiscoveryDocumentReference (((System.Web.Services.Discovery.DiscoveryDocumentReference) ob.@references[n6]), "discoveryRef", "http://schemas.xmlsoap.org/disco/", false, false, true);
  351. }
  352. else if (ob.@references[n6].GetType() == typeof(System.Web.Services.Discovery.ContractReference)) {
  353. WriteObject_ContractReference (((System.Web.Services.Discovery.ContractReference) ob.@references[n6]), "contractRef", "http://schemas.xmlsoap.org/disco/scl/", false, false, true);
  354. }
  355. else throw CreateUnknownTypeException (ob.@references[n6]);
  356. }
  357. }
  358. if (ob.@additionalInfo != null) {
  359. for (int n7 = 0; n7 < [email protected]; n7++) {
  360. WriteObject_SoapBinding (((System.Web.Services.Discovery.SoapBinding) ob.@additionalInfo[n7]), "soap", "http://schemas/xmlsoap.org/disco/schema/soap/", false, false, true);
  361. }
  362. }
  363. if (writeWrappingElem) WriteEndElement (ob);
  364. }
  365. void WriteObject_SchemaReference (System.Web.Services.Discovery.SchemaReference ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem)
  366. {
  367. if (ob == null)
  368. {
  369. if (isNullable)
  370. WriteNullTagLiteral(element, namesp);
  371. return;
  372. }
  373. if (writeWrappingElem) {
  374. WriteStartElement (element, namesp, ob);
  375. }
  376. if (needType) WriteXsiType("SchemaReference", "http://schemas/xmlsoap.org/disco/schema/");
  377. if (ob.@TargetNamespace != "") {
  378. WriteAttribute ("targetNamespace", "", ob.@TargetNamespace);
  379. }
  380. WriteAttribute ("ref", "", ob.@Ref);
  381. if (writeWrappingElem) WriteEndElement (ob);
  382. }
  383. void WriteObject_DiscoveryDocumentReference (System.Web.Services.Discovery.DiscoveryDocumentReference ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem)
  384. {
  385. if (ob == null)
  386. {
  387. if (isNullable)
  388. WriteNullTagLiteral(element, namesp);
  389. return;
  390. }
  391. if (writeWrappingElem) {
  392. WriteStartElement (element, namesp, ob);
  393. }
  394. if (needType) WriteXsiType("DiscoveryDocumentReference", "http://schemas.xmlsoap.org/disco/");
  395. WriteAttribute ("ref", "", ob.@Ref);
  396. if (writeWrappingElem) WriteEndElement (ob);
  397. }
  398. void WriteObject_ContractReference (System.Web.Services.Discovery.ContractReference ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem)
  399. {
  400. if (ob == null)
  401. {
  402. if (isNullable)
  403. WriteNullTagLiteral(element, namesp);
  404. return;
  405. }
  406. if (writeWrappingElem) {
  407. WriteStartElement (element, namesp, ob);
  408. }
  409. if (needType) WriteXsiType("ContractReference", "http://schemas.xmlsoap.org/disco/scl/");
  410. WriteAttribute ("docRef", "", ob.@DocRef);
  411. WriteAttribute ("ref", "", ob.@Ref);
  412. if (writeWrappingElem) WriteEndElement (ob);
  413. }
  414. void WriteObject_SoapBinding (System.Web.Services.Discovery.SoapBinding ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem)
  415. {
  416. if (ob == null)
  417. {
  418. if (isNullable)
  419. WriteNullTagLiteral(element, namesp);
  420. return;
  421. }
  422. if (writeWrappingElem) {
  423. WriteStartElement (element, namesp, ob);
  424. }
  425. if (needType) WriteXsiType("SoapBinding", "http://schemas/xmlsoap.org/disco/schema/soap/");
  426. WriteAttribute ("binding", "", FromXmlQualifiedName (ob.@Binding));
  427. WriteAttribute ("address", "", ob.@Address);
  428. if (writeWrappingElem) WriteEndElement (ob);
  429. }
  430. protected override void InitCallbacks ()
  431. {
  432. }
  433. }
  434. }