1 package com.thoughtworks.xstream.mapper; 2 3 import com.thoughtworks.xstream.alias.CannotResolveClassException; 4 import com.thoughtworks.xstream.alias.ClassMapper; 5 6 12 public class DefaultMapper extends MapperWrapper { 13 14 private final ClassLoader classLoader; 15 private final String classAttributeIdentifier; 16 17 public DefaultMapper(ClassLoader classLoader) { 18 this(classLoader, "class"); 19 } 20 21 public DefaultMapper(ClassLoader classLoader, String classAttributeIdentifier) { 22 super(null); 23 this.classLoader = classLoader; 24 this.classAttributeIdentifier = classAttributeIdentifier == null ? "class" : classAttributeIdentifier; 25 } 26 27 public String serializedClass(Class type) { 28 return type.getName(); 29 } 30 31 public Class realClass(String elementName) { 32 try { 33 return classLoader.loadClass(elementName); 34 } catch (ClassNotFoundException e) { 35 throw new CannotResolveClassException(elementName + " : " + e.getMessage()); 36 } 37 } 38 39 public Class lookupDefaultType(Class baseType) { 40 return baseType; 41 } 42 43 public Class defaultImplementationOf(Class type) { 44 return type; 45 } 46 47 public String attributeForClassDefiningField() { 48 return "defined-in"; 49 } 50 51 public String attributeForReadResolveField() { 52 return "resolves-to"; 53 } 54 55 public String attributeForEnumType() { 56 return "enum-type"; 57 } 58 59 public String attributeForImplementationClass() { 60 return classAttributeIdentifier; 61 } 62 63 public boolean isImmutableValueType(Class type) { 64 return false; 65 } 66 67 public String getFieldNameForItemTypeAndName(Class definedIn, Class itemType, String itemFieldName) { 68 return null; 69 } 70 71 public Class getItemTypeForItemFieldName(Class definedIn, String itemFieldName) { 72 return null; 73 } 74 75 public ImplicitCollectionMapping getImplicitCollectionDefForFieldName(Class itemType, String fieldName) { 76 return null; 77 } 78 79 public boolean shouldSerializeMember(Class definedIn, String fieldName) { 80 return true; 81 } 82 83 public String lookupName(Class type) { 84 return serializedClass(type); 85 } 86 87 public Class lookupType(String elementName) { 88 return realClass(elementName); 89 } 90 91 public String serializedMember(Class type, String memberName) { 92 return memberName; 93 } 94 95 public String realMember(Class type, String serialized) { 96 return serialized; 97 } 98 99 public String mapNameFromXML(String xmlName) { 100 return xmlName; 101 } 102 103 public String mapNameToXML(String javaName) { 104 return javaName; 105 } 106 107 public void alias(String elementName, Class type, Class defaultImplementation) { 108 } 109 110 } 111 | Popular Tags |