Exemplo n.º 1
0
        /// <summary>  Parse the input and return the root of the AST node structure.
        /// *
        /// </summary>
        /// <param name="InputStream">inputstream retrieved by a resource loader
        /// </param>
        /// <param name="String">name of the template being parsed
        /// </param>
        /// <param name="dumpNamespace">flag to dump the Velocimacro namespace for this template
        ///
        /// </param>
        public virtual SimpleNode parse(System.IO.TextReader reader, System.String templateName, bool dumpNamespace)
        {
            SimpleNode ast = null;

            Parser.Parser parser  = (Parser.Parser)parserPool.get();
            bool          madeNew = false;

            if (parser == null)
            {
                /*
                 *  if we couldn't get a parser from the pool
                 *  make one and log it.
                 */

                error("Runtime : ran out of parsers. Creating new.  " + " Please increment the parser.pool.size property." + " The current value is too small.");

                parser = createNewParser();

                if (parser != null)
                {
                    madeNew = true;
                }
            }

            /*
             *  now, if we have a parser
             */

            if (parser != null)
            {
                try {
                    /*
                     *  dump namespace if we are told to.  Generally, you want to
                     *  do this - you don't in special circumstances, such as
                     *  when a VM is getting init()-ed & parsed
                     */

                    if (dumpNamespace)
                    {
                        dumpVMNamespace(templateName);
                    }

                    ast = parser.parse(reader, templateName);
                } finally {
                    /*
                     *  if this came from the pool, then put back
                     */
                    if (!madeNew)
                    {
                        parserPool.put(parser);
                    }
                }
            }
            else
            {
                error("Runtime : ran out of parsers and unable to create more.");
            }
            return(ast);
        }
Exemplo n.º 2
0
        /// <summary> Initializes the Velocity parser pool.
        /// This still needs to be implemented.
        /// </summary>
        private void  initializeParserPool()
        {
            int numParsers = getInt(NVelocity.Runtime.RuntimeConstants_Fields.PARSER_POOL_SIZE, NVelocity.Runtime.RuntimeConstants_Fields.NUMBER_OF_PARSERS);

            parserPool = new SimplePool(numParsers);

            for (int i = 0; i < numParsers; i++)
            {
                parserPool.put(createNewParser());
            }

            info("Created: " + numParsers + " parsers.");
        }
	/// <summary> Initializes the Velocity parser pool.
	/// This still needs to be implemented.
	/// </summary>
	private void  initializeParserPool() {
	    int numParsers = getInt(NVelocity.Runtime.RuntimeConstants_Fields.PARSER_POOL_SIZE, NVelocity.Runtime.RuntimeConstants_Fields.NUMBER_OF_PARSERS);

	    parserPool = new SimplePool(numParsers);

	    for (int i = 0; i < numParsers; i++) {
		parserPool.put(createNewParser());
	    }

	    info("Created: " + numParsers + " parsers.");
	}