Touch() 공개 메소드

'Touch' this template and thereby resetting the nextCheck field.
public Touch ( ) : void
리턴 void
예제 #1
0
        /// <summary> Takes an existing resource, and 'refreshes' it. This generally means that the source of the resource is checked for changes
        /// according to some cache/check algorithm and if the resource changed, then the resource data is reloaded and re-parsed.
        ///
        /// </summary>
        /// <param name="resource"> resource to refresh
        /// </param>
        /// <param name="encoding"> character encoding of the resource to refresh.
        ///
        /// </param>
        /// <throws>   ResourceNotFoundException  if template not found from current source for this Resource </throws>
        /// <throws>   ParseErrorException  if template cannot be parsed due to syntax (or other) Error. </throws>
        /// <throws>   Exception  if a problem in parse </throws>
        protected internal virtual Resource RefreshResource(Resource resource, string encoding)
        {
            /*
             * The resource knows whether it needs to be checked
             * or not, and the resource's loader can check to
             * see if the source has been modified. If both
             * these conditions are true then we must reload
             * the input stream and parse it to make a new
             * AST for the resource.
             */

            /*
             *  touch() the resource to reset the counters
             */
            resource.Touch();

            if (resource.IsSourceModified)
            {
                /*
                 *  now check encoding Info.  It's possible that the newly declared
                 *  encoding is different than the encoding already in the resource
                 *  this strikes me as bad...
                 */

                if (!string.Equals(resource.Encoding, encoding))
                {
                    log.Warn("Declared encoding for template '" + resource.Name + "' is different on reload. Old = '" + resource.Encoding + "' New = '" + encoding);

                    resource.Encoding = encoding;
                }

                /*
                 *  read how old the resource is _before_
                 *  processing (=>reading) it
                 */
                long howOldItWas = resource.ResourceLoader.GetLastModified(resource);

                string resourceKey = resource.Type + resource.Name;

                /*
                 * we create a copy to avoid partially overwriting a
                 * template which may be in use in another thread
                 */

                Resource newResource = ResourceFactory.getResource(resource.Name, resource.Type);

                newResource.RuntimeServices           = rsvc;
                newResource.Name                      = resource.Name;
                newResource.Encoding                  = resource.Encoding;
                newResource.ResourceLoader            = resource.ResourceLoader;
                newResource.ModificationCheckInterval = resource.ResourceLoader.ModificationCheckInterval;

                newResource.Process();
                newResource.LastModified = howOldItWas;
                resource = newResource;

                globalCache.Put(resourceKey, newResource);
            }
            return(resource);
        }
예제 #2
0
 protected internal void RefreshResource(Resource resource, string encoding)
 {
     if (resource.RequiresChecking())
     {
         resource.Touch();
         if (resource.IsSourceModified())
         {
             if (!resource.Encoding.Equals(encoding))
             {
                 this.rsvc.Error(string.Concat(new string[]
                 {
                     "Declared encoding for template '",
                     resource.Name,
                     "' is different on reload.  Old = '",
                     resource.Encoding,
                     "'  New = '",
                     encoding
                 }));
                 resource.Encoding = encoding;
             }
             long lastModified = resource.ResourceLoader.GetLastModified(resource);
             resource.Process();
             resource.LastModified = lastModified;
         }
     }
 }
예제 #3
0
        /// <summary>  Takes an existing resource, and 'refreshes' it.  This
        /// generally means that the source of the resource is checked
        /// for changes according to some cache/check algorithm
        /// and if the resource changed, then the resource data is
        /// reloaded and re-parsed.
        /// *
        /// </summary>
        /// <param name="resource">resource to refresh
        /// *
        /// @throws ResourceNotFoundException if template not found
        /// from current source for this Resource
        /// @throws ParseErrorException if template cannot be parsed due
        /// to syntax (or other) error.
        /// @throws Exception if a problem in parse
        ///
        /// </param>
        /// <param name="encoding"></param>
        protected internal void RefreshResource(Resource resource, String encoding)
        {
            /*
             * The resource knows whether it needs to be checked
             * or not, and the resource's loader can check to
             * see if the source has been modified. If both
             * these conditions are true then we must reload
             * the input stream and parse it to make a new
             * AST for the resource.
             */
            if (resource.RequiresChecking())
            {
                /*
                 *  touch() the resource to reset the counters
                 */

                resource.Touch();

                if (resource.IsSourceModified())
                {
                    /*
                     *  now check encoding info.  It's possible that the newly declared
                     *  encoding is different than the encoding already in the resource
                     *  this strikes me as bad...
                     */

                    if (!resource.Encoding.Equals(encoding))
                    {
                        runtimeServices.Error(
                            string.Format("Declared encoding for template '{0}' is different on reload.  Old = '{1}'  New = '{2}",
                                          resource.Name, resource.Encoding, encoding));

                        resource.Encoding = encoding;
                    }

                    /*
                     *  read how old the resource is _before_
                     *  processing (=>reading) it
                     */
                    long howOldItWas = resource.ResourceLoader.GetLastModified(resource);

                    /*
                     *  read in the fresh stream and parse
                     */

                    resource.Process();

                    /*
                     *  now set the modification info and reset
                     *  the modification check counters
                     */

                    resource.LastModified = howOldItWas;
                }
            }
        }
예제 #4
0
        protected internal Resource LoadResource(string resourceName, ResourceType resourceType, string encoding)
        {
            Resource resource = ResourceFactory.GetResource(resourceName, resourceType);

            resource.RuntimeServices = this.rsvc;
            resource.Name            = resourceName;
            resource.Encoding        = encoding;
            long           lastModified   = 0L;
            ResourceLoader resourceLoader = null;

            for (int i = 0; i < this.resourceLoaders.Count; i++)
            {
                resourceLoader          = (ResourceLoader)this.resourceLoaders[i];
                resource.ResourceLoader = resourceLoader;
                try
                {
                    if (resource.Process())
                    {
                        if (this.logWhenFound)
                        {
                            this.rsvc.Info("ResourceManager : found " + resourceName + " with loader " + resourceLoader.ClassName);
                        }
                        lastModified = resourceLoader.GetLastModified(resource);
                        break;
                    }
                }
                catch (ResourceNotFoundException)
                {
                }
            }
            if (resource.Data == null)
            {
                throw new ResourceNotFoundException("Unable to find resource '" + resourceName + "'");
            }
            resource.LastModified = lastModified;
            resource.ModificationCheckInterval = resourceLoader.ModificationCheckInterval;
            resource.Touch();
            return(resource);
        }
	/// <summary>  Takes an existing resource, and 'refreshes' it.  This
	/// generally means that the source of the resource is checked
	/// for changes according to some cache/check algorithm
	/// and if the resource changed, then the resource data is
	/// reloaded and re-parsed.
	/// *
	/// </summary>
	/// <param name="resource">resource to refresh
	/// *
	/// @throws ResourceNotFoundException if template not found
	/// from current source for this Resource
	/// @throws ParseErrorException if template cannot be parsed due
	/// to syntax (or other) error.
	/// @throws Exception if a problem in parse
	///
	/// </param>
	protected internal virtual void  refreshResource(Resource resource, System.String encoding) {
	    /*
	    * The resource knows whether it needs to be checked
	    * or not, and the resource's loader can check to
	    * see if the source has been modified. If both
	    * these conditions are true then we must reload
	    * the input stream and parse it to make a new
	    * AST for the resource.
	    */
	    if (resource.RequiresChecking()) {
		/*
		*  touch() the resource to reset the counters
		*/

		resource.Touch();

		if (resource.IsSourceModified()) {
		    /*
		    *  now check encoding info.  It's possible that the newly declared
		    *  encoding is different than the encoding already in the resource
		    *  this strikes me as bad...
		    */

		    if (!resource.Encoding.Equals(encoding)) {
			rsvc.error("Declared encoding for template '" + resource.Name + "' is different on reload.  Old = '" + resource.Encoding + "'  New = '" + encoding);

			resource.Encoding = encoding;
		    }

		    /*
		    *  read how old the resource is _before_
		    *  processing (=>reading) it
		    */
		    long howOldItWas = resource.ResourceLoader.getLastModified(resource);

		    /*
		    *  read in the fresh stream and parse
		    */

		    resource.Process();

		    /*
		    *  now set the modification info and reset
		    *  the modification check counters
		    */

		    resource.LastModified = howOldItWas;
		}
	    }
	}
예제 #6
0
        /// <summary> Loads a resource from the current set of resource loaders.
        ///
        /// </summary>
        /// <param name="resourceName"> The name of the resource to retrieve.
        /// </param>
        /// <param name="resourceType"> The type of resource (<code>RESOURCE_TEMPLATE</code>, <code>RESOURCE_CONTENT</code>, etc.).
        /// </param>
        /// <param name="encoding"> The character encoding to use.
        ///
        /// </param>
        /// <returns>  Resource with the template parsed and ready.
        ///
        /// </returns>
        /// <throws>   ResourceNotFoundException  if template not found from any available source. </throws>
        /// <throws>   ParseErrorException  if template cannot be parsed due to syntax (or other) Error. </throws>
        /// <throws>   Exception  if a problem in parse </throws>
        protected internal virtual Resource LoadResource(string resourceName, int resourceType, string encoding)
        {
            Resource resource = CreateResource(resourceName, resourceType);

            resource.RuntimeServices = rsvc;
            resource.Name            = resourceName;
            resource.Encoding        = encoding;

            /*
             * Now we have to try to find the appropriate
             * loader for this resource. We have to cycle through
             * the list of available resource loaders and see
             * which one gives us a stream that we can use to
             * make a resource with.
             */

            long howOldItWas = 0;

            for (IEnumerator <ResourceLoader> it = resourceLoaders.GetEnumerator(); it.MoveNext();)
            {
                ResourceLoader resourceLoader = it.Current;
                resource.ResourceLoader = resourceLoader;

                /*
                 *  catch the ResourceNotFound exception
                 *  as that is ok in our new multi-loader environment
                 */

                try
                {
                    if (resource.Process())
                    {
                        /*
                         *  FIXME  (gmj)
                         *  moved in here - technically still
                         *  a problem - but the resource needs to be
                         *  processed before the loader can figure
                         *  it out due to to the new
                         *  multi-path support - will revisit and fix
                         */

                        if (logWhenFound && log.DebugEnabled)
                        {
                            log.Debug("ResourceManager : found " + resourceName + " with loader " + resourceLoader.ClassName);
                        }

                        howOldItWas = resourceLoader.GetLastModified(resource);

                        break;
                    }
                }
                catch (ResourceNotFoundException)
                {
                    /*
                     *  that's ok - it's possible to fail in
                     *  multi-loader environment
                     */
                }
            }

            /*
             * Return null if we can't find a resource.
             */
            if (resource.Data == null)
            {
                throw new ResourceNotFoundException("Unable to find resource '" + resourceName + "'");
            }

            /*
             *  some final cleanup
             */

            resource.LastModified = howOldItWas;
            resource.ModificationCheckInterval = resource.ResourceLoader.ModificationCheckInterval;

            resource.Touch();

            return(resource);
        }
예제 #7
0
        /// <summary>
        /// Loads a resource from the current set of resource loaders
        /// </summary>
        /// <param name="resourceName">The name of the resource to retrieve.</param>
        /// <param name="resourceType">The type of resource (<code>Template</code>,
        /// <code>Content</code>, etc.).
        /// </param>
        /// <param name="encoding"> The character encoding to use.</param>
        /// <returns>Resource with the template parsed and ready.
        /// @throws ResourceNotFoundException if template not found
        /// from any available source.
        /// @throws ParseErrorException if template cannot be parsed due
        /// to syntax (or other) error.
        /// @throws Exception if a problem in parse
        /// </returns>
        protected internal Resource LoadResource(String resourceName, ResourceType resourceType, String encoding)
        {
            Resource resource = ResourceFactory.GetResource(resourceName, resourceType);

            resource.RuntimeServices = runtimeServices;

            resource.Name     = resourceName;
            resource.Encoding = encoding;

            /*
             * Now we have to try to find the appropriate
             * loader for this resource. We have to cycle through
             * the list of available resource loaders and see
             * which one gives us a stream that we can use to
             * make a resource with.
             */

            long howOldItWas = 0;             // Initialize to avoid warnings

            ResourceLoader resourceLoader = null;

            for (int i = 0; i < resourceLoaders.Count; i++)
            {
                resourceLoader          = (ResourceLoader)resourceLoaders[i];
                resource.ResourceLoader = resourceLoader;

                /*
                 *  catch the ResourceNotFound exception
                 *  as that is ok in our new multi-loader environment
                 */

                try
                {
                    if (resource.Process())
                    {
                        /*
                         *  FIXME  (gmj)
                         *  moved in here - technically still
                         *  a problem - but the resource needs to be
                         *  processed before the loader can figure
                         *  it out due to to the new
                         *  multi-path support - will revisit and fix
                         */

                        if (logWhenFound)
                        {
                            runtimeServices.Info(
                                string.Format("ResourceManager : found {0} with loader {1}", resourceName, resourceLoader.ClassName));
                        }

                        howOldItWas = resourceLoader.GetLastModified(resource);
                        break;
                    }
                }
                catch (ResourceNotFoundException)
                {
                    /*
                     *  that's ok - it's possible to fail in
                     *  multi-loader environment
                     */
                }
            }

            /*
             * Return null if we can't find a resource.
             */
            if (resource.Data == null)
            {
                throw new ResourceNotFoundException(string.Format("Unable to find resource '{0}'", resourceName));
            }

            /*
             *  some final cleanup
             */

            resource.LastModified = howOldItWas;

            resource.ModificationCheckInterval = resourceLoader.ModificationCheckInterval;

            resource.Touch();

            return(resource);
        }