1 package com.thoughtworks.xstream.mapper; 2 3 import com.thoughtworks.xstream.alias.ClassMapper; 4 5 10 public class OuterClassMapper extends MapperWrapper { 11 12 private final String alias; 13 14 public OuterClassMapper(ClassMapper wrapped, String alias) { 15 super(wrapped); 16 this.alias = alias; 17 } 18 19 public OuterClassMapper(ClassMapper wrapped) { 20 this(wrapped, "outer-class"); 21 } 22 23 public String serializedMember(Class type, String memberName) { 24 if (memberName.equals("this$0")) { 25 return alias; 26 } else { 27 return super.serializedMember(type, memberName); 28 } 29 } 30 31 public String realMember(Class type, String serialized) { 32 if (serialized.equals(alias)) { 33 return "this$0"; 34 } else { 35 return super.realMember(type, serialized); 36 } 37 } 38 39 41 public String mapNameToXML(String javaName) { 42 if (javaName.equals("this$0")) { 43 return alias; 44 } else { 45 return super.mapNameToXML(javaName); 46 } 47 } 48 49 public String mapNameFromXML(String xmlName) { 50 if (xmlName.equals(alias)) { 51 return "this$0"; 52 } else { 53 return super.mapNameFromXML(xmlName); 54 } 55 } 56 57 } 58 | Popular Tags |