* ProtocolImporter.cs: Use the binding name as class name for the
[mono.git] / mcs / class / System.XML / System.Xml.Serialization / XmlTypeMapElementInfo.cs
1 //
2 // XmlTypeMapElementInfo.cs: 
3 //
4 // Author:
5 //   Lluis Sanchez Gual (lluis@ximian.com)
6 //
7 // (C) 2002, 2003 Ximian, Inc.  http://www.ximian.com
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;
32 using System.Xml.Schema;
33 using System.Collections;
34
35 namespace System.Xml.Serialization
36 {
37         /// <summary>
38         /// Summary description for XmlTypeMapElementInfo.
39         /// </summary>
40         internal class XmlTypeMapElementInfo
41         {
42                 string _elementName;
43                 string _namespace = "";
44                 XmlSchemaForm _form;
45                 XmlTypeMapMember _member;
46                 object _choiceValue;
47                 bool _isNullable;
48                 int _nestingLevel;      // Only for array items
49                 XmlTypeMapping _mappedType;
50                 TypeData _type;
51                 bool _wrappedElement = true;
52                 
53                 public XmlTypeMapElementInfo (XmlTypeMapMember member, TypeData type)
54                 {
55                         _member = member;
56                         _type = type;
57                         if (type.IsValueType && type.IsNullable)
58                                 _isNullable = true;
59                 }
60
61                 public TypeData TypeData
62                 {
63                         get { return _type; }
64                         set { _type = value; }
65                 }
66
67                 public object ChoiceValue
68                 {
69                         get { return _choiceValue; }
70                         set { _choiceValue = value; }
71                 }
72
73                 public string ElementName
74                 {
75                         get { return _elementName; }
76                         set { _elementName = value; }
77                 }
78
79                 public string Namespace
80                 {
81                         get { return _namespace; }
82                         set { _namespace = value; }
83                 }
84
85                 public string DataTypeNamespace
86                 {
87                         get 
88                         { 
89                                 if (_mappedType == null) return XmlSchema.Namespace;
90                                 else return _mappedType.XmlTypeNamespace;
91                         }
92                 }
93
94                 public string DataTypeName
95                 {
96                         get 
97                         { 
98                                 if (_mappedType == null) return TypeData.XmlType;
99                                 else return _mappedType.XmlType;
100                         }
101                 }
102
103                 public XmlSchemaForm Form 
104                 {
105                         get { return _form; }
106                         set { _form = value; }
107                 }
108
109                 public XmlTypeMapping MappedType
110                 {
111                         get { return _mappedType; }
112                         set { _mappedType = value; }
113                 }
114
115                 public bool IsNullable
116                 {
117                         get { return _isNullable; }
118                         set { _isNullable = value; }
119                 }
120
121                 internal bool IsPrimitive
122                 {
123                         get { return _mappedType == null; }
124                 }
125
126                 public XmlTypeMapMember Member
127                 {
128                         get { return _member; }
129                         set { _member = value; }
130                 }
131
132                 public int NestingLevel
133                 {
134                         get { return _nestingLevel; }
135                         set { _nestingLevel = value; }
136                 }
137
138                 public bool MultiReferenceType
139                 {
140                         get 
141                         { 
142                                 if (_mappedType != null) return _mappedType.MultiReferenceType;
143                                 else return false;
144                         }
145                 }
146
147                 public bool WrappedElement
148                 {
149                         get { return _wrappedElement; }
150                         set { _wrappedElement = value; }
151                 }
152
153                 public bool IsTextElement
154                 {
155                         get { return ElementName == "<text>"; }
156                         set {
157                                 if (!value)
158                                         throw new Exception ("INTERNAL ERROR; someone wrote unexpected code in sys.xml");
159                                 ElementName = "<text>"; Namespace = string.Empty;
160                         }
161                 }
162
163                 public bool IsUnnamedAnyElement
164                 {
165                         get { return ElementName == string.Empty; }
166                         set {
167                                 if (!value)
168                                         throw new Exception ("INTERNAL ERROR; someone wrote unexpected code in sys.xml");
169                                 ElementName = string.Empty; Namespace = string.Empty;
170                         }
171                 }
172
173                 public override bool Equals (object other)
174                 {
175                         if (other == null)
176                                 return false;
177                         XmlTypeMapElementInfo oinfo = (XmlTypeMapElementInfo)other;
178                         if (_elementName != oinfo._elementName) return false;
179                         if (_type.XmlType != oinfo._type.XmlType) return false;
180                         if (_namespace != oinfo._namespace) return false;
181                         if (_form != oinfo._form) return false;
182                         if (_type != oinfo._type) return false;
183                         if (_isNullable != oinfo._isNullable) return false;
184                         if (_choiceValue != null && !_choiceValue.Equals (oinfo._choiceValue)) return false;
185                         if (_choiceValue != oinfo._choiceValue) return false;
186                         return true;
187                 }
188
189                 public override int GetHashCode ()
190                 {
191                         return base.GetHashCode ();
192                 }
193         }
194
195         class XmlTypeMapElementInfoList: ArrayList
196         {
197                 public int IndexOfElement (string name, string namspace)
198                 {
199                         for (int n=0; n<Count; n++) {
200                                 XmlTypeMapElementInfo info = (XmlTypeMapElementInfo) base [n];
201                                 if (info.ElementName == name && info.Namespace == namspace)
202                                         return n;
203                         }
204                         return -1;
205                 }
206         }
207 }
208