1 22 package org.jboss.util.propertyeditor; 23 24 import java.util.ArrayList ; 25 import java.util.StringTokenizer ; 26 import java.beans.PropertyEditorSupport ; 27 28 33 public class ClassArrayEditor extends PropertyEditorSupport 34 { 35 38 public void setAsText(final String text) throws IllegalArgumentException 39 { 40 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 41 StringTokenizer tokenizer = new StringTokenizer (text, ", \t\r\n"); 42 ArrayList classes = new ArrayList (); 43 while( tokenizer.hasMoreTokens() == true ) 44 { 45 String name = tokenizer.nextToken(); 46 try 47 { 48 Class c = loader.loadClass(name); 49 classes.add(c); 50 } 51 catch(ClassNotFoundException e) 52 { 53 throw new IllegalArgumentException ("Failed to find class: "+name); 54 } 55 } 56 57 Class [] theValue = new Class [classes.size()]; 58 classes.toArray(theValue); 59 setValue(theValue); 60 } 61 62 65 public String getAsText() 66 { 67 Class [] theValue = (Class []) getValue(); 68 StringBuffer text = new StringBuffer (); 69 int length = theValue == null ? 0 : theValue.length; 70 for(int n = 0; n < length; n ++) 71 { 72 text.append(theValue[n].getName()); 73 text.append(','); 74 } 75 text.setLength(text.length()-1); 77 return text.toString(); 78 } 79 } 80 | Popular Tags |