// ----------------------------------------------------------------------
// This code is developed as part of the Java CoG Kit project
// The terms of the license can be found at http://www.cogkit.org/license
// This message may not be removed or altered.
// ----------------------------------------------------------------------

/*
 * Created on Jul 2, 2004
 */
package org.globus.cog.karajan.workflow.nodes.functions;

import java.util.Collections;
import java.util.Stack;

import org.globus.cog.karajan.arguments.Arg;
import org.globus.cog.karajan.stack.VariableNotFoundException;
import org.globus.cog.karajan.stack.VariableStack;
import org.globus.cog.karajan.util.Identifier;
import org.globus.cog.karajan.util.TypeUtil;
import org.globus.cog.karajan.workflow.ExecutionException;

public class Variable extends AbstractFunction {

	public static final Arg A_NAME = new Arg.Positional("name");

	public static final int UNINITIALIZED = -999;

	static {
		setArguments(Variable.class, new Arg[] { A_NAME });
	}

	private int frame = UNINITIALIZED;
	private String name;

	public Variable() {
		this.setAcceptsInlineText(true);
	}

	public Object function(VariableStack stack) throws ExecutionException {
		synchronized (this) {
			if (name == null) {
				name = TypeUtil.toString(A_NAME.getStatic(this)).toLowerCase();
				if (getStaticArguments().size() == 1) {
					java.util.Map<String, Object> m = Collections.emptyMap();
					setStaticArguments(m);
				}
			}
		}

		switch (frame) {
			case UNINITIALIZED:
			case VariableStack.NO_FRAME:
				if (stack.parentFrame().isDefined("#quoted")) {
					Object value = new Identifier(name);
					setSimple(value);
					return value;
				}
				else {
					frame = stack.getVarFrameFromTop(name);
					switch (frame) {
					    case VariableStack.NO_FRAME:
					        throw new VariableNotFoundException(name);
					    case VariableStack.FIRST_FRAME:
					        Object value = stack.firstFrame().getVar(name);
					        setSimple(value);
					        return value;
					    case VariableStack.DYNAMIC_FRAME:
					        return stack.getVar(name);
					    default:
					        return stack.getFrameFromTop(frame).getVar(name);
					}
				}
			case VariableStack.FIRST_FRAME:
			    return stack.firstFrame().getVar(name);
			case VariableStack.DYNAMIC_FRAME:
			    return stack.getVar(name);
			default:
			    return stack.getFrameFromTop(frame).getVar(name);
		}
	}
}
@@ -450,32 +450,40 @@
 ns;%0A
+%0A
 import 
-java.util.Stack;%0A
+org.apache.log4j.Logger;
 %0Aimp
@@ -840,16 +840,81 @@
 tion %7B%0A%0A
+%09final static Logger logger = Logger.getLogger(Variable.class);%0A%0A
 %09public 
@@ -1542,16 +1542,49 @@
 %09%7D%0A%09%09%7D%0A%0A
+%09%09logger.debug(%22get: %22 + name);%0A%0A
 %09%09switch
@@ -2530,8 +2530,9 @@
 %09%09%7D%0A%09%7D%0A%7D
+%0A

Add logger