package net.w_horse.excelpojo.excel.cellseeker;

import java.lang.annotation.Annotation;

import net.w_horse.excelpojo.ExcelPOJOException;
import net.w_horse.excelpojo.annotation.ExcelPOJOAnnotationParser;
import net.w_horse.excelpojo.bean.Utils;
import net.w_horse.excelpojo.excel.reservedword.ReservedWordManager;

import org.apache.poi.ss.usermodel.Sheet;

public class ConstantValueCellSeeker extends AbstractCellSeeker {

	private String value;

	@Override
	public void set(Annotation annotation, ExcelPOJOAnnotationParser parser) {
		parser.setCellSeeker(annotation, this);
	}

	@Override
	public boolean verify() throws IllegalArgumentException {
		return true;
	}

	@Override
	public Object seekCellValue(Sheet sheet, Class<?> requiredType) throws ExcelPOJOException {
		String value = ReservedWordManager.convReservedWord(getValue());
		return Utils.convertIfNecessary(getConverter().convertCell2Field(value), requiredType);
	}

	@Override
	protected Offset seekCellPosition(Sheet sheet) {
		return new Offset();
	}

	@Override
	protected Offset seekCellPosition(Sheet sheet, Offset basePosition, Offset offset) {
		return new Offset();
	}

	@Override
	public void setValue(Sheet sheet, Object bean) {
		// 書き込みについては何もしない
	}

	@Override
	public void setValue(Sheet sheet, Offset basePosition,
			Offset offset, Object value) {
		// 書き込みについては何もしない
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getValue() {
		return value;
	}

}
