Fix for running against RabbitMQ 2.2
[mono.git] / mcs / class / System.Web / System.Web.J2EE / J2EEUtils.cs
index c5d4d970b94b391f29a72ddaf83dc2e69643c4e8..64592c9667e218c61bd959c38566380b51c10c6c 100644 (file)
@@ -28,73 +28,77 @@ using System.Web.Util;
 using System.IO;
 using vmw.@internal.io;
 using vmw.common;
-
+using System.ComponentModel;
+using System.Threading;
 using javax.servlet;
+using System.Diagnostics;
 
 namespace System.Web.J2EE
 {
-       public class J2EEUtils
+       internal static class J2EEUtils
        {
-               public J2EEUtils()
-               {
-               }
+               #region InputStreamWrapper
 
-               public static string GetApplicationRealPath(ServletConfig config) 
+               public sealed class InputStreamWrapper : Stream
                {
-                       string realFs = config.getInitParameter(J2EEConsts.FILESYSTEM_ACCESS);
-                       if(realFs != null && realFs == J2EEConsts.ACCESS_FULL)
-                       {
-                               try 
-                               {
-                                       if(Path.IsPathRooted(config.getServletContext().getRealPath("")))
-                                               return config.getServletContext().getRealPath("").Replace("\\","/").TrimEnd('/');
-                               }
-                               catch (ArgumentException e)
-                               {
-                                       Console.WriteLine(e.Message);
+                       readonly java.io.InputStream _ins;
+
+                       public InputStreamWrapper (java.io.InputStream ins) {
+                               _ins = ins;
+                       }
+
+                       public override bool CanRead {
+                               get { return true; }
+                       }
+
+                       public override bool CanSeek {
+                               get { return _ins.markSupported (); }
+                       }
+
+                       public override bool CanWrite {
+                               get { return false; }
+                       }
+
+                       public override void Flush () {
+                       }
+
+                       public override long Length {
+                               get { return _ins.available (); }
+                       }
+
+                       public override long Position {
+                               get {
+                                       throw new NotSupportedException ();
                                }
-                               catch (Exception e)
-                               {
-                                       Console.WriteLine(e.Message);
+                               set {
+                                       throw new NotSupportedException ();
                                }
                        }
-                       return IAppDomainConfig.WAR_ROOT_SYMBOL;
-               }
 
-               public static string GetApplicationPhysicalPath(ServletConfig config) {
-                       string path = "";
-                       ServletContext context = config.getServletContext();
-                       string appDir = config.getInitParameter(IAppDomainConfig.APP_DIR_NAME);
-                       Console.WriteLine("appdir = {0}", appDir);
-                       if (appDir != null)
-                       {
-                               try
-                               {
-                                       java.io.File f = new java.io.File(appDir);
-                                       if(f.exists())
-                                       {
-                                               Console.WriteLine("Physical path= {0}", appDir);
-                                               path = appDir;
-                                       }
-                               }
-                               catch (Exception e)
-                               {
-                                       Console.WriteLine(e.Message + appDir + "is invalid or unaccessible." +
-                                               " If " + appDir + " really exists, check your security permissions"); 
-                               };
-                       }                       
-                       if (path == "")
-                       {
-                               path = GetApplicationRealPath(config);
+                       public override int Read (byte [] buffer, int offset, int count) {
+                               int r = _ins.read (TypeUtils.ToSByteArray (buffer), offset, count);
+                               return r < 0 ? 0 : r;
                        }
 
-                       if (!path.EndsWith ("/") && !path.EndsWith ("\\"))
-                               path += "/";
+                       public override long Seek (long offset, SeekOrigin origin) {
+                               throw new NotImplementedException ();
+                       }
+
+                       public override void SetLength (long value) {
+                               throw new NotSupportedException ();
+                       }
 
-                       Console.WriteLine("Physical path= {0}", path); 
-                       return path;
+                       public override void Write (byte [] buffer, int offset, int count) {
+                               throw new NotSupportedException ();
+                       }
+
+                       public override void Close () {
+                               _ins.close ();
+                       }
                }
 
+               #endregion
+
                public static int RunProc(string[] cmd)
                {       
                        java.lang.Runtime rt = java.lang.Runtime.getRuntime();
@@ -134,17 +138,197 @@ namespace System.Web.J2EE
                                String line=null;
                                while ( (line = br.readLine()) != null)
                                {
-#if DEBUG
-                                       Console.WriteLine(_type + ">" + line); 
-#endif
+                                       Debug.WriteLine(_type + ">" + line); 
                                }
                        } 
                        catch (Exception ex)
                        {
-#if DEBUG
-                               Console.WriteLine(ex);
+                               Debug.WriteLine (ex);
+                       }
+               }
+       }
+}
+
+#region FileSystemWatcher Stub
+
+namespace System.IO
+{
+       [DefaultEvent ("Changed")]
+#if NET_2_0
+       [IODescription ("")]
 #endif
+       public class FileSystemWatcher : Component, ISupportInitialize
+       {
+               public FileSystemWatcher ()
+                       : this (String.Empty) {
+               }
+
+               public FileSystemWatcher (string path)
+                       : this (path, "*.*") {
+               }
+
+               public FileSystemWatcher (string path, string filter) {
+               }
+
+               #region Properties
+
+               [DefaultValue (false)]
+               [IODescription ("Flag to indicate if this instance is active")]
+               public bool EnableRaisingEvents {
+                       get { return false; }
+                       set { }
+               }
+
+               [DefaultValue ("*.*")]
+               [IODescription ("File name filter pattern")]
+               [RecommendedAsConfigurable (true)]
+               [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
+               public string Filter {
+                       get { return "*.*"; }
+                       set { }
+               }
+
+               [DefaultValue (false)]
+               [IODescription ("Flag to indicate we want to watch subdirectories")]
+               public bool IncludeSubdirectories {
+                       get { return false; }
+                       set { }
+               }
+
+               [Browsable (false)]
+               [DefaultValue (8192)]
+               public int InternalBufferSize {
+                       get { return 8192; }
+                       set { }
+               }
+
+               [DefaultValue (NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.LastWrite)]
+               [IODescription ("Flag to indicate which change event we want to monitor")]
+               public NotifyFilters NotifyFilter {
+                       get { return NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.LastWrite; }
+                       set { }
+               }
+
+               [DefaultValue ("")]
+               [IODescription ("The directory to monitor")]
+               [RecommendedAsConfigurable (true)]
+               [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
+               [Editor ("System.Diagnostics.Design.FSWPathEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
+               public string Path {
+                       get { return String.Empty; }
+                       set { }
+               }
+
+               [DefaultValue (null)]
+               [IODescription ("The object used to marshal the event handler calls resulting from a directory change")]
+#if NET_2_0
+               [Browsable (false)]
+#endif
+               public ISynchronizeInvoke SynchronizingObject {
+                       get { return null; }
+                       set { }
+               }
+
+               #endregion // Properties
+
+               #region Methods
+
+               protected override void Dispose (bool disposing) {
+                       base.Dispose (disposing);
+               }
+
+               enum EventType
+               {
+                       FileSystemEvent,
+                       ErrorEvent,
+                       RenameEvent
+               }
+
+               void RaiseEvent (Delegate ev, EventArgs arg, EventType evtype) {
+                       if (ev == null)
+                               return;
+
+                       if (SynchronizingObject == null) {
+                               Delegate [] delegates = ev.GetInvocationList ();
+                               if (evtype == EventType.RenameEvent) {
+                                       foreach (RenamedEventHandler d in delegates) {
+                                               d.BeginInvoke (this, (RenamedEventArgs) arg, null, null);
+                                       }
+                               }
+                               else if (evtype == EventType.ErrorEvent) {
+                                       foreach (ErrorEventHandler d in delegates) {
+                                               d.BeginInvoke (this, (ErrorEventArgs) arg, null, null);
+                                       }
+                               }
+                               else {
+                                       foreach (FileSystemEventHandler d in delegates) {
+                                               d.BeginInvoke (this, (FileSystemEventArgs) arg, null, null);
+                                       }
+                               }
+                               return;
                        }
+
+                       SynchronizingObject.BeginInvoke (ev, new object [] { this, arg });
+               }
+
+               protected void OnChanged (FileSystemEventArgs e) {
+                       RaiseEvent (Changed, e, EventType.FileSystemEvent);
+               }
+
+               protected void OnCreated (FileSystemEventArgs e) {
+                       RaiseEvent (Created, e, EventType.FileSystemEvent);
+               }
+
+               protected void OnDeleted (FileSystemEventArgs e) {
+                       RaiseEvent (Deleted, e, EventType.FileSystemEvent);
+               }
+
+               protected void OnError (ErrorEventArgs e) {
+                       RaiseEvent (Error, e, EventType.ErrorEvent);
                }
+
+               protected void OnRenamed (RenamedEventArgs e) {
+                       RaiseEvent (Renamed, e, EventType.RenameEvent);
+               }
+
+               public WaitForChangedResult WaitForChanged (WatcherChangeTypes changeType) {
+                       return WaitForChanged (changeType, Timeout.Infinite);
+               }
+
+               public WaitForChangedResult WaitForChanged (WatcherChangeTypes changeType, int timeout) {
+                       return new WaitForChangedResult ();
+               }
+
+               #endregion
+
+               #region Events and Delegates
+
+               [IODescription ("Occurs when a file/directory change matches the filter")]
+               public event FileSystemEventHandler Changed;
+
+               [IODescription ("Occurs when a file/directory creation matches the filter")]
+               public event FileSystemEventHandler Created;
+
+               [IODescription ("Occurs when a file/directory deletion matches the filter")]
+               public event FileSystemEventHandler Deleted;
+
+               [Browsable (false)]
+               public event ErrorEventHandler Error;
+
+               [IODescription ("Occurs when a file/directory rename matches the filter")]
+               public event RenamedEventHandler Renamed;
+
+               #endregion // Events and Delegates
+
+               #region ISupportInitialize Members
+
+               public void BeginInit () {
+               }
+
+               public void EndInit () {
+               }
+
+               #endregion
        }
 }
+#endregion