public void Initialize(IRuntimeServices rs) { this.rsvc = rs; this.rsvc.Info("Default ResourceManager initializing. (" + base.GetType() + ")"); this.AssembleResourceLoaderInitializers(); for (int i = 0; i < this.sourceInitializerList.Count; i++) { ExtendedProperties extendedProperties = (ExtendedProperties)this.sourceInitializerList[i]; string @string = extendedProperties.GetString("class"); if (@string == null) { this.rsvc.Error("Unable to find '" + extendedProperties.GetString("_RESOURCE_LOADER_IDENTIFIER_") + ".resource.loader.class' specification in configuation. This is a critical value. Please adjust configuration."); } else { ResourceLoader loader = ResourceLoaderFactory.getLoader(this.rsvc, @string); loader.CommonInit(this.rsvc, extendedProperties); loader.Init(extendedProperties); this.resourceLoaders.Add(loader); } } this.logWhenFound = this.rsvc.GetBoolean("resource.manager.logwhenfound", true); string string2 = this.rsvc.GetString("resource.manager.cache.class"); object obj = null; if (string2 != null && string2.Length > 0) { try { Type type = Type.GetType(string2); obj = Activator.CreateInstance(type); } catch (System.Exception var_7_135) { string message = "The specified class for ResourceCache (" + string2 + ") does not exist (or is not accessible to the current classloader)."; this.rsvc.Error(message); obj = null; } if (!(obj is ResourceCache)) { string message = "The specified class for ResourceCache (" + string2 + ") does not implement NVelocity.Runtime.Resource.ResourceCache. Using default ResourceCache implementation."; this.rsvc.Error(message); obj = null; } } if (obj == null) { obj = new ResourceCacheImpl(); } this.globalCache = (ResourceCache)obj; this.globalCache.initialize(this.rsvc); this.rsvc.Info("Default ResourceManager initialization complete."); }
/// <summary> Initialize the ResourceManager. /// /// </summary> /// <param name="rsvc"> The Runtime Services object which is associated with this Resource Manager. /// /// </param> /// <throws> Exception </throws> public virtual void Initialize(IRuntimeServices rsvc) { lock (syncOjb) { if (isInit) { log.Debug("Re-initialization of ResourceLoader attempted and ignored."); return; } ResourceLoader resourceLoader = null; this.rsvc = rsvc; log = rsvc.Log; log.Trace("Default ResourceManager initializing. (" + this.GetType() + ")"); AssembleResourceLoaderInitializers(); for (IEnumerator it = sourceInitializerList.GetEnumerator(); it.MoveNext();) { /** * Resource loader can be loaded either via class name or be passed * in as an instance. */ ExtendedProperties configuration = (ExtendedProperties)it.Current; string loaderClass = StringUtils.NullTrim(configuration.GetString("class")); ResourceLoader loaderInstance = (ResourceLoader)configuration["instance"]; if (loaderInstance != null) { resourceLoader = loaderInstance; } else if (loaderClass != null) { resourceLoader = ResourceLoaderFactory.GetLoader(rsvc, loaderClass); } else { string msg = "Unable to find '" + configuration.GetString(RESOURCE_LOADER_IDENTIFIER) + ".resource.loader.class' specification in configuration." + " This is a critical value. Please adjust configuration."; log.Error(msg); throw new System.Exception(msg); } resourceLoader.CommonInit(rsvc, configuration); resourceLoader.Init(configuration); resourceLoaders.Add(resourceLoader); } /* * now see if this is overridden by configuration */ logWhenFound = rsvc.GetBoolean(NVelocity.Runtime.RuntimeConstants.RESOURCE_MANAGER_LOGWHENFOUND, true); /* * now, is a global cache specified? */ string cacheClassName = rsvc.GetString(RuntimeConstants.RESOURCE_MANAGER_CACHE_CLASS); object cacheObject = null; if (!string.IsNullOrEmpty(cacheClassName)) { try { cacheObject = System.Activator.CreateInstance(Type.GetType(cacheClassName.Replace(';', ','))); } catch (System.Exception cnfe) { string msg = "The specified class for ResourceCache (" + cacheClassName + ") does not exist or is not accessible to the current classloader."; log.Error(msg, cnfe); throw cnfe; } if (!(cacheObject is IResourceCache)) { string msg = "The specified resource cache class (" + cacheClassName + ") must implement " + typeof(IResourceCache).FullName; log.Error(msg); throw new System.SystemException(msg); } } /* * if we didn't Get through that, just use the default. */ if (cacheObject == null) { cacheObject = new ResourceCacheImpl(); } globalCache = (IResourceCache)cacheObject; globalCache.Initialize(rsvc); log.Trace("Default ResourceManager initialization complete."); } }