2006-02-21 Atsushi Enomoto <atsushi@ximian.com>
[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                 }
58
59                 public TypeData TypeData
60                 {
61                         get { return _type; }
62                         set { _type = value; }
63                 }
64
65                 public object ChoiceValue
66                 {
67                         get { return _choiceValue; }
68                         set { _choiceValue = value; }
69                 }
70
71                 public string ElementName
72                 {
73                         get { return _elementName; }
74                         set { _elementName = value; }
75                 }
76
77                 public string Namespace
78                 {
79                         get { return _namespace; }
80                         set { _namespace = value; }
81                 }
82
83                 public string DataTypeNamespace
84                 {
85                         get 
86                         { 
87                                 if (_mappedType == null) return XmlSchema.Namespace;
88                                 else return _mappedType.XmlTypeNamespace;
89                         }
90                 }
91
92                 public string DataTypeName
93                 {
94                         get 
95                         { 
96                                 if (_mappedType == null) return TypeData.XmlType;
97                                 else return _mappedType.XmlType;
98                         }
99                 }
100
101                 public XmlSchemaForm Form 
102                 {
103                         get { return _form; }
104                         set { _form = value; }
105                 }
106
107                 public XmlTypeMapping MappedType
108                 {
109                         get { return _mappedType; }
110                         set { _mappedType = value; }
111                 }
112
113                 public bool IsNullable
114                 {
115                         get { return _isNullable; }
116                         set { _isNullable = value; }
117                 }
118
119                 internal bool IsPrimitive
120                 {
121                         get { return _mappedType == null; }
122                 }
123
124                 public XmlTypeMapMember Member
125                 {
126                         get { return _member; }
127                         set { _member = value; }
128                 }
129
130                 public int NestingLevel
131                 {
132                         get { return _nestingLevel; }
133                         set { _nestingLevel = value; }
134                 }
135
136                 public bool MultiReferenceType
137                 {
138                         get 
139                         { 
140                                 if (_mappedType != null) return _mappedType.MultiReferenceType;
141                                 else return false;
142                         }
143                 }
144
145                 public bool WrappedElement
146                 {
147                         get { return _wrappedElement; }
148                         set { _wrappedElement = value; }
149                 }
150
151                 public bool IsTextElement
152                 {
153                         get { return ElementName == "<text>"; }
154                         set { ElementName = "<text>"; Namespace = string.Empty; }
155                 }
156
157                 public bool IsUnnamedAnyElement
158                 {
159                         get { return ElementName == string.Empty; }
160                         set { ElementName = string.Empty; Namespace = string.Empty; }
161                 }
162
163                 public override bool Equals (object other)
164                 {
165                         XmlTypeMapElementInfo oinfo = (XmlTypeMapElementInfo)other;
166                         if (_elementName != oinfo._elementName) return false;
167                         if (_type.XmlType != oinfo._type.XmlType) return false;
168                         if (_namespace != oinfo._namespace) return false;
169                         if (_form != oinfo._form) return false;
170                         if (_type != oinfo._type) return false;
171                         if (_isNullable != oinfo._isNullable) return false;
172                         if (_choiceValue != null && !_choiceValue.Equals (oinfo._choiceValue)) return false;
173                         if (_choiceValue != oinfo._choiceValue) return false;
174                         return true;
175                 }
176
177                 public override int GetHashCode ()
178                 {
179                         return base.GetHashCode ();
180                 }
181         }
182
183         class XmlTypeMapElementInfoList: ArrayList
184         {
185                 public int IndexOfElement (string name, string namspace)
186                 {
187                         for (int n=0; n<Count; n++) {
188                                 XmlTypeMapElementInfo info = (XmlTypeMapElementInfo) base [n];
189                                 if (info.ElementName == name && info.Namespace == namspace)
190                                         return n;
191                         }
192                         return -1;
193                 }
194         }
195 }
196