View Javadoc

1   package org.kuali.student.common.util.spring;
2   
3   import java.beans.PropertyEditorSupport;
4   
5   public class SimpleEnumPropertyEditor extends PropertyEditorSupport {
6   	Class<? extends Enum<?>> enumClass;
7   
8   	@Override
9   	public void setAsText(String text) throws IllegalArgumentException {
10  		for (Object e : enumClass.getEnumConstants()) {
11  			if (e.toString().toUpperCase().equals(text.toUpperCase())) {
12  				this.setValue(e);
13  			}
14  		}
15  	}
16  
17  	public SimpleEnumPropertyEditor(Class<? extends Enum<?>> enumClass) {
18  		super();
19  		if(enumClass==null||!enumClass.isEnum()){
20  			throw new IllegalArgumentException("Must set a valid Enum Class in the constructor");
21  		}
22  		this.enumClass = enumClass;
23  	}
24  
25  }