1 // created on 24/04/2003 at 15:35
\r
3 // System.Runtime.Serialization.Formatters.Soap.SoapReader
\r
6 // Jean-Marc Andre (jean-marc.andre@polymtl.ca)
\r
10 using System.Reflection;
\r
11 using System.Collections;
\r
12 using System.Runtime.Serialization;
\r
14 namespace System.Runtime.Serialization.Formatters.Soap {
\r
15 internal class SoapReader: ISoapReader {
\r
16 public event ElementReadEventHandler ElementReadEvent;
\r
18 public SoapReader(ISoapParser parser) {
\r
19 // register the SoapElementReadEvent handler
\r
20 parser.SoapElementReadEvent += new SoapElementReadEventHandler(SoapElementRead);
\r
23 // called when SoapElementReadEvent is raized by the SoapParser object
\r
24 public void SoapElementRead(ISoapParser sender, SoapElementReadEventArgs e) {
\r
25 Queue elementQueue = e.ElementQueue;
\r
26 Queue elementInfoQueue = new Queue();
\r
27 SoapSerializationEntry root = (SoapSerializationEntry) elementQueue.Dequeue();
\r
29 ElementInfo rootInfo = GetElementInfo(root);
\r
30 SoapSerializationEntry field;
\r
31 while(elementQueue.Count > 0){
\r
32 field = (SoapSerializationEntry) elementQueue.Dequeue();
\r
33 elementInfoQueue.Enqueue(GetElementInfo(field));
\r
36 // raise the ElementReadEvent
\r
37 ElementReadEvent(this,new ElementReadEventArgs(rootInfo, elementInfoQueue));
\r
40 // Converts the text information from the SoapParser into
\r
41 // information that with by used by the ObjectReader to reconstruct
\r
43 private ElementInfo GetElementInfo(SoapSerializationEntry entry) {
\r
44 SoapTypeMapping mapping = new SoapTypeMapping(entry.elementName, entry.elementNamespace);
\r
45 Type elementType = SoapTypeMapper.GetType(mapping);
\r
49 ElementType elementId = ElementType.Nothing;
\r
50 ICollection attrLst = entry.elementAttributes;
\r
51 int[] arrayRank = null;
\r
52 foreach(SoapAttributeStruct attr in attrLst){
\r
53 if(attr.attributeName == "id"){
\r
54 string attrId = ((string)attr.attributeValue).Remove(0,4);
\r
55 id = (new FormatterConverter()).ToInt64(attrId);
\r
56 elementId = ElementType.Id;
\r
57 } else if(attr.attributeName == "href") {
\r
58 string attrId = ((string)attr.attributeValue).Remove(0,5);
\r
59 id = (new FormatterConverter()).ToInt64(attrId);
\r
60 elementId = ElementType.Href;
\r
61 } else if(attr.attributeName == "xsi:null" && attr.attributeValue == "1") {
\r
62 elementId = ElementType.Null;
\r
63 } else if(attr.attributeName == "SOAP-ENC:arrayType") {
\r
64 string[] tokens = attr.attributeValue.Split(new System.Char[] {'[',',',']'});
\r
65 mapping = new SoapTypeMapping(tokens[0], attr.prefix);
\r
66 elementType = SoapTypeMapper.GetType(mapping);
\r
67 arrayRank = new int[tokens.Length - 2];
\r
68 for(int i=0; i<tokens.Length-2; i++) {
\r
69 arrayRank[i] = Convert.ToInt32(tokens[i+1]);
\r
71 Type tempType = Type.GetType(elementType.ToString()+"[]");
\r
73 if(tempType == null) {
\r
74 AssemblyName assName = elementType.Assembly.GetName();
\r
75 Assembly ass = Assembly.Load(assName);
\r
76 tempType = ass.GetType(elementType.ToString()+"[]", true);
\r
79 elementType = tempType;
\r
80 } else if(attr.attributeName == "xsi:type") {
\r
81 mapping = new SoapTypeMapping(attr.attributeValue, attr.prefix);
\r
82 elementType = SoapTypeMapper.GetType(mapping);
\r
89 ElementInfo elementInfo = new ElementInfo(elementType, entry.elementName, entry.elementValue, elementId, id, arrayRank);
\r