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

com.talk2object.plum.interaction.view.annotation.parameter.helper.AbstractParameterWrapper Maven / Gradle / Ivy

There is a newer version: 0.1.22
Show newest version
package com.talk2object.plum.interaction.view.annotation.parameter.helper;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;

import com.talk2object.plum.interaction.rich.field.InteractiveField;
import com.talk2object.plum.interaction.rich.field.StringField;

public abstract class AbstractParameterWrapper implements ParameterWrapper {
	protected Annotation parameter;
	protected Class targetClass;

	@Override
	public void setParameter(Annotation parameter) {
		this.parameter = parameter;
	}

	@Override
	public void setTargetClass(Class targetClass) {
		this.targetClass = targetClass;
	}

	/**
	 * direct value from annotation
	 * 
	 * @return
	 */
	abstract Object getInitValue();

	/**
	 * direct value from annotation
	 * 
	 * @return
	 */
	abstract Object[] getOptionValues();

	@Override
	public boolean hasOptions() {

		return getOptionValues().length > 0;
	}

	@Override
	public Object value2Object(Object value) {
		// same as annotation type
		return value;
	}

	@Override
	public Object getInitValueAsObject() {
		return value2Object(getInitValue());
	}

	@Override
	public List getOptionAsList() {

		List list = new ArrayList();
		for (Object option : getOptionValues()) {
			list.add(value2Object(option));
		}
		return list;
	}

	@Override
	public void enrich(InteractiveField input) {

		input.setInitValue(getInitValueAsObject());
		input.setOptions(getOptionAsList());

	}
}