KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtworks > xstream > mapper > DefaultMapper


1 package com.thoughtworks.xstream.mapper;
2
3 import com.thoughtworks.xstream.alias.CannotResolveClassException;
4 import com.thoughtworks.xstream.alias.ClassMapper;
5
6 /**
7  * Default mapper implementation with 'vanilla' functionality. To build up the functionality required, wrap this mapper
8  * with other mapper implementations.
9  *
10  * @author Joe Walnes
11  */

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