1 17 18 package org.sape.carbon.core.config.type.handlers; 19 20 21 22 import org.sape.carbon.core.config.type.ConfigurationTypeHandler; 23 import org.sape.carbon.core.config.type.TypeConversionException; 24 25 33 public class ClassTypeHandler implements ConfigurationTypeHandler { 34 35 44 public Object toObject(Class type, String stringValue) 45 throws TypeConversionException { 46 47 if (stringValue == null) { 48 throw new TypeConversionException( 49 this.getClass(), 50 "Cannot load a class with a null name."); 51 } 52 53 Class object = null; 54 try { 55 object = 56 Class.forName( 57 stringValue.trim(), 58 true, 59 this.getClass().getClassLoader()); 60 } catch (ClassNotFoundException cnfe) { 61 throw new TypeConversionException( 62 this.getClass(), 63 "Couldn't format", cnfe); 64 } 65 return object; 66 } 67 68 75 public String toString(Object objectValue) { 76 return ((Class ) objectValue).getName(); 77 } 78 79 } 80 | Popular Tags |