package org.apache.jmeter.engine;

import java.util.Map;

import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.engine.util.ValueReplacer;
import org.apache.jmeter.functions.InvalidVariableException;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.testelement.TestPlan;
import org.apache.jmeter.threads.JMeterContextService;
import org.apache.jmeter.threads.JMeterVariables;
import org.apache.jorphan.collections.HashTree;
import org.apache.jorphan.collections.HashTreeTraverser;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;

/**
 * @author mstover
 * @version $Revision$
 */
public class PreCompiler implements HashTreeTraverser
{
    transient private static Logger log = LoggingManager.getLoggerForClass();
    private ValueReplacer replacer;

    public PreCompiler()
    {
        replacer = new ValueReplacer();
    }

    /* (non-Javadoc)
     * @see HashTreeTraverser#addNode(Object, HashTree)
     */
    public void addNode(Object node, HashTree subTree)
    {
        if (node instanceof TestPlan)
        {
            Map args= ((TestPlan)node).getUserDefinedVariables();
            replacer.setUserDefinedVariables(args);
            JMeterVariables vars= new JMeterVariables();
            vars.putAll(args);
            JMeterContextService.getContext().setVariables(vars);
        }
        else if (node instanceof TestElement)
        {
            try
            {
                replacer.replaceValues((TestElement) node);
                ((TestElement)node).setRunningVersion(true);
            }
            catch (InvalidVariableException e)
            {
                log.error("invalid variables", e);
            }
        }

        if (node instanceof Arguments)
        {
            Map args= ((Arguments)node).getArgumentsAsMap();
            replacer.addVariables(args);
            JMeterContextService.getContext().getVariables().putAll(args);
        }
    }

    /* (non-Javadoc)
     * @see HashTreeTraverser#subtractNode()
     */
    public void subtractNode()
    {
    }

    /* (non-Javadoc)
     * @see HashTreeTraverser#processPath()
     */
    public void processPath()
    {
    }
}

@@ -1,8 +1,2756 @@
+/*%0A * ====================================================================%0A * The Apache Software License, Version 1.1%0A *%0A * Copyright (c) 2003 The Apache Software Foundation.  All rights%0A * reserved.%0A *%0A * Redistribution and use in source and binary forms, with or without%0A * modification, are permitted provided that the following conditions%0A * are met:%0A *%0A * 1. Redistributions of source code must retain the above copyright%0A * notice, this list of conditions and the following disclaimer.%0A *%0A * 2. Redistributions in binary form must reproduce the above copyright%0A * notice, this list of conditions and the following disclaimer in%0A * the documentation and/or other materials provided with the%0A * distribution.%0A *%0A * 3. The end-user documentation included with the redistribution,%0A * if any, must include the following acknowledgment:%0A * %22This product includes software developed by the%0A * Apache Software Foundation (http://www.apache.org/).%22%0A * Alternately, this acknowledgment may appear in the software itself,%0A * if and wherever such third-party acknowledgments normally appear.%0A *%0A * 4. The names %22Apache%22 and %22Apache Software Foundation%22 and%0A * %22Apache JMeter%22 must not be used to endorse or promote products%0A * derived from this software without prior written permission. For%0A * written permission, please contact apache@apache.org.%0A *%0A * 5. Products derived from this software may not be called %22Apache%22,%0A * %22Apache JMeter%22, nor may %22Apache%22 appear in their name, without%0A * prior written permission of the Apache Software Foundation.%0A *%0A * THIS SOFTWARE IS PROVIDED %60%60AS IS'' AND ANY EXPRESSED OR IMPLIED%0A * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES%0A * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE%0A * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR%0A * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,%0A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT%0A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF%0A * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND%0A * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,%0A * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT%0A * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF%0A * SUCH DAMAGE.%0A * ====================================================================%0A *%0A * This software consists of voluntary contributions made by many%0A * individuals on behalf of the Apache Software Foundation.  For more%0A * information on the Apache Software Foundation, please see%0A * %3Chttp://www.apache.org/%3E.%0A * %0A * @author  Michael Stover%0A * @author  %3Ca href=%22mailto:jsalvata@apache.org%22%3EJordi Salvat i Alabart%3C/a%3E%0A * @version $Id$%0A */%0A
 package 
@@ -3347,58 +3347,8 @@
 r;%0A%0A
-/**%0A * @author mstover%0A * @version $Revision$%0A */%0A
 publ

Add Apache copyright note.