using System.Runtime.Remoting;
using System.Web.Util;
using System.Xml;
+#if TARGET_J2EE
+using vmw.@internal.io;
+using vmw.common;
+using System.Web.J2EE;
+#endif
namespace System.Web.Configuration
{
class WebConfigurationSettings
{
+#if TARGET_J2EE
+ static private IConfigurationSystem oldConfig {
+ get {
+ return (IConfigurationSystem)AppDomain.CurrentDomain.GetData("WebConfigurationSettings.oldConfig");
+ }
+ set {
+ AppDomain.CurrentDomain.SetData("WebConfigurationSettings.oldConfig", value);
+ }
+ }
+
+ static private WebDefaultConfig config {
+ get {
+ return (WebDefaultConfig)AppDomain.CurrentDomain.GetData("WebConfigurationSettings.config");
+ }
+ set {
+ AppDomain.CurrentDomain.SetData("WebConfigurationSettings.config", value);
+ }
+ }
+#else
static IConfigurationSystem oldConfig;
static WebDefaultConfig config;
+#endif
static string machineConfigPath;
const BindingFlags privStatic = BindingFlags.NonPublic | BindingFlags.Static;
-
+ static readonly object lockobj = new object ();
+
private WebConfigurationSettings ()
{
}
public static void Init ()
{
- lock (typeof (WebConfigurationSettings)) {
+ lock (lockobj) {
if (config != null)
return;
public static string MachineConfigPath {
get {
- lock (typeof (WebConfigurationSettings)) {
+ lock (lockobj) {
if (machineConfigPath != null)
return machineConfigPath;
//
class WebDefaultConfig : IConfigurationSystem
{
+#if TARGET_J2EE
+ static private WebDefaultConfig instance {
+ get {
+ WebDefaultConfig val = (WebDefaultConfig)AppDomain.CurrentDomain.GetData("WebDefaultConfig.instance");
+ if (val == null) {
+ val = new WebDefaultConfig();
+ AppDomain.CurrentDomain.SetData("WebDefaultConfig.instance", val);
+ }
+ return val;
+ }
+ set {
+ AppDomain.CurrentDomain.SetData("WebDefaultConfig.instance", value);
+ }
+ }
+#else
static WebDefaultConfig instance;
+#endif
Hashtable fileToConfig;
HttpContext firstContext;
bool initCalled;
tempDir = "";
realpath = HttpRuntime.AppDomainAppPath;
}
-
ConfigurationData parent = GetConfigFromFileName (tempDir, context);
if (wcfile == null) {
data = new ConfigurationData (parent, null, realpath);
data.DirName = dir;
data.LoadFromFile (wcfile);
fileToConfig [dir] = data;
+#if !TARGET_JVM // no remoting support yet in Grasshopper
RemotingConfiguration.Configure (wcfile);
+#endif
}
return data;
initCalled = true;
}
}
-
- static string GetAppConfigPath ()
- {
- AppDomainSetup currentInfo = AppDomain.CurrentDomain.SetupInformation;
-
- string configFile = currentInfo.ConfigurationFile;
- if (configFile == null || configFile.Length == 0)
- return null;
-
- return configFile;
-
- }
}
class FileWatcherCache
Hashtable cacheTable;
string path;
string filename;
+#if !TARGET_JVM // no file watcher support yet in Grasshopper
FileSystemWatcher watcher;
+#endif
ConfigurationData data;
public FileWatcherCache (ConfigurationData data)
if (!Directory.Exists (path))
return;
+#if !TARGET_JVM
watcher = new FileSystemWatcher (this.path, this.filename);
FileSystemEventHandler handler = new FileSystemEventHandler (SetChanged);
watcher.Created += handler;
watcher.Changed += handler;
watcher.Deleted += handler;
watcher.EnableRaisingEvents = true;
+#endif
}
+#if !TARGET_JVM
void SetChanged (object o, FileSystemEventArgs args)
{
lock (data) {
data.LoadFromFile (args.FullPath);
}
}
+#endif
public object this [string key] {
get {
public void Close ()
{
+#if !TARGET_JVM
if (watcher != null)
watcher.EnableRaisingEvents = false;
+#endif
}
- }
+ }
enum AllowDefinition
{
Hashtable locations;
string fileName;
string dirname;
- string realdir;
static object removedMark = new object ();
static object groupMark = new object ();
static object emptyMark = new object ();
public ConfigurationData (ConfigurationData parent, string filename, string realdir)
{
this.parent = (parent == this) ? null : parent;
- this.realdir = realdir;
if (filename == null) {
this.fileName = Path.Combine (realdir, "*.config");
} else {
public bool LoadFromFile (string fileName)
{
this.fileName = fileName;
- if (fileName == null || !File.Exists (fileName))
- return false;
+ Stream fs = null;
+ if (fileName == null || !File.Exists (fileName)) {
+#if TARGET_J2EE
+ if (fileName != null && fileName.EndsWith("machine.config"))
+ {
+ if (fileName.StartsWith("/"))
+ fileName = fileName.Substring(1);
+ java.lang.ClassLoader cl = (java.lang.ClassLoader)AppDomain.CurrentDomain.GetData("GH_ContextClassLoader");
+ if (cl == null)
+ return false;
+ java.io.InputStream inputStream = cl.getResourceAsStream(fileName);
+ fs = (Stream)IOUtils.getStream(inputStream);
+ }
+ else
+#endif
+ return false;
+ }
XmlTextReader reader = null;
try {
- FileStream fs = new FileStream (fileName, FileMode.Open, FileAccess.Read);
+ if (fs == null)
+ fs = new FileStream (fileName, FileMode.Open, FileAccess.Read);
reader = new XmlTextReader (fs);
InitRead (reader);
ReadConfig (reader, false);