All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.etlunit.context.VariableVelocityWrapper Maven / Gradle / Ivy

package org.etlunit.context;

import org.etlunit.parser.ETLTestValueObject;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

public class VariableVelocityWrapper implements Map
{
	private final ETLTestValueObject qcontext;
	private final VariableContext vcontext;

	public VariableVelocityWrapper(VariableContext variableContext)
	{
		qcontext = null;
		vcontext = variableContext;
	}

	public VariableVelocityWrapper(ETLTestValueObject variableContext)
	{
		qcontext = variableContext;
		vcontext = null;
	}

	@Override
	public int size()
	{
		throw new UnsupportedOperationException();
	}

	@Override
	public boolean isEmpty()
	{
		throw new UnsupportedOperationException();
	}

	@Override
	public boolean containsKey(Object o)
	{
		throw new UnsupportedOperationException();
	}

	@Override
	public boolean containsValue(Object o)
	{
		throw new UnsupportedOperationException();
	}

	@Override
	public Object get(Object o)
	{
		String name = String.valueOf(o);

		ETLTestValueObject value = null;

		if (qcontext != null)
		{
			value = qcontext.query(name);
		}
		else
		{
			try
			{
				value = vcontext.getValue(name);
			}
			catch (IllegalArgumentException arg)
			{
				// trap this to allow velocity to test variables
			}
		}

		if (value != null)
		{
			switch (value.getValueType())
			{
				case literal:
				case quoted_string:
					return value.getValueAsString();
				case object:
					return new VariableVelocityWrapper(value);
				case list:
					// TODO: What to do for lists??
					throw new UnsupportedOperationException("I can't handle lists yet.  Please fix that");
				case pojo:
					// don't wrap pojos
					return value.getValueAsPojo();
			}
		}

		return null;
	}

	@Override
	public Object put(String s, Object o)
	{
		throw new UnsupportedOperationException();
	}

	@Override
	public Object remove(Object o)
	{
		throw new UnsupportedOperationException();
	}

	@Override
	public void putAll(Map map)
	{
		throw new UnsupportedOperationException();
	}

	@Override
	public void clear()
	{
		throw new UnsupportedOperationException();
	}

	@Override
	public Set keySet()
	{
		throw new UnsupportedOperationException();
	}

	@Override
	public Collection values()
	{
		throw new UnsupportedOperationException();
	}

	@Override
	public Set> entrySet()
	{
		throw new UnsupportedOperationException();
	}
}