Default implementation of the resource cache for the default ResourceManager. The cache uses a least recently used (LRU) algorithm, with a maximum size specified via the resource.manager.cache.size property (identified by the {@link org.apache.velocity.runtime.RuntimeConstants#RESOURCE_MANAGER_CACHE_SIZE} constant). This property get be set to 0 or less for a greedy, unbounded cache (the behavior from pre-v1.5). *
Наследование: ResourceCache
	/// <summary> Initialize the ResourceManager. It is assumed
	/// that assembleSourceInitializers() has been
	/// called before this is run.
	/// </summary>
	public virtual void  initialize(RuntimeServices rs) {
	    rsvc = rs;

	    rsvc.info("Default ResourceManager initializing. (" + this.GetType() + ")");

	    ResourceLoader resourceLoader;

	    assembleResourceLoaderInitializers();

	    for (int i = 0; i < sourceInitializerList.Count; i++) {
		ExtendedProperties configuration = (ExtendedProperties) sourceInitializerList[i];
		System.String loaderClass = configuration.GetString("class");

		if (loaderClass == null) {
		    rsvc.error("Unable to find '" + configuration.GetString(RESOURCE_LOADER_IDENTIFIER) + ".resource.loader.class' specification in configuation." + " This is a critical value.  Please adjust configuration.");
		    continue;
		}

		resourceLoader = ResourceLoaderFactory.getLoader(rsvc, loaderClass);
		resourceLoader.commonInit(rsvc, configuration);
		resourceLoader.init(configuration);
		resourceLoaders.Add(resourceLoader);

	    }

	    /*
	    * now see if this is overridden by configuration
	    */

	    logWhenFound = rsvc.getBoolean(NVelocity.Runtime.RuntimeConstants_Fields.RESOURCE_MANAGER_LOGWHENFOUND, true);

	    /*
	    *  now, is a global cache specified?
	    */
	    System.String claz = rsvc.getString(NVelocity.Runtime.RuntimeConstants_Fields.RESOURCE_MANAGER_CACHE_CLASS);
	    System.Object o = null;

	    if (claz != null && claz.Length > 0) {
		try {
		    Type type = System.Type.GetType(claz);
		    o = System.Activator.CreateInstance(type);
		} catch (System.Exception cnfe) {
		    System.String err = "The specified class for ResourceCache (" + claz + ") does not exist (or is not accessible to the current classlaoder).";
		    rsvc.error(err);
		    o = null;
		}

		if (!(o is ResourceCache)) {
		    System.String err = "The specified class for ResourceCache (" + claz + ") does not implement NVelocity.Runtime.Resource.ResourceCache." + " Using default ResourceCache implementation.";
		    rsvc.error(err);
		    o = null;
		}
	    }

	    /*
	    *  if we didn't get through that, just use the default.
	    */
	    if (o == null) {
		o = new ResourceCacheImpl();
	    }

	    globalCache = (ResourceCache) o;
	    globalCache.initialize(rsvc);
	    rsvc.info("Default ResourceManager initialization complete.");
	}
Пример #2
0
        /// <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.");
            }
        }
Пример #3
0
        /// <summary> Initialize the ResourceManager. It is assumed
        /// that assembleSourceInitializers() has been
        /// called before this is run.
        /// </summary>
        public virtual void  initialize(RuntimeServices rs)
        {
            rsvc = rs;

            rsvc.info("Default ResourceManager initializing. (" + this.GetType() + ")");

            ResourceLoader resourceLoader;

            assembleResourceLoaderInitializers();

            for (int i = 0; i < sourceInitializerList.Count; i++)
            {
                ExtendedProperties configuration = (ExtendedProperties)sourceInitializerList[i];
                System.String      loaderClass   = configuration.GetString("class");

                if (loaderClass == null)
                {
                    rsvc.error("Unable to find '" + configuration.GetString(RESOURCE_LOADER_IDENTIFIER) + ".resource.loader.class' specification in configuation." + " This is a critical value.  Please adjust configuration.");
                    continue;
                }

                resourceLoader = ResourceLoaderFactory.getLoader(rsvc, loaderClass);
                resourceLoader.commonInit(rsvc, configuration);
                resourceLoader.init(configuration);
                resourceLoaders.Add(resourceLoader);
            }

            /*
             * now see if this is overridden by configuration
             */

            logWhenFound = rsvc.getBoolean(NVelocity.Runtime.RuntimeConstants_Fields.RESOURCE_MANAGER_LOGWHENFOUND, true);

            /*
             *  now, is a global cache specified?
             */
            System.String claz = rsvc.getString(NVelocity.Runtime.RuntimeConstants_Fields.RESOURCE_MANAGER_CACHE_CLASS);
            System.Object o    = null;

            if (claz != null && claz.Length > 0)
            {
                try {
                    Type type = System.Type.GetType(claz);
                    o = System.Activator.CreateInstance(type);
                } catch (System.Exception cnfe) {
                    System.String err = "The specified class for ResourceCache (" + claz + ") does not exist (or is not accessible to the current classlaoder).";
                    rsvc.error(err);
                    o = null;
                }

                if (!(o is ResourceCache))
                {
                    System.String err = "The specified class for ResourceCache (" + claz + ") does not implement NVelocity.Runtime.Resource.ResourceCache." + " Using default ResourceCache implementation.";
                    rsvc.error(err);
                    o = null;
                }
            }

            /*
             *  if we didn't get through that, just use the default.
             */
            if (o == null)
            {
                o = new ResourceCacheImpl();
            }

            globalCache = (ResourceCache)o;
            globalCache.initialize(rsvc);
            rsvc.info("Default ResourceManager initialization complete.");
        }
Пример #4
0
        /// <summary>
        /// Initialize the ResourceManager.
        /// </summary>
        public void Initialize(IRuntimeServices rs)
        {
            runtimeServices = rs;

            runtimeServices.Info(string.Format("Default ResourceManager initializing. ({0})", GetType()));

            ResourceLoader resourceLoader;

            AssembleResourceLoaderInitializers();

            for (int i = 0; i < sourceInitializerList.Count; i++)
            {
                ExtendedProperties configuration = (ExtendedProperties)sourceInitializerList[i];
                String             loaderClass   = configuration.GetString("class");

                if (loaderClass == null)
                {
                    runtimeServices.Error(
                        string.Format(
                            "Unable to find '{0}.resource.loader.class' specification in configuration. This is a critical value.  Please adjust configuration.",
                            configuration.GetString(RESOURCE_LOADER_IDENTIFIER)));
                    continue;
                }

                resourceLoader = ResourceLoaderFactory.getLoader(runtimeServices, loaderClass);
                resourceLoader.CommonInit(runtimeServices, configuration);
                resourceLoader.Init(configuration);
                resourceLoaders.Add(resourceLoader);
            }

            // now see if this is overridden by configuration
            logWhenFound = runtimeServices.GetBoolean(RuntimeConstants.RESOURCE_MANAGER_LOGWHENFOUND, true);

            // now, is a global cache specified?
            String resourceManagerCacheClassName = runtimeServices.GetString(RuntimeConstants.RESOURCE_MANAGER_CACHE_CLASS);
            Object o = null;

            if (resourceManagerCacheClassName != null && resourceManagerCacheClassName.Length > 0)
            {
                try
                {
                    Type type = Type.GetType(resourceManagerCacheClassName);
                    o = Activator.CreateInstance(type);
                }
                catch (Exception)
                {
                    String err =
                        string.Format(
                            "The specified class for ResourceCache ({0}) does not exist (or is not accessible to the current classLoader).",
                            resourceManagerCacheClassName);
                    runtimeServices.Error(err);
                    o = null;
                }

                if (!(o is ResourceCache))
                {
                    String err =
                        string.Format(
                            "The specified class for ResourceCache ({0}) does not implement NVelocity.Runtime.Resource.ResourceCache. Using default ResourceCache implementation.",
                            resourceManagerCacheClassName);
                    runtimeServices.Error(err);
                    o = null;
                }
            }

            // if we didn't get through that, just use the default.
            if (o == null)
            {
                o = new ResourceCacheImpl();
            }

            globalCache = (ResourceCache)o;
            globalCache.initialize(runtimeServices);
            runtimeServices.Info("Default ResourceManager initialization complete.");
        }
Пример #5
0
		/// <summary>
		/// Initialize the ResourceManager.
		/// </summary>
		public void Initialize(IRuntimeServices rs)
		{
			runtimeServices = rs;

			runtimeServices.Info(string.Format("Default ResourceManager initializing. ({0})", GetType()));

			ResourceLoader resourceLoader;

			AssembleResourceLoaderInitializers();

			for(int i = 0; i < sourceInitializerList.Count; i++)
			{
				ExtendedProperties configuration = (ExtendedProperties) sourceInitializerList[i];
				String loaderClass = configuration.GetString("class");

				if (loaderClass == null)
				{
					runtimeServices.Error(
						string.Format(
							"Unable to find '{0}.resource.loader.class' specification in configuration. This is a critical value.  Please adjust configuration.",
							configuration.GetString(RESOURCE_LOADER_IDENTIFIER)));
					continue;
				}

				resourceLoader = ResourceLoaderFactory.getLoader(runtimeServices, loaderClass);
				resourceLoader.CommonInit(runtimeServices, configuration);
				resourceLoader.Init(configuration);
				resourceLoaders.Add(resourceLoader);
			}

			// now see if this is overridden by configuration
			logWhenFound = runtimeServices.GetBoolean(RuntimeConstants.RESOURCE_MANAGER_LOGWHENFOUND, true);

			// now, is a global cache specified?
			String resourceManagerCacheClassName = runtimeServices.GetString(RuntimeConstants.RESOURCE_MANAGER_CACHE_CLASS);
			Object o = null;

			if (resourceManagerCacheClassName != null && resourceManagerCacheClassName.Length > 0)
			{
				try
				{
					Type type = Type.GetType(resourceManagerCacheClassName);
					o = Activator.CreateInstance(type);
				}
				catch(Exception)
				{
					String err =
						string.Format(
							"The specified class for ResourceCache ({0}) does not exist (or is not accessible to the current classLoader).",
							resourceManagerCacheClassName);
					runtimeServices.Error(err);
					o = null;
				}

				if (!(o is ResourceCache))
				{
					String err =
						string.Format(
							"The specified class for ResourceCache ({0}) does not implement NVelocity.Runtime.Resource.ResourceCache. Using default ResourceCache implementation.",
							resourceManagerCacheClassName);
					runtimeServices.Error(err);
					o = null;
				}
			}

			// if we didn't get through that, just use the default.
			if (o == null)
			{
				o = new ResourceCacheImpl();
			}

			globalCache = (ResourceCache) o;
			globalCache.initialize(runtimeServices);
			runtimeServices.Info("Default ResourceManager initialization complete.");
		}