コード例 #1
0
        /// <summary>  Invoked by VMContext when Context.put() is called for a proxied reference.
        /// *
        /// </summary>
        /// <param name="context">context to modify via direct placement, or AST.setValue()
        /// </param>
        /// <param name="o"> new value of reference
        /// </param>
        /// <returns>Object currently null
        ///
        /// </returns>
        public Object setObject(IInternalContextAdapter context, Object o)
        {
            /*
             *  if we are a reference, we could be updating a property
             */

            if (type == ParserTreeConstants.REFERENCE)
            {
                if (numTreeChildren > 0)
                {
                    /*
                     *  we are a property, and being updated such as
                     *  #foo( $bar.BangStart)
                     */

                    try
                    {
                        ((ASTReference)nodeTree).SetValue(context, o);
                    }
                    catch (MethodInvocationException methodInvocationException)
                    {
                        runtimeServices.Error(
                            string.Format("VMProxyArg.getObject() : method invocation error setting value : {0}", methodInvocationException));
                    }
                }
                else
                {
                    /*
                     *  we are a 'single level' reference like $foo, so we can set
                     *  out context directly
                     */

                    context.Put(singleLevelRef, o);

                    // alternate impl : userContext.put( singleLevelRef, o);
                }
            }
            else
            {
                /*
                 *  if we aren't a reference, then we simply switch type,
                 *  get a new value, and it doesn't go into the context
                 *
                 *  in current impl, this shouldn't happen.
                 */

                type         = GENERALSTATIC;
                staticObject = o;

                runtimeServices.Error(
                    string.Format("VMProxyArg.setObject() : Programmer error : I am a constant!  No setting! : {0} / {1}",
                                  contextReference, callerReference));
            }

            return(null);
        }
コード例 #2
0
        public static ResourceLoader getLoader(IRuntimeServices rs, string loaderClassName)
        {
            ResourceLoader result;

            try
            {
                loaderClassName = loaderClassName.Replace(';', ',');
                Type           type           = Type.GetType(loaderClassName);
                object         obj            = Activator.CreateInstance(type);
                ResourceLoader resourceLoader = (ResourceLoader)obj;
                rs.Info("Resource Loader Instantiated: " + resourceLoader.GetType().FullName);
                result = resourceLoader;
            }
            catch (System.Exception e)
            {
                rs.Error("Problem instantiating the template loader.\nLook at your properties file and make sure the\nname of the template loader is correct. Here is the\nerror: " + StringUtils.StackTrace(e));
                throw new System.Exception("Problem initializing template loader: " + loaderClassName + "\nError is: " + StringUtils.StackTrace(e));
            }
            return(result);
        }
コード例 #3
0
ファイル: Macro.cs プロジェクト: SkelletonX/DDTServer
        public static void processAndRegister(IRuntimeServices rs, INode node, string sourceTemplate)
        {
            int childrenCount = node.ChildrenCount;

            if (childrenCount < 2)
            {
                rs.Error("#macro error : Velocimacro must have name as 1st argument to #macro()");
            }
            else
            {
                string[]      argArray         = Macro.getArgArray(node);
                IList         aSTAsStringArray = Macro.getASTAsStringArray(node.GetChild(childrenCount - 1));
                StringBuilder stringBuilder    = new StringBuilder();
                for (int i = 0; i < aSTAsStringArray.Count; i++)
                {
                    stringBuilder.Append(aSTAsStringArray[i]);
                }
                string macro = stringBuilder.ToString();
                rs.AddVelocimacro(argArray[0], macro, argArray, sourceTemplate);
            }
        }
コード例 #4
0
        /// <summary>
        /// Used by Parser.java to process VMs within the parsing process
        ///
        /// processAndRegister() doesn't actually render the macro to the output
        /// Processes the macro body into the internal representation used by the
        /// VelocimacroProxy objects, and if not currently used, adds it
        /// to the macro Factory
        /// </summary>
        public static void processAndRegister(IRuntimeServices rs, INode node, String sourceTemplate)
        {
            // There must be at least one arg to  #macro,
            // the name of the VM.  Note that 0 following
            // args is ok for naming blocks of HTML
            int numArgs = node.ChildrenCount;

            // this number is the # of args + 1.  The + 1
            // is for the block tree
            if (numArgs < 2)
            {
                // error - they didn't name the macro or
                // define a block
                rs.Error("#macro error : Velocimacro must have name as 1st argument to #macro()");

                return;
            }

            // get the arguments to the use of the VM
            String[] argArray = getArgArray(node);

            // now, try and eat the code block. Pass the root.
            IList macroArray = getASTAsStringArray(node.GetChild(numArgs - 1));

            // make a big string out of our macro
            StringBuilder temp = new StringBuilder();

            for (int i = 0; i < macroArray.Count; i++)
            {
                temp.Append(macroArray[i]);
            }

            String macroBody = temp.ToString();

            // now, try to add it.  The Factory controls permissions,
            // so just give it a whack...
            rs.AddVelocimacro(argArray[0], macroBody, argArray, sourceTemplate);

            return;
        }
コード例 #5
0
        public virtual Object Init(IInternalContextAdapter context, Object data)
        {
            /*
             * hold onto the RuntimeServices
             */

            runtimeServices = (IRuntimeServices)data;

            int i, k = ChildrenCount;

            for (i = 0; i < k; i++)
            {
                try
                {
                    GetChild(i).Init(context, data);
                }
                catch (ReferenceException re)
                {
                    runtimeServices.Error(re);
                }
            }

            return(data);
        }
コード例 #6
0
		/// <summary>
		/// Gets the loader specified in the configuration file.
		/// </summary>
		/// <returns>TemplateLoader</returns>
		public static ResourceLoader getLoader(IRuntimeServices rs, String loaderClassName)
		{
			try
			{
				// since properties are parsed into arrays with commas, 
				// something else needed to be used
				loaderClassName = loaderClassName.Replace(';', ',');
				Type loaderType = Type.GetType(loaderClassName);
				Object o = Activator.CreateInstance(loaderType);
				ResourceLoader loader = (ResourceLoader) o;

				rs.Info(string.Format("Resource Loader Instantiated: {0}", loader.GetType().FullName));

				return loader;
			}
			catch(System.Exception e)
			{
				rs.Error(
					string.Format(
						"Problem instantiating the template loader.\nLook at your properties file and make sure the\nname of the template loader is correct. Here is the\nerror: {0}",
						e));
				throw new System.Exception(string.Format("Problem initializing template loader: {0}\nError is: {1}", loaderClassName, e));
			}
		}
コード例 #7
0
        /// <summary>
        /// Gets the loader specified in the configuration file.
        /// </summary>
        /// <returns>TemplateLoader</returns>
        public static ResourceLoader getLoader(IRuntimeServices rs, String loaderClassName)
        {
            try
            {
                // since properties are parsed into arrays with commas,
                // something else needed to be used
                loaderClassName = loaderClassName.Replace(';', ',');
                Type           loaderType = Type.GetType(loaderClassName);
                Object         o          = Activator.CreateInstance(loaderType);
                ResourceLoader loader     = (ResourceLoader)o;

                rs.Info(string.Format("Resource Loader Instantiated: {0}", loader.GetType().FullName));

                return(loader);
            }
            catch (System.Exception e)
            {
                rs.Error(
                    string.Format(
                        "Problem instantiating the template loader.\nLook at your properties file and make sure the\nname of the template loader is correct. Here is the\nerror: {0}",
                        e));
                throw new System.Exception(string.Format("Problem initializing template loader: {0}\nError is: {1}", loaderClassName, e));
            }
        }
コード例 #8
0
        /// <summary>  Creates a new logging system or returns an existing one
        /// specified by the application.
        /// </summary>
        public static ILogSystem CreateLogSystem(IRuntimeServices runtimeServices)
        {
            ILogSystem logSystem;
            // if a logSystem was set as a configuration value, use that.
            // This is any class the user specifies.
            Object o = runtimeServices.GetProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM);

            logSystem = o as ILogSystem;
            if (logSystem != null)
            {
                logSystem.Init(runtimeServices);

                return(logSystem);
            }

            // otherwise, see if a class was specified.  You
            // can put multiple classes, and we use the first one we find.
            //
            // Note that the default value of this property contains both the
            // AvalonLogSystem and the SimpleLog4JLogSystem for convenience -
            // so we use whichever we find.
            IList  classes = new ArrayList();
            Object obj     = runtimeServices.GetProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS);

            // we might have a list, or not - so check
            if (obj is IList)
            {
                classes = (IList)obj;
            }
            else if (obj is String)
            {
                classes.Add(obj);
            }

            // now run through the list, trying each.  It's ok to
            // fail with a class not found, as we do this to also
            // search out a default simple file logger
            foreach (String className in classes)
            {
                if (className != null && className.Length > 0)
                {
                    runtimeServices.Info(string.Format("Trying to use logger class {0}", className));

                    try
                    {
                        Type type = Type.GetType(className);
                        o         = Activator.CreateInstance(type);
                        logSystem = o as ILogSystem;
                        if (logSystem == null)
                        {
                            runtimeServices.Error(string.Format("The specified logger class {0} isn't a valid LogSystem", className));
                        }
                        else
                        {
                            logSystem.Init(runtimeServices);

                            runtimeServices.Info(string.Format("Using logger class {0}", className));

                            return(logSystem);
                        }
                    }
                    catch (ApplicationException applicationException)
                    {
                        runtimeServices.Debug(
                            string.Format("Couldn't find class {0} or necessary supporting classes in classpath. Exception : {1}", className,
                                          applicationException));
                    }
                }
            }

            // if the above failed, then we are in deep doo-doo, as the
            // above means that either the user specified a logging class
            // that we can't find, there weren't the necessary
            // dependencies in the classpath for it, or there were no
            // dependencies for the default logger.
            // Since we really don't know,
            // then take a wack at the log4net as a last resort.
            try
            {
                logSystem = new NullLogSystem();
                logSystem.Init(runtimeServices);
            }
            catch (ApplicationException applicationException)
            {
                String error =
                    string.Format(
                        "PANIC : NVelocity cannot find any of the specified or default logging systems in the classpath, or the classpath doesn't contain the necessary classes to support them. Please consult the documentation regarding logging. Exception : {0}",
                        applicationException);

                Console.Out.WriteLine(error);
                Console.Error.WriteLine(error);

                throw;
            }

            runtimeServices.Info("Using log4net as logger of final resort.");

            return(logSystem);
        }
コード例 #9
0
ファイル: LogManager.cs プロジェクト: ralescano/castle
		/// <summary>  Creates a new logging system or returns an existing one
		/// specified by the application.
		/// </summary>
		public static ILogSystem CreateLogSystem(IRuntimeServices runtimeServices)
		{
			ILogSystem logSystem;
			// if a logSystem was set as a configuration value, use that.
			// This is any class the user specifies.
			Object o = runtimeServices.GetProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM);
			logSystem = o as ILogSystem;
			if (logSystem != null)
			{
				logSystem.Init(runtimeServices);

				return logSystem;
			}

			// otherwise, see if a class was specified.  You
			// can put multiple classes, and we use the first one we find.
			//
			// Note that the default value of this property contains both the
			// AvalonLogSystem and the SimpleLog4JLogSystem for convenience -
			// so we use whichever we find.
			IList classes = new ArrayList();
			Object obj = runtimeServices.GetProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS);

			// we might have a list, or not - so check
			if (obj is IList)
			{
				classes = (IList) obj;
			}
			else if (obj is String)
			{
				classes.Add(obj);
			}

			// now run through the list, trying each.  It's ok to
			// fail with a class not found, as we do this to also
			// search out a default simple file logger
			foreach(String className in classes)
			{
				if (className != null && className.Length > 0)
				{
					runtimeServices.Info(string.Format("Trying to use logger class {0}", className));

					try
					{
						Type type = Type.GetType(className);
						o = Activator.CreateInstance(type);
						logSystem = o as ILogSystem;
						if (logSystem == null)
						{
							runtimeServices.Error(string.Format("The specified logger class {0} isn't a valid LogSystem", className));
						}
						else
						{
							logSystem.Init(runtimeServices);

							runtimeServices.Info(string.Format("Using logger class {0}", className));

							return logSystem;
						}
					}
					catch(ApplicationException applicationException)
					{
						runtimeServices.Debug(
							string.Format("Couldn't find class {0} or necessary supporting classes in classpath. Exception : {1}", className,
							              applicationException));
					}
				}
			}

			// if the above failed, then we are in deep doo-doo, as the
			// above means that either the user specified a logging class
			// that we can't find, there weren't the necessary
			// dependencies in the classpath for it, or there were no
			// dependencies for the default logger.
			// Since we really don't know,
			// then take a wack at the log4net as a last resort.
			try
			{
				logSystem = new NullLogSystem();
				logSystem.Init(runtimeServices);
			}
			catch(ApplicationException applicationException)
			{
				String error =
					string.Format(
						"PANIC : NVelocity cannot find any of the specified or default logging systems in the classpath, or the classpath doesn't contain the necessary classes to support them. Please consult the documentation regarding logging. Exception : {0}",
						applicationException);

				Console.Out.WriteLine(error);
				Console.Error.WriteLine(error);

				throw;
			}

			runtimeServices.Info("Using log4net as logger of final resort.");

			return logSystem;
		}
コード例 #10
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(System.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.");
		}
コード例 #11
0
ファイル: SimpleNode.cs プロジェクト: rambo-returns/MonoRail
		public virtual Object Init(IInternalContextAdapter context, Object data)
		{
			/*
	    * hold onto the RuntimeServices
	    */

			runtimeServices = (IRuntimeServices) data;

			int i, k = ChildrenCount;

			for(i = 0; i < k; i++)
			{
				try
				{
					GetChild(i).Init(context, data);
				}
				catch(ReferenceException re)
				{
					runtimeServices.Error(re);
				}
			}

			return data;
		}
コード例 #12
0
ファイル: Macro.cs プロジェクト: ralescano/castle
		/// <summary>
		/// Used by Parser.java to process VMs within the parsing process
		///
		/// processAndRegister() doesn't actually render the macro to the output
		/// Processes the macro body into the internal representation used by the
		/// VelocimacroProxy objects, and if not currently used, adds it
		/// to the macro Factory
		/// </summary>
		public static void processAndRegister(IRuntimeServices rs, INode node, String sourceTemplate)
		{
			// There must be at least one arg to  #macro,
			// the name of the VM.  Note that 0 following 
			// args is ok for naming blocks of HTML
			int numArgs = node.ChildrenCount;

			// this number is the # of args + 1.  The + 1
			// is for the block tree
			if (numArgs < 2)
			{
				// error - they didn't name the macro or
				// define a block
				rs.Error("#macro error : Velocimacro must have name as 1st argument to #macro()");

				return;
			}

			// get the arguments to the use of the VM
			String[] argArray = getArgArray(node);

			// now, try and eat the code block. Pass the root.
			IList macroArray = getASTAsStringArray(node.GetChild(numArgs - 1));

			// make a big string out of our macro
			StringBuilder temp = new StringBuilder();

			for(int i = 0; i < macroArray.Count; i++)
			{
				temp.Append(macroArray[i]);
			}

			String macroBody = temp.ToString();

			// now, try to add it.  The Factory controls permissions, 
			// so just give it a whack...
			rs.AddVelocimacro(argArray[0], macroBody, argArray, sourceTemplate);

			return;
		}
コード例 #13
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.");
        }
コード例 #14
0
        /// <summary> Gets the named resource.  Returned class type corresponds to specified type
        /// (i.e. <code>Template</code> to <code>Template</code>).
        /// *
        /// </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>
        public Resource GetResource(string resourceName, ResourceType resourceType, string encoding)
        {
            /*
             * Check to see if the resource was placed in the cache.
             * If it was placed in the cache then we will use
             * the cached version of the resource. If not we
             * will load it.
             */

            Resource resource = globalCache.get(resourceName);

            if (resource == null)
            {
                try
                {
                    // it's not in the cache, so load it.
                    resource = LoadResource(resourceName, resourceType, encoding);

                    if (resource.ResourceLoader.CachingOn)
                    {
                        globalCache.put(resourceName, resource);
                    }
                }
                catch (ResourceNotFoundException)
                {
                    runtimeServices.Error(
                        string.Format("ResourceManager : unable to find resource '{0}' in any resource loader.", resourceName));

                    throw;
                }
                catch (ParseErrorException pee)
                {
                    runtimeServices.Error(string.Format("ResourceManager.GetResource() parse exception: {0}", pee));

                    throw;
                }
                catch (Exception ee)
                {
                    runtimeServices.Error(string.Format("ResourceManager.GetResource() exception new: {0}", ee));

                    throw;
                }
            }
            else
            {
                /*
                 *  refresh the resource
                 */

                try
                {
                    RefreshResource(resource, encoding);
                }
                catch (ResourceNotFoundException)
                {
                    /*
                     *  something exceptional happened to that resource
                     *  this could be on purpose,
                     *  so clear the cache and try again
                     */

                    globalCache.remove(resourceName);

                    return(GetResource(resourceName, resourceType, encoding));
                }
                catch (ParseErrorException parseErrorException)
                {
                    runtimeServices.Error(string.Format("ResourceManager.GetResource() exception: {0}", parseErrorException));

                    throw;
                }
                catch (Exception exception)
                {
                    runtimeServices.Error(string.Format("ResourceManager.GetResource() exception: {0}", exception));

                    throw;
                }
            }

            return(resource);
        }