1 package com.thoughtworks.xstream.converters.extended; 2 3 import com.thoughtworks.xstream.converters.ConversionException; 4 import com.thoughtworks.xstream.converters.basic.AbstractBasicConverter; 5 6 12 public class JavaClassConverter extends AbstractBasicConverter { 13 14 private ClassLoader classLoader; 15 16 public JavaClassConverter() { 17 this(Thread.currentThread().getContextClassLoader()); 18 } 19 20 public JavaClassConverter(ClassLoader classLoader) { 21 this.classLoader = classLoader; 22 } 23 24 public boolean canConvert(Class clazz) { 25 return Class .class.equals(clazz); } 27 28 protected String toString(Object obj) { 29 return ((Class ) obj).getName(); 30 } 31 32 protected Object fromString(String str) { 33 try { 34 return classLoader.loadClass(str); 35 } catch (ClassNotFoundException e) { 36 throw new ConversionException("Cannot load java class " + str, e); 37 } 38 } 39 40 } 41 | Popular Tags |