tim@335: package de.intevation.gnv.state;
tim@335:
ingo@634: import java.util.HashMap;
ingo@634: import java.util.Map;
ingo@634:
ingo@634: import org.apache.log4j.Logger;
ingo@634:
tim@335: /**
sascha@780: * @author Tim Englich
sascha@780: * @author Ingo Weinzierl
tim@335: */
tim@335: public class DefaultInputData implements InputData {
tim@335:
tim@335: /**
tim@335: *
tim@335: */
tim@335: private static final long serialVersionUID = 4308041648698108066L;
ingo@634:
ingo@634: private static final Logger logger = Logger.getLogger(DefaultInputData.class);
ingo@634:
tim@598: private final static String VALUE_SEPARATOR = " , ";
tim@598:
ingo@634: protected String name;
ingo@634: protected String value;
ingo@634: protected Map description;
ingo@634: protected Object object;
ingo@634:
tim@335:
tim@335: /**
tim@335: * Constructor
tim@335: */
tim@335: public DefaultInputData(String name, String value) {
tim@335: this.name = name;
tim@335: this.value = value;
tim@335: }
tim@335:
ingo@607: public DefaultInputData(String name, Object object) {
ingo@607: this.name = name;
ingo@607: this.object = object;
ingo@607: }
ingo@607:
tim@335: /**
tim@335: * @see de.intevation.gnv.state.InputData#getName()
tim@335: */
tim@335: public String getName() {
tim@335: return this.name;
tim@335: }
tim@335:
tim@335: /**
tim@335: * @see de.intevation.gnv.state.InputData#getValue()
tim@335: */
tim@335: public String getValue() {
tim@335: return this.value;
tim@335: }
tim@335:
ingo@607: public void setObject(Object object) {
ingo@607: this.object = object;
ingo@607: }
ingo@607:
ingo@607: public Object getObject() {
ingo@607: return object;
ingo@607: }
ingo@607:
ingo@634: public String getDescription(String key) {
ingo@634: if (description == null)
ingo@634: return null;
ingo@634:
ingo@634: return (String) description.get(key);
ingo@634: }
ingo@634:
ingo@615: public String[] getDescription() {
ingo@634: String[] values = splitValue();
ingo@634: int length = values.length;
ingo@634:
ingo@634: String[] description = new String[length];
ingo@634: for (int i = 0; i < length; i++) {
ingo@634: description[i] = (String) this.description.get(values[i]);
ingo@634: }
ingo@634:
ingo@607: return description;
ingo@607: }
ingo@607:
ingo@615: public void setDescription(String[] description) {
ingo@634: if (this.description == null)
ingo@634: this.description = new HashMap();
ingo@634:
ingo@634: String[] values = splitValue();
ingo@634:
ingo@634: int length = values.length;
ingo@634: int descLength = description.length;
ingo@634:
ingo@634: for (int i = 0; i < length; i++) {
ingo@634: if (i < descLength) {
ingo@634: this.description.put(values[i], description[i]);
ingo@634: }
ingo@634: else {
ingo@634: break;
ingo@634: }
ingo@634: }
ingo@607: }
ingo@607:
tim@335: /**
tim@335: * @see java.lang.Object#toString()
tim@335: */
tim@335: @Override
tim@335: public String toString() {
tim@335: return this.name + "==> " + this.value;
tim@335: }
tim@335:
tim@335: /**
tim@335: * @see de.intevation.gnv.state.InputData#concartValue(java.lang.String)
tim@335: */
tim@335: public void concartValue(String value) {
tim@598: this.value = this.value + VALUE_SEPARATOR + value;
tim@598: }
tim@598:
tim@598: /**
tim@598: * @see de.intevation.gnv.state.InputData#splitValue()
tim@598: */
tim@598: public String[] splitValue() {
tim@598: if (this.value != null){
tim@598: return this.value.split(VALUE_SEPARATOR);
tim@598: }
tim@598: return null;
tim@335: }
tim@335:
tim@335: }