1 // System.Xml.Xsl.XsltArgumentList
\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
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
15 // The above copyright notice and this permission notice shall be
\r
16 // included in all copies or substantial portions of the Software.
\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
27 using System.Collections;
\r
28 using System.Security.Permissions;
\r
29 using System.Xml.XPath;
\r
31 namespace System.Xml.Xsl
\r
36 public class XsltArgumentList
\r
40 internal Hashtable extensionObjects;
\r
41 internal Hashtable parameters;
\r
45 #region Constructors
\r
47 public XsltArgumentList ()
\r
49 extensionObjects = new Hashtable ();
\r
50 parameters = new Hashtable ();
\r
58 public event XsltMessageEncounteredEventHandler XsltMessageEncountered;
\r
65 [PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
\r
66 public void AddExtensionObject (string namespaceUri, object extension)
\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
75 extensionObjects [namespaceUri] = extension;
\r
78 public void AddParam (string name, string namespaceUri, object parameter)
\r
81 if (namespaceUri == null)
\r
82 throw new ArgumentException ("The namespaceUri is a null reference.");
\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
88 throw new ArgumentException ("The parameter name is a null reference.");
\r
92 // verify that the name is a valid name according to
\r
93 // the W3C XML specification
\r
95 XmlQualifiedName qName = new XmlQualifiedName (name, namespaceUri);
\r
97 if (parameters.Contains (qName))
\r
98 throw new ArgumentException ("The namespaceUri already has a parameter associated with it.");
\r
100 parameter = ValidateParam (parameter);
\r
102 parameters [qName] = parameter;
\r
105 public void Clear ()
\r
107 extensionObjects.Clear ();
\r
108 parameters.Clear ();
\r
111 public object GetExtensionObject (string namespaceUri)
\r
113 return extensionObjects [namespaceUri];
\r
116 public object GetParam (string name, string namespaceUri)
\r
119 throw (new ArgumentException ("The parameter name is a null reference."));
\r
121 XmlQualifiedName qName = new XmlQualifiedName (name, namespaceUri);
\r
122 return parameters [qName];
\r
125 public object RemoveExtensionObject (string namespaceUri)
\r
127 object extensionObject = this.GetExtensionObject (namespaceUri);
\r
128 extensionObjects.Remove (namespaceUri);
\r
129 return extensionObject;
\r
132 public object RemoveParam (string name, string namespaceUri)
\r
134 XmlQualifiedName qName = new XmlQualifiedName (name, namespaceUri);
\r
135 object parameter = this.GetParam (name, namespaceUri);
\r
136 parameters.Remove (qName);
\r
140 private object ValidateParam (object parameter)
\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
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
156 return parameter.ToString ();
\r