public override Object Init(IInternalContextAdapter context, Object data)
        {
            base.Init(context, data);

            if (directive == null && runtimeServices.IsVelocimacro(directiveName, context.CurrentTemplateName))
            {
                directive = runtimeServices.GetVelocimacro(directiveName, context.CurrentTemplateName);
            }

            if (directive != null)
            {
                directive.Init(runtimeServices, context, this);
                directive.SetLocation(Line, Column);
            }

            return(data);
        }
示例#2
0
        /// <seealso cref="NVelocity.Runtime.Paser.Node.SimpleNode.Init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)">
        /// </seealso>
        public override object Init(IInternalContextAdapter context, object data)
        {
            lock (this)
            {
                /** method is synchronized to avoid concurrent directive initialization **/

                if (!isInitialized)
                {
                    base.Init(context, data);

                    /*
                     *  only do things that are not context dependent
                     */

                    if (parser.IsDirective(directiveName))
                    {
                        isDirective = true;

                        try
                        {
                            directive = (Directive)System.Activator.CreateInstance(parser.GetDirective(directiveName).GetType());
                        }
                        catch (System.UnauthorizedAccessException e)
                        {
                            throw new RuntimeException("Couldn't initialize " + "directive of class " + parser.GetDirective(directiveName).GetType().FullName, e);
                        }
                        catch (System.Exception e)
                        {
                            throw new RuntimeException("Couldn't initialize " + "directive of class " + parser.GetDirective(directiveName).GetType().FullName, e);
                        }



                        directive.SetLocation(Line, Column);
                        directive.Init(rsvc, context, this);
                    }
                    else
                    {
                        /**
                         * Create a new RuntimeMacro
                         */
                        directive = new RuntimeMacro(directiveName, TemplateName);

                        directive.SetLocation(Line, Column);

                        /**
                         * Initialize it
                         */
                        try
                        {
                            directive.Init(rsvc, context, this);
                        }

                        /**
                         * correct the line/column number if an exception is caught
                         */
                        catch (TemplateInitException die)
                        {
                            throw new TemplateInitException(die.Message, (ParseException)die.InnerException, die.TemplateName, die.ColumnNumber + Column, die.LineNumber + Line);
                        }
                        isDirective = true;
                    }

                    isInitialized = true;
                }

                return(data);
            }
        }