(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / Microsoft.JScript / Microsoft.Vsa / BaseVsaEngine.cs
blobef9d140f0f2f633024e611bbb48e2a65199fc905
1 //
2 // BaseVsaEngine.cs:
3 //
4 // Author:
5 // Cesar Lopez Nataren (cesar@ciencias.unam.mx)
6 //
7 // (C) 2003, Cesar Lopez Nataren
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.Reflection;
33 using System.Security.Policy;
34 using System.Threading;
35 using Microsoft.JScript;
36 using Microsoft.JScript.Vsa;
38 namespace Microsoft.Vsa {
40 public abstract class BaseVsaEngine : IVsaEngine {
42 private const int ROOT_MONIKER_MAX_SIZE = 256;
43 private bool monikerAlreadySet;
44 private string rootMoniker;
46 private bool closed;
47 private bool busy;
48 private bool empty;
49 private bool siteAlreadySet;
50 private bool running;
52 private bool namespaceNotSet;
53 private bool supportDebug;
54 private bool generateDebugInfo;
55 protected bool compiled;
56 private bool dirty;
58 private bool initNewCalled;
60 private IVsaSite site;
61 private IVsaItems items;
63 // its default value has to be "JScript"
64 private string language;
66 private string version;
67 private int lcid;
68 private Assembly assembly;
69 private Evidence evidence;
70 private string name;
71 private string rootNamespace;
73 // FIXME: must set vars to proper values
74 internal BaseVsaEngine ()
77 public BaseVsaEngine (string language, string version, bool supportDebug)
79 this.language = language;
81 // FIXME: I think we must ensure that version it's
82 // compliant with versionformat Major.Minor.Build.Revision.
83 // Not sure about what Exception throw.
84 this.version = version;
86 this.supportDebug = supportDebug;
87 this.site = null;
88 this.rootMoniker = "";
89 this.running = false;
90 this.evidence = null;
91 this.compiled = false;
92 this.dirty = false;
94 this.lcid = Thread.CurrentThread.CurrentCulture.LCID;
95 this.name = "";
97 this.rootNamespace = "";
98 this.namespaceNotSet = true;
100 this.initNewCalled = false;
101 this.generateDebugInfo = false;
102 this.closed = false;
103 this.items = null;
104 this.siteAlreadySet = false;
107 public System._AppDomain AppDomain {
108 get { throw new NotImplementedException (); }
109 set { throw new NotImplementedException (); }
112 // FIXME: research if we can use "get" Evidence when: running and busy.
113 public Evidence Evidence {
114 get {
115 if (closed)
116 throw new VsaException (VsaError.EngineClosed);
117 else if (!initNewCalled)
118 throw new VsaException (VsaError.EngineNotInitialized);
120 return evidence;
123 set {
124 if (closed)
125 throw new VsaException (VsaError.EngineClosed);
126 else if (running)
127 throw new VsaException (VsaError.EngineRunning);
128 else if (busy)
129 throw new VsaException (VsaError.EngineBusy);
130 else if (!initNewCalled)
131 throw new VsaException (VsaError.EngineNotInitialized);
133 evidence = value;
137 public string ApplicationBase {
138 get { throw new NotImplementedException (); }
139 set { throw new NotImplementedException (); }
142 public Assembly Assembly {
143 get {
144 if (closed)
145 throw new VsaException (VsaError.EngineClosed);
146 else if (!running)
147 throw new VsaException (VsaError.EngineNotRunning);
148 else if (busy)
149 throw new VsaException (VsaError.EngineBusy);
151 return assembly;
156 // FIXME: research if we can "get" it when running and busy.
157 // FIXME: when do we throw VsaException with
158 // VsaError set to DebugInfoNotSupported?
160 public bool GenerateDebugInfo {
161 get {
162 if (closed)
163 throw new VsaException (VsaError.EngineClosed);
164 else if (!initNewCalled)
165 throw new VsaException (VsaError.EngineNotInitialized);
167 return generateDebugInfo;
170 set {
171 if (closed)
172 throw new VsaException (VsaError.EngineClosed);
173 else if (running)
174 throw new VsaException (VsaError.EngineRunning);
175 else if (busy)
176 throw new VsaException (VsaError.EngineBusy);
177 else if (!initNewCalled)
178 throw new VsaException (VsaError.EngineNotInitialized);
179 else if (!supportDebug)
180 throw new VsaException (VsaError.DebugInfoNotSupported);
182 generateDebugInfo = value;
186 public bool IsCompiled {
187 get {
188 if (dirty)
189 return false;
190 else if (closed)
191 throw new VsaException (VsaError.EngineClosed);
192 else if (busy)
193 throw new VsaException (VsaError.EngineBusy);
194 else if (!initNewCalled)
195 throw new VsaException (VsaError.EngineNotInitialized);
197 return compiled;
202 // FIXME: Research if we can "set" it when running
203 public bool IsDirty {
204 set {
205 if (closed)
206 throw new VsaException (VsaError.EngineClosed);
208 dirty = value;
211 get {
212 if (closed)
213 throw new VsaException (VsaError.EngineClosed);
214 else if (busy)
215 throw new VsaException (VsaError.EngineBusy);
216 else if (!initNewCalled)
217 throw new VsaException (VsaError.EngineNotInitialized);
219 return dirty;
223 public bool IsRunning {
224 get {
225 if (closed)
226 throw new VsaException (VsaError.EngineClosed);
227 else if (busy)
228 throw new VsaException (VsaError.EngineBusy);
229 else if (!initNewCalled)
230 throw new VsaException (VsaError.EngineNotInitialized);
232 return running;
236 public IVsaItems Items {
237 get {
238 if (closed)
239 throw new VsaException (VsaError.EngineClosed);
240 else if (busy)
241 throw new VsaException (VsaError.EngineBusy);
242 else if (!initNewCalled)
243 throw new VsaException (VsaError.EngineNotInitialized);
245 items = new VsaItems ((VsaEngine) this);
246 return items;
251 public string Language {
252 get {
253 if (closed)
254 throw new VsaException (VsaError.EngineClosed);
255 else if (busy)
256 throw new VsaException (VsaError.EngineBusy);
257 else if (!initNewCalled)
258 throw new VsaException (VsaError.EngineNotInitialized);
260 return language;
264 // FIXME: research when LCIDNotSupported gets thrown.
265 public int LCID {
266 get {
267 if (closed)
268 throw new VsaException (VsaError.EngineClosed);
269 else if (busy)
270 throw new VsaException (VsaError.EngineBusy);
271 else if (!initNewCalled)
272 throw new VsaException (VsaError.EngineNotInitialized);
273 else if (running)
274 throw new VsaException (VsaError.EngineRunning);
276 return lcid;
279 set {
280 if (closed)
281 throw new VsaException (VsaError.EngineClosed);
282 else if (busy)
283 throw new VsaException (VsaError.EngineBusy);
284 else if (!initNewCalled)
285 throw new VsaException (VsaError.EngineNotInitialized);
286 else if (running)
287 throw new VsaException (VsaError.EngineRunning);
289 lcid = value;
294 // FIXME: we must throw VsaException, VsaError set to EngineNameInUse
295 // when setting and name is already in use.
296 public string Name {
297 get {
298 if (closed)
299 throw new VsaException (VsaError.EngineClosed);
300 else if (busy)
301 throw new VsaException (VsaError.EngineBusy);
302 else if (!initNewCalled)
303 throw new VsaException (VsaError.EngineNotInitialized);
304 else if (running)
305 throw new VsaException (VsaError.EngineRunning);
307 return name;
310 set {
311 if (closed)
312 throw new VsaException (VsaError.EngineClosed);
313 else if (busy)
314 throw new VsaException (VsaError.EngineBusy);
315 else if (!initNewCalled)
316 throw new VsaException (VsaError.EngineNotInitialized);
317 else if (running)
318 throw new VsaException (VsaError.EngineRunning);
320 name = value;
324 // FIXME: We have to check - when setting - that the moniker
325 // is not already in use.
326 public string RootMoniker {
327 get {
328 if (closed)
329 throw new VsaException (VsaError.EngineClosed);
330 else if (busy)
331 throw new VsaException (VsaError.EngineBusy);
333 return rootMoniker;
336 set {
337 if (monikerAlreadySet)
338 throw new VsaException (VsaError.RootMonikerAlreadySet);
339 else if (closed)
340 throw new VsaException (VsaError.EngineClosed);
341 else if (busy)
342 throw new VsaException (VsaError.EngineBusy);
343 else {
344 MonikerState state = ValidateRootMoniker (value);
346 switch (state) {
347 case MonikerState.Valid:
348 rootMoniker = value;
349 monikerAlreadySet = true;
350 break;
352 case MonikerState.Invalid:
353 throw new VsaException (VsaError.RootMonikerInvalid);
355 case MonikerState.ProtocolInvalid:
356 throw new VsaException (VsaError.RootMonikerProtocolInvalid);
362 internal static MonikerState ValidateRootMoniker (string n)
364 if (n == null || n == "" || n.Length > ROOT_MONIKER_MAX_SIZE)
365 return MonikerState.Invalid;
367 try {
368 Uri uri = new Uri (n);
369 string protocol = uri.Scheme;
371 if (protocol == "http" || protocol == "file" ||
372 protocol == "ftp" || protocol == "gopher" ||
373 protocol == "https" || protocol == "mailto")
374 return MonikerState.ProtocolInvalid;
376 return MonikerState.Valid;
378 } catch (UriFormatException e) {
379 return MonikerState.Invalid;
384 // FIXME: we must check - when setting - that the value is a valid
385 // namespace (research what does that mean :-)). If not the case
386 // VsaException must be thrown, set to VsaError.NamespaceInvalid
387 public string RootNamespace {
388 get {
389 if (closed)
390 throw new VsaException (VsaError.EngineClosed);
391 else if (busy)
392 throw new VsaException (VsaError.EngineBusy);
393 else if (!initNewCalled)
394 throw new VsaException (VsaError.EngineNotInitialized);
395 else if (running)
396 throw new VsaException (VsaError.EngineRunning);
398 return rootNamespace;
401 set {
402 if (closed)
403 throw new VsaException (VsaError.EngineClosed);
404 else if (busy)
405 throw new VsaException (VsaError.EngineBusy);
406 else if (!initNewCalled)
407 throw new VsaException (VsaError.EngineNotInitialized);
408 else if (running)
409 throw new VsaException (VsaError.EngineRunning);
411 rootNamespace = value;
412 namespaceNotSet = false;
416 public IVsaSite Site {
417 get {
418 if (closed)
419 throw new VsaException (VsaError.EngineClosed);
420 else if (busy)
421 throw new VsaException (VsaError.EngineBusy);
422 else if (!monikerAlreadySet)
423 throw new VsaException (VsaError.RootMonikerNotSet);
425 return site;
428 set {
429 if (!monikerAlreadySet)
430 throw new VsaException (VsaError.RootMonikerNotSet);
431 else if (siteAlreadySet)
432 throw new VsaException (VsaError.SiteAlreadySet);
433 else if (closed)
434 throw new VsaException (VsaError.EngineClosed);
435 else if (busy)
436 throw new VsaException (VsaError.EngineBusy);
437 else if (value == null)
438 throw new VsaException (VsaError.SiteInvalid);
440 site = value;
441 siteAlreadySet = true;
446 // Version Format: Major.Minor.Revision.Build
448 public string Version {
449 get {
450 if (closed)
451 throw new VsaException (VsaError.EngineClosed);
452 else if (busy)
453 throw new VsaException (VsaError.EngineBusy);
454 else if (!initNewCalled)
455 throw new VsaException (VsaError.EngineNotInitialized);
457 return version;
461 public virtual void Close ()
463 if (running)
464 Reset ();
465 else if (closed)
466 throw new VsaException (VsaError.EngineClosed);
467 else if (busy)
468 throw new VsaException (VsaError.EngineBusy);
470 running = false;
471 closed = true;
476 // Count that AssemblyExpected exception may be thrown.
478 public virtual bool Compile ()
480 if (closed)
481 throw new VsaException (VsaError.EngineClosed);
482 else if (busy)
483 throw new VsaException (VsaError.EngineBusy);
484 else if (empty)
485 throw new VsaException (VsaError.EngineEmpty);
486 else if (running)
487 throw new VsaException (VsaError.EngineRunning);
488 else if (!initNewCalled)
489 throw new VsaException (VsaError.EngineNotInitialized);
490 else if (namespaceNotSet)
491 throw new VsaException (VsaError.RootNamespaceNotSet);
493 return false;
496 public virtual object GetOption (string name)
498 object opt;
500 try {
501 opt = GetSpecificOption (name);
502 } catch (VsaException e) {
503 throw;
505 return opt;
508 protected abstract object GetSpecificOption (string name);
510 protected abstract void SetSpecificOption (string name, object val);
512 public virtual void InitNew ()
514 if (closed)
515 throw new VsaException (VsaError.EngineClosed);
516 else if (busy)
517 throw new VsaException (VsaError.EngineBusy);
518 else if (initNewCalled)
519 throw new VsaException (VsaError.EngineInitialized);
520 else if (!monikerAlreadySet)
521 throw new VsaException (VsaError.RootMonikerNotSet);
522 else if (!siteAlreadySet)
523 throw new VsaException (VsaError.SiteNotSet);
525 initNewCalled = true;
528 public virtual void LoadSourceState (IVsaPersistSite site)
530 throw new NotImplementedException ();
533 public virtual void Reset ()
535 if (closed)
536 throw new VsaException (VsaError.EngineClosed);
537 else if (busy)
538 throw new VsaException (VsaError.EngineBusy);
539 else if (!running)
540 throw new VsaException (VsaError.EngineNotRunning);
542 running = false;
543 assembly = null;
546 public virtual void RevokeCache ()
548 throw new NotImplementedException ();
551 public virtual void Run ()
553 if (closed)
554 throw new VsaException (VsaError.EngineClosed);
555 else if (busy)
556 throw new VsaException (VsaError.EngineBusy);
557 else if (running)
558 throw new VsaException (VsaError.EngineRunning);
559 else if (!monikerAlreadySet)
560 throw new VsaException (VsaError.RootMonikerNotSet);
561 else if (!siteAlreadySet)
562 throw new VsaException (VsaError.SiteNotSet);
563 else if (namespaceNotSet)
564 throw new VsaException (VsaError.RootNamespaceNotSet);
566 running = true;
569 public virtual void SetOption (string name, object value)
571 dirty = true;
574 public virtual void SaveCompiledState (out byte [] pe, out byte [] debugInfo)
576 throw new NotImplementedException ();
579 public virtual void SaveSourceState (IVsaPersistSite site)
581 throw new NotImplementedException ();
584 public abstract bool IsValidIdentifier (string ident);
586 internal bool Closed {
587 get { return closed; }
590 internal bool Running {
591 get { return running; }
594 internal bool Busy {
595 get { return busy; }
598 internal bool InitNewCalled {
599 get { return initNewCalled; }
600 set { initNewCalled = value; }
604 public class BaseVsaSite : IVsaSite {
606 public virtual byte [] Assembly {
607 get { throw new NotImplementedException (); }
610 public virtual byte [] DebugInfo {
611 get { throw new NotImplementedException (); }
614 public virtual void GetCompiledState (out byte [] pe, out byte [] debugInfo)
616 throw new NotImplementedException ();
619 public virtual object GetEventSourceInstance (string itemName, string eventSourceName)
621 throw new NotImplementedException ();
624 public virtual object GetGlobalInstance (string name)
626 throw new NotImplementedException ();
629 public virtual void Notify (string notify, object optional)
631 throw new NotImplementedException ();
634 public virtual bool OnCompilerError (IVsaError error)
636 throw new NotImplementedException ();
641 public abstract class BaseVsaStartup {
643 public void SetSite (IVsaSite site)
645 throw new NotImplementedException ();
648 public abstract void Startup ();
650 public abstract void Shutdown ();
653 internal enum MonikerState {
654 Valid,
655 Invalid,
656 ProtocolInvalid