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

org.etlunit.parser.ETLTestAnnotatedImpl Maven / Gradle / Ivy

There is a newer version: 1.6.9
Show newest version
package org.etlunit.parser;

import java.util.*;

public class ETLTestAnnotatedImpl extends ETLTestDebugTraceableImpl implements ETLTestAnnotated
{
	List annotations = new ArrayList();
	Map> annotationMap = new HashMap>();

	public ETLTestAnnotatedImpl(Token token)
	{
		super(token);
	}

	public ETLTestAnnotatedImpl()
	{
	}

	public void addAnnotations(List ano)
	{
		Iterator it = ano.iterator();

		while (it.hasNext())
		{
			addAnnotation(it.next());
		}
	}

	public void addAnnotation(ETLTestAnnotation ano)
	{
		annotations.add(ano);

		List li = annotationMap.get(ano.getName());

		if (li == null)
		{
			li = new ArrayList();
			annotationMap.put(ano.getName(), li);
		}

		li.add(ano);
	}

	@Override
	public List getAnnotations()
	{
		return Collections.unmodifiableList(annotations);
	}

	@Override
	public List getAnnotations(String name)
	{
		List list = annotationMap.get(name);

		if (list == null)
		{
			return Collections.EMPTY_LIST;
		}

		return Collections.unmodifiableList(list);
	}

	@Override
	public boolean hasAnnotation(String name)
	{
		return annotationMap.containsKey(name);
	}

	public String getDescription()
	{
		if (!hasAnnotation("@Description"))
		{
			return "";
		}

		List desc = getAnnotations("@Description");

		ETLTestAnnotation dAnn = desc.get(0);

		if (!dAnn.hasValue())
		{
			throw new IllegalStateException("@Description annotation missing description attribute");
		}
		else if (dAnn.getValue().getValueType() != ETLTestValueObject.value_type.object)
		{
			throw new IllegalStateException("@Description annotation must have an object type argument");
		}

		ETLTestValueObject val = dAnn.getValue().getValueAsMap().get("description");

		if (val == null)
		{
			throw new IllegalStateException("@Description annotation missing description attribute");
		}
		else if (val.getValueType() != ETLTestValueObject.value_type.quoted_string)
		{
			throw new IllegalStateException("@Description description attribute must be text");
		}

		return val.getValueAsString();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy