1 16 17 package org.springframework.beans.propertyeditors; 18 19 import java.beans.PropertyEditorSupport ; 20 21 import org.springframework.util.ClassUtils; 22 import org.springframework.util.StringUtils; 23 24 38 public class ClassEditor extends PropertyEditorSupport { 39 40 private final ClassLoader classLoader; 41 42 43 46 public ClassEditor() { 47 this(null); 48 } 49 50 55 public ClassEditor(ClassLoader classLoader) { 56 this.classLoader = 57 (classLoader != null ? classLoader : ClassUtils.getDefaultClassLoader()); 58 } 59 60 61 public void setAsText(String text) throws IllegalArgumentException { 62 if (StringUtils.hasText(text)) { 63 setValue(ClassUtils.resolveClassName(text.trim(), this.classLoader)); 64 } 65 else { 66 setValue(null); 67 } 68 } 69 70 public String getAsText() { 71 Class clazz = (Class ) getValue(); 72 if (clazz != null) { 73 return ClassUtils.getQualifiedName(clazz); 74 } 75 else { 76 return ""; 77 } 78 } 79 80 } 81 | Popular Tags |