2010-04-06 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System.XML / System.Xml.Serialization / SerializationCodeGeneratorConfiguration.cs
blobd2e2f47f40c6c132a1caba6c1db231321525ea8c
1 //
2 // System.Xml.Serialization.SerializationCodeGeneratorConfiguration.cs:
3 //
4 // Author:
5 // Lluis Sanchez Gual (lluis@ximian.com)
6 //
7 // (C) 2002, 2003 Ximian, Inc. http://www.ximian.com
8 //
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.
31 using System;
32 using System.Collections;
33 using System.Xml.Serialization;
35 namespace System.Xml.Serialization
37 [XmlType ("configuration")]
38 internal class SerializationCodeGeneratorConfiguration
40 [XmlElement ("serializer")]
41 public SerializerInfo[] Serializers;
44 [XmlType ("serializer")]
45 internal class SerializerInfo
47 [XmlAttribute ("class")]
48 public string ClassName;
50 [XmlAttribute ("assembly")]
51 public string Assembly;
53 [XmlElement ("reader")]
54 public string ReaderClassName;
56 [XmlElement ("writer")]
57 public string WriterClassName;
59 [XmlElement ("baseSerializer")]
60 public string BaseSerializerClassName;
62 [XmlElement ("implementation")]
63 public string ImplementationClassName;
65 [XmlElement ("noreader")]
66 public bool NoReader;
68 [XmlElement ("nowriter")]
69 public bool NoWriter;
71 [XmlElement ("generateAsInternal")]
72 public bool GenerateAsInternal;
74 [XmlElement ("namespace")]
75 public string Namespace;
77 [XmlArray ("namespaceImports")]
78 [XmlArrayItem ("namespaceImport")]
79 public string [] NamespaceImports;
81 [System.ComponentModel.DefaultValue (SerializationFormat.Literal)]
82 public SerializationFormat SerializationFormat = SerializationFormat.Literal;
84 [XmlElement ("outFileName")]
85 public string OutFileName;
87 [XmlArray ("readerHooks")]
88 public Hook[] ReaderHooks;
90 [XmlArray ("writerHooks")]
91 public Hook[] WriterHooks;
93 public ArrayList GetHooks (HookType hookType, XmlMappingAccess dir, HookAction action, Type type, string member)
95 if ((dir & XmlMappingAccess.Read) != 0)
96 return FindHook (ReaderHooks, hookType, action, type, member);
97 if ((dir & XmlMappingAccess.Write) != 0)
98 return FindHook (WriterHooks, hookType, action, type, member);
99 else
100 throw new Exception ("INTERNAL ERROR");
103 ArrayList FindHook (Hook[] hooks, HookType hookType, HookAction action, Type type, string member)
105 ArrayList foundHooks = new ArrayList ();
106 if (hooks == null) return foundHooks;
108 foreach (Hook hook in hooks)
110 if (action == HookAction.InsertBefore && (hook.InsertBefore == null || hook.InsertBefore == ""))
111 continue;
112 else if (action == HookAction.InsertAfter && (hook.InsertAfter == null || hook.InsertAfter == ""))
113 continue;
114 else if (action == HookAction.Replace && (hook.Replace == null || hook.Replace == ""))
115 continue;
117 if (hook.HookType != hookType)
118 continue;
120 if (hook.Select != null)
122 if (hook.Select.TypeName != null && hook.Select.TypeName != "")
123 if (hook.Select.TypeName != type.FullName) continue;
125 if (hook.Select.TypeMember != null && hook.Select.TypeMember != "")
126 if (hook.Select.TypeMember != member) continue;
128 if (hook.Select.TypeAttributes != null && hook.Select.TypeAttributes.Length > 0)
130 object[] ats = type.GetCustomAttributes (true);
131 bool found = false;
132 foreach (object at in ats)
133 if (Array.IndexOf (hook.Select.TypeAttributes, at.GetType().FullName) != -1) { found = true; break; }
134 if (!found) continue;
137 foundHooks.Add (hook);
139 return foundHooks;
143 [XmlType ("hook")]
144 internal class Hook
146 [XmlAttribute ("type")]
147 public HookType HookType;
149 [XmlElement ("select")]
150 public Select Select;
152 [XmlElement ("insertBefore")]
153 public string InsertBefore;
155 [XmlElement ("insertAfter")]
156 public string InsertAfter;
158 [XmlElement ("replace")]
159 public string Replace;
161 public string GetCode (HookAction action)
163 if (action == HookAction.InsertBefore)
164 return InsertBefore;
165 else if (action == HookAction.InsertAfter)
166 return InsertAfter;
167 else
168 return Replace;
172 [XmlType ("select")]
173 internal class Select
175 [XmlElement ("typeName")]
176 public string TypeName;
178 [XmlElement("typeAttribute")]
179 public string[] TypeAttributes;
181 [XmlElement ("typeMember")]
182 public string TypeMember;
185 internal enum HookAction
187 InsertBefore,
188 InsertAfter,
189 Replace
192 [XmlType ("hookType")]
193 internal enum HookType
195 attributes,
196 elements,
197 unknownAttribute,
198 unknownElement,
199 member,
200 type