* BuildEngine.cs (BuildProjectFile): Use AddProperty method to specify
[mono.git] / mcs / class / System.XML / System.Xml.Xsl / XsltArgumentList.cs
1 // System.Xml.Xsl.XsltArgumentList\r
2 //\r
3 // Author: Tim Coleman <tim@timcoleman.com>\r
4 // (C) Copyright 2002 Tim Coleman\r
5 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)\r
6 //\r
7 // Permission is hereby granted, free of charge, to any person obtaining\r
8 // a copy of this software and associated documentation files (the\r
9 // "Software"), to deal in the Software without restriction, including\r
10 // without limitation the rights to use, copy, modify, merge, publish,\r
11 // distribute, sublicense, and/or sell copies of the Software, and to\r
12 // permit persons to whom the Software is furnished to do so, subject to\r
13 // the following conditions:\r
14 // \r
15 // The above copyright notice and this permission notice shall be\r
16 // included in all copies or substantial portions of the Software.\r
17 // \r
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
19 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
21 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
23 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
25 //\r
26 \r
27 using System.Collections;\r
28 using System.Security.Permissions;\r
29 using System.Xml.XPath;\r
30 \r
31 namespace System.Xml.Xsl\r
32 {\r
33 #if !NET_2_0\r
34         sealed\r
35 #endif\r
36         public class XsltArgumentList\r
37         {\r
38                 #region Fields\r
39 \r
40                 internal Hashtable extensionObjects;\r
41                 internal Hashtable parameters;\r
42 \r
43                 #endregion\r
44 \r
45                 #region Constructors\r
46 \r
47                 public XsltArgumentList ()\r
48                 {\r
49                         extensionObjects = new Hashtable ();\r
50                         parameters = new Hashtable ();\r
51                 }\r
52 \r
53                 #endregion\r
54 \r
55                 #region Event\r
56 #if NET_2_0\r
57 \r
58                 public event XsltMessageEncounteredEventHandler XsltMessageEncountered;\r
59 \r
60 #endif\r
61                 #endregion\r
62 \r
63                 #region Methods\r
64 \r
65                 [PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]\r
66                 public void AddExtensionObject (string namespaceUri, object extension)\r
67                 {\r
68                         if (namespaceUri == null)\r
69                                 throw new ArgumentException ("The namespaceUri is a null reference.");\r
70                         if (namespaceUri == "http://www.w3.org/1999/XSL/Transform")\r
71                                 throw new ArgumentException ("The namespaceUri is http://www.w3.org/1999/XSL/Transform.");\r
72                         if (extensionObjects.Contains (namespaceUri))\r
73                                 throw new ArgumentException ("The namespaceUri already has an extension object associated with it.");\r
74 \r
75                         extensionObjects [namespaceUri] = extension;\r
76                 }\r
77 \r
78                 public void AddParam (string name, string namespaceUri, object parameter)\r
79                 {\r
80 \r
81                         if (namespaceUri == null)\r
82                                 throw new ArgumentException ("The namespaceUri is a null reference.");\r
83 \r
84                         if (namespaceUri == "http://www.w3.org/1999/XSL/Transform")\r
85                                 throw new ArgumentException ("The namespaceUri is http://www.w3.org/1999/XSL/Transform.");\r
86 \r
87                         if (name == null)\r
88                                 throw new ArgumentException ("The parameter name is a null reference.");\r
89 \r
90 \r
91                         // TODO:\r
92                         // verify that the name is a valid name according to\r
93                         // the W3C XML specification\r
94 \r
95                         XmlQualifiedName qName = new XmlQualifiedName (name, namespaceUri);\r
96 \r
97                         if (parameters.Contains (qName))\r
98                                 throw new ArgumentException ("The namespaceUri already has a parameter associated with it.");\r
99 \r
100                         parameter = ValidateParam (parameter);\r
101 \r
102                         parameters [qName] = parameter;\r
103                 }\r
104 \r
105                 public void Clear ()\r
106                 {\r
107                         extensionObjects.Clear ();\r
108                         parameters.Clear ();\r
109                 }\r
110 \r
111                 public object GetExtensionObject (string namespaceUri)\r
112                 {\r
113                         return extensionObjects [namespaceUri];\r
114                 }\r
115 \r
116                 public object GetParam (string name, string namespaceUri)\r
117                 {\r
118                         if (name == null)\r
119                                 throw (new ArgumentException ("The parameter name is a null reference."));\r
120 \r
121                         XmlQualifiedName qName = new XmlQualifiedName (name, namespaceUri);\r
122                         return parameters [qName];\r
123                 }\r
124 \r
125                 public object RemoveExtensionObject (string namespaceUri)\r
126                 {\r
127                         object extensionObject = this.GetExtensionObject (namespaceUri);\r
128                         extensionObjects.Remove (namespaceUri);\r
129                         return extensionObject;\r
130                 }\r
131 \r
132                 public object RemoveParam (string name, string namespaceUri)\r
133                 {\r
134                         XmlQualifiedName qName = new XmlQualifiedName (name, namespaceUri);\r
135                         object parameter = this.GetParam (name, namespaceUri);\r
136                         parameters.Remove (qName);\r
137                         return parameter;\r
138                 }\r
139 \r
140                 private object ValidateParam (object parameter)\r
141                 {\r
142                         if (parameter is string)                return parameter;\r
143                         if (parameter is bool)                  return parameter;\r
144                         if (parameter is double)                return parameter;\r
145                         if (parameter is XPathNavigator)        return parameter;\r
146                         if (parameter is XPathNodeIterator)     return parameter;\r
147 \r
148                         if (parameter is Int16)                 return (double) (Int16) parameter;\r
149                         if (parameter is UInt16)                return (double) (UInt16) parameter;\r
150                         if (parameter is Int32)                 return (double) (Int32) parameter;\r
151                         if (parameter is Int64)                 return (double) (Int64) parameter;\r
152                         if (parameter is UInt64)                return (double) (UInt64) parameter;\r
153                         if (parameter is Single)                return (double) (Single) parameter;\r
154                         if (parameter is decimal)               return (double) (decimal) parameter;\r
155 \r
156                         return parameter.ToString ();\r
157                 }\r
158 \r
159                 #endregion\r
160         }\r
161 }\r