Merge pull request #587 from madewokherd/gdipdllmap
[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                 int _explicitOrder = -1;
53                 
54                 public XmlTypeMapElementInfo (XmlTypeMapMember member, TypeData type)
55                 {
56                         _member = member;
57                         _type = type;
58                         if (type.IsValueType && type.IsNullable)
59                                 _isNullable = true;
60                 }
61
62                 public TypeData TypeData
63                 {
64                         get { return _type; }
65                         set { _type = value; }
66                 }
67
68                 public object ChoiceValue
69                 {
70                         get { return _choiceValue; }
71                         set { _choiceValue = value; }
72                 }
73
74                 public string ElementName
75                 {
76                         get { return _elementName; }
77                         set { _elementName = value; }
78                 }
79
80                 public string Namespace
81                 {
82                         get { return _namespace; }
83                         set { _namespace = value; }
84                 }
85
86                 public string DataTypeNamespace
87                 {
88                         get 
89                         { 
90                                 if (_mappedType == null) return XmlSchema.Namespace;
91                                 else return _mappedType.XmlTypeNamespace;
92                         }
93                 }
94
95                 public string DataTypeName
96                 {
97                         get 
98                         { 
99                                 if (_mappedType == null) return TypeData.XmlType;
100                                 else return _mappedType.XmlType;
101                         }
102                 }
103
104                 public XmlSchemaForm Form 
105                 {
106                         get { return _form; }
107                         set { _form = value; }
108                 }
109
110                 public XmlTypeMapping MappedType
111                 {
112                         get { return _mappedType; }
113                         set { _mappedType = value; }
114                 }
115
116                 public bool IsNullable
117                 {
118                         get { return _isNullable; }
119                         set { _isNullable = value; }
120                 }
121
122                 internal bool IsPrimitive
123                 {
124                         get { return _mappedType == null; }
125                 }
126
127                 public XmlTypeMapMember Member
128                 {
129                         get { return _member; }
130                         set { _member = value; }
131                 }
132
133                 public int NestingLevel
134                 {
135                         get { return _nestingLevel; }
136                         set { _nestingLevel = value; }
137                 }
138
139                 public bool MultiReferenceType
140                 {
141                         get 
142                         { 
143                                 if (_mappedType != null) return _mappedType.MultiReferenceType;
144                                 else return false;
145                         }
146                 }
147
148                 public bool WrappedElement
149                 {
150                         get { return _wrappedElement; }
151                         set { _wrappedElement = value; }
152                 }
153
154                 public bool IsTextElement
155                 {
156                         get { return ElementName == "<text>"; }
157                         set {
158                                 if (!value)
159                                         throw new Exception ("INTERNAL ERROR; someone wrote unexpected code in sys.xml");
160                                 ElementName = "<text>"; Namespace = string.Empty;
161                         }
162                 }
163
164                 public bool IsUnnamedAnyElement
165                 {
166                         get { return ElementName == string.Empty; }
167                         set {
168                                 if (!value)
169                                         throw new Exception ("INTERNAL ERROR; someone wrote unexpected code in sys.xml");
170                                 ElementName = string.Empty; Namespace = string.Empty;
171                         }
172                 }
173
174                 public int ExplicitOrder
175                 {
176                         get { return _explicitOrder; }
177                         set { _explicitOrder = value; }
178                 }
179
180                 public override bool Equals (object other)
181                 {
182                         if (other == null)
183                                 return false;
184                         XmlTypeMapElementInfo oinfo = (XmlTypeMapElementInfo)other;
185                         if (_elementName != oinfo._elementName) return false;
186                         if (_type.XmlType != oinfo._type.XmlType) return false;
187                         if (_namespace != oinfo._namespace) return false;
188                         if (_form != oinfo._form) return false;
189                         if (_type != oinfo._type) return false;
190                         if (_isNullable != oinfo._isNullable) return false;
191                         if (_choiceValue != null && !_choiceValue.Equals (oinfo._choiceValue)) return false;
192                         if (_choiceValue != oinfo._choiceValue) return false;
193                         return true;
194                 }
195
196                 public override int GetHashCode ()
197                 {
198                         return base.GetHashCode ();
199                 }
200         }
201
202         class XmlTypeMapElementInfoList: ArrayList
203         {
204                 public int IndexOfElement (string name, string namspace)
205                 {
206                         for (int n=0; n<Count; n++) {
207                                 XmlTypeMapElementInfo info = (XmlTypeMapElementInfo) base [n];
208                                 if (info.ElementName == name && info.Namespace == namspace)
209                                         return n;
210                         }
211                         return -1;
212                 }
213         }
214 }
215