add partial support for XmlSchemaProviderAttribute
[mono.git] / mcs / class / System.XML / System.Xml.Serialization / SoapAttributes.cs
1 //
2 // SoapAttributes.cs: 
3 //
4 // Author:
5 //   John Donagher (john@webmeta.com)
6 //
7 // (C) 2002 John Donagher
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System.Reflection;
32 using System;
33 using System.ComponentModel;
34
35 namespace System.Xml.Serialization
36 {
37         /// <summary>
38         /// Summary description for SoapAttributes.
39         /// </summary>
40         public class SoapAttributes
41         {
42                 private SoapAttributeAttribute soapAttribute;
43                 private object soapDefaultValue = System.DBNull.Value;
44                 private SoapElementAttribute soapElement;
45                 private SoapEnumAttribute soapEnum;
46                 private bool soapIgnore;
47                 private SoapTypeAttribute soapType;
48
49                 public SoapAttributes ()
50                 {
51                 }
52                 
53                 public SoapAttributes (ICustomAttributeProvider provider)
54                 {
55                         object[] attributes = provider.GetCustomAttributes(false);
56                         foreach(object obj in attributes)
57                         {
58                                 if(obj is SoapAttributeAttribute)
59                                         soapAttribute = (SoapAttributeAttribute) obj;
60                                 else if(obj is DefaultValueAttribute)
61                                         soapDefaultValue = ((DefaultValueAttribute) obj).Value;
62                                 else if(obj is SoapElementAttribute)
63                                         soapElement = (SoapElementAttribute) obj;
64                                 else if(obj is SoapEnumAttribute)
65                                         soapEnum = (SoapEnumAttribute) obj;
66                                 else if(obj is SoapIgnoreAttribute)
67                                         soapIgnore = true;
68                                 else if(obj is SoapTypeAttribute)
69                                         soapType = (SoapTypeAttribute) obj;
70                         }
71                 }
72
73                 public SoapAttributeAttribute SoapAttribute 
74                 {
75                         get { return  soapAttribute; } 
76                         set { soapAttribute = value; }
77                 }
78
79                 public object SoapDefaultValue 
80                 {
81                         get { return  soapDefaultValue; } 
82                         set { soapDefaultValue = value; }
83                 }
84
85                 public SoapElementAttribute SoapElement 
86                 {
87                         get { return  soapElement; } 
88                         set { soapElement = value; }
89                 }
90
91                 public SoapEnumAttribute SoapEnum 
92                 {
93                         get { return  soapEnum; } 
94                         set { soapEnum = value; }
95                 }
96
97                 public bool SoapIgnore
98                 {
99                         get { return  soapIgnore; } 
100                         set { soapIgnore = value; }
101                 }
102
103                 public SoapTypeAttribute SoapType 
104                 {
105                         get { return  soapType; } 
106                         set { soapType = value; }
107                 }
108                 
109                 internal void AddKeyHash (System.Text.StringBuilder sb)
110                 {
111                         sb.Append ("SA ");
112                         
113                         if (soapIgnore) 
114                                 sb.Append ('i');
115                                 
116                         if (soapAttribute != null)
117                                 soapAttribute.AddKeyHash (sb);
118                                 
119                         if (soapElement != null)
120                                 soapElement.AddKeyHash (sb);
121                                 
122                         if (soapEnum != null)
123                                 soapEnum.AddKeyHash (sb);
124                                 
125                         if (soapType != null)
126                                 soapType.AddKeyHash (sb);
127                                 
128                         if (soapDefaultValue == null) {
129                                 sb.Append ("n");
130                         }
131                         else if (!(soapDefaultValue is System.DBNull)) {
132                                 string v = XmlCustomFormatter.ToXmlString (TypeTranslator.GetTypeData (soapDefaultValue.GetType()), soapDefaultValue);
133                                 sb.Append ("v" + v);
134                         }
135                         sb.Append ("|");
136                 }       
137         }
138 }