1 package com.thoughtworks.xstream.mapper; 2 3 import com.thoughtworks.xstream.alias.ClassMapper; 4 5 import java.lang.reflect.Proxy ; 6 7 13 public class DynamicProxyMapper extends MapperWrapper { 14 15 private String alias = "dynamic-proxy"; 16 17 public DynamicProxyMapper(ClassMapper wrapped) { 18 super(wrapped); 19 } 20 21 public DynamicProxyMapper(ClassMapper wrapped, String alias) { 22 super(wrapped); 23 this.alias = alias; 24 } 25 26 public String getAlias() { 27 return alias; 28 } 29 30 public void setAlias(String alias) { 31 this.alias = alias; 32 } 33 34 public String serializedClass(Class type) { 35 if (Proxy.isProxyClass(type)) { 36 return alias; 37 } else { 38 return super.serializedClass(type); 39 } 40 } 41 42 public Class realClass(String elementName) { 43 if (elementName.equals(alias)) { 44 return DynamicProxy.class; 45 } else { 46 return super.realClass(elementName); 47 } 48 } 49 50 53 public static class DynamicProxy {} 54 55 } 56 | Popular Tags |