2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / Microsoft.JScript / Microsoft.Vsa / BaseVsaEngine.cs
index 23e6594d22208f71ab49c25fda7e2d911d2d55aa..ef9d140f0f2f633024e611bbb48e2a65199fc905 100755 (executable)
@@ -7,10 +7,33 @@
 // (C) 2003, Cesar Lopez Nataren
 //
 
+//
+// 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.Reflection;
 using System.Security.Policy;
 using System.Threading;
+using Microsoft.JScript;
+using Microsoft.JScript.Vsa;
 
 namespace Microsoft.Vsa {
 
@@ -26,13 +49,10 @@ namespace Microsoft.Vsa {
                private bool siteAlreadySet;
                private bool running;
 
-               // indicates that RootMoniker and Site have been set.
-               private bool initialized;
-
                private bool namespaceNotSet;
                private bool supportDebug;
                private bool generateDebugInfo;
-               private bool compiled;
+               protected bool compiled;
                private bool dirty;
 
                private bool initNewCalled;
@@ -50,6 +70,10 @@ namespace Microsoft.Vsa {
                private string name;
                private string rootNamespace;
 
+               // FIXME: must set vars to proper values                
+               internal BaseVsaEngine ()
+               {}
+
                public BaseVsaEngine (string language, string version, bool supportDebug)
                {
                        this.language = language;
@@ -73,7 +97,6 @@ namespace Microsoft.Vsa {
                        this.rootNamespace = "";
                        this.namespaceNotSet = true;    
 
-                       this.initialized = false;
                        this.initNewCalled = false;
                        this.generateDebugInfo = false;
                        this.closed = false;
@@ -219,6 +242,7 @@ namespace Microsoft.Vsa {
                                else if (!initNewCalled)
                                        throw new VsaException (VsaError.EngineNotInitialized);
 
+                               items = new VsaItems ((VsaEngine) this);
                                return items;
                        }
                }
@@ -436,9 +460,21 @@ namespace Microsoft.Vsa {
 
                public virtual void Close ()
                {
+                       if (running)
+                               Reset ();
+                       else if (closed)
+                               throw new VsaException (VsaError.EngineClosed);
+                       else if (busy)
+                               throw new VsaException (VsaError.EngineBusy);
+
                        running = false;
+                       closed = true;
                }
 
+
+               //
+               // Count that AssemblyExpected exception may be thrown.
+               //
                public virtual bool Compile ()
                {
                        if (closed)
@@ -459,9 +495,20 @@ namespace Microsoft.Vsa {
 
                public virtual object GetOption (string name)
                {
-                       throw new NotImplementedException ();
+                       object opt;
+                       
+                       try {                   
+                               opt =  GetSpecificOption (name);
+                       } catch (VsaException e) {
+                               throw;
+                       }
+                       return opt;
                }
 
+               protected abstract object GetSpecificOption (string name);
+
+               protected abstract void SetSpecificOption (string name, object val);
+
                public virtual void InitNew ()
                {
                        if (closed)
@@ -535,6 +582,23 @@ namespace Microsoft.Vsa {
                }
 
                public abstract bool IsValidIdentifier (string ident);
+
+               internal bool Closed {
+                       get { return closed; }
+               }
+
+               internal bool Running {
+                       get { return running; }
+               }
+
+               internal bool Busy {
+                       get { return busy; }
+               }
+
+               internal bool InitNewCalled {
+                       get { return initNewCalled; }
+                       set { initNewCalled = value; }
+               }
        }
 
        public class BaseVsaSite : IVsaSite {