2008-05-01 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mcs / class / System.XML / Mono.Xml.Xsl / MSXslScriptManager.cs
index a488b4a8faa81510522bd3285b8faeaf98eba0d2..cc61bbf49fe7284751700ebb088d5991f8d484f1 100644 (file)
@@ -7,6 +7,27 @@
 //
 // (C)2003 Atsushi Enomoto
 //
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
 using System;
 using System.Diagnostics;
 using System.Collections;
@@ -22,18 +43,19 @@ using System.Xml.Xsl;
 
 namespace Mono.Xml.Xsl {
 
-       [MonoTODO ("Correct evedence handling; test other than simple string case")]
-       public class MSXslScriptManager {
+       // FIXME: Correct evidence handling; test other than simple string case
+       internal class MSXslScriptManager {
                Hashtable scripts = new Hashtable ();
-               Evidence evidence;
 
                public MSXslScriptManager () {}
                
                public void AddScript (Compiler c)
                {
-                       MSXslScript s = new MSXslScript (c.Input, c.Evidence, scripts.Count);
-                       this.evidence = c.Evidence;
-                       scripts.Add (c.Input.GetNamespace (s.ImplementsPrefix), s.Compile ());
+                       MSXslScript s = new MSXslScript (c.Input, c.Evidence);
+                       string ns = c.Input.GetNamespace (s.ImplementsPrefix);
+                       if (ns == null)
+                               throw new XsltCompileException ("Specified prefix for msxsl:script was not found: " + s.ImplementsPrefix, null, c.Input);
+                       scripts.Add (ns, s.Compile (c.Input));
                }
                
                enum ScriptingLanguage {
@@ -53,15 +75,11 @@ namespace Mono.Xml.Xsl {
                        ScriptingLanguage language = ScriptingLanguage.JScript; // default = JScript.
                        string implementsPrefix = null;
                        string code = null;
-                       string suffix;
-                       XPathNavigator node;
                        Evidence evidence;
 
-                       public MSXslScript (XPathNavigator nav, Evidence evidence, int suffix)
+                       public MSXslScript (XPathNavigator nav, Evidence evidence)
                        {
-                               node = nav.Clone ();
                                this.evidence = evidence;
-                               this.suffix = suffix.ToString ();
                                code = nav.Value;
                                if (nav.MoveToFirstAttribute ()) {
                                        do {
@@ -107,9 +125,12 @@ namespace Mono.Xml.Xsl {
                                get { return code; }
                        }
                        
-                       public object Compile ()
+                       public object Compile (XPathNavigator node)
                        {
-                               string suffix = Guid.NewGuid ().ToString ().Replace ("-", String.Empty);
+#if TARGET_JVM
+                               throw new NotImplementedException ();
+#else
+                               string suffix = Guid.NewGuid ().ToString ("N");
                                switch (this.language) {
                                case ScriptingLanguage.CSharp:
                                        return new CSharpCompilerInfo ().GetScriptClass (Code, suffix, node, evidence);
@@ -120,6 +141,7 @@ namespace Mono.Xml.Xsl {
                                default:
                                        return null;
                                }
+#endif
                        }
                }
        }