KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.thoughtworks.xstream.mapper;
2
3 import com.thoughtworks.xstream.alias.ClassMapper;
4
5 public abstract class MapperWrapper implements ClassMapper {
6
7     private final ClassMapper wrapped;
8
9     public MapperWrapper(ClassMapper wrapped) {
10         this.wrapped = wrapped;
11     }
12
13     public String JavaDoc serializedClass(Class JavaDoc type) {
14         return wrapped.serializedClass(type);
15     }
16
17     public Class JavaDoc realClass(String JavaDoc elementName) {
18         return wrapped.realClass(elementName);
19     }
20
21     public String JavaDoc serializedMember(Class JavaDoc type, String JavaDoc memberName) {
22         return wrapped.serializedMember(type, memberName);
23     }
24
25     public String JavaDoc realMember(Class JavaDoc type, String JavaDoc serialized) {
26         return wrapped.realMember(type, serialized);
27     }
28
29     public String JavaDoc mapNameFromXML(String JavaDoc xmlName) {
30         return wrapped.mapNameFromXML(xmlName);
31     }
32
33     public String JavaDoc mapNameToXML(String JavaDoc javaName) {
34         return wrapped.mapNameToXML(javaName);
35     }
36
37     public boolean isImmutableValueType(Class JavaDoc type) {
38         return wrapped.isImmutableValueType(type);
39     }
40
41     public Class JavaDoc defaultImplementationOf(Class JavaDoc type) {
42         return wrapped.defaultImplementationOf(type);
43     }
44
45     public String JavaDoc attributeForClassDefiningField() {
46         return wrapped.attributeForClassDefiningField();
47     }
48
49     public String JavaDoc attributeForImplementationClass() {
50         return wrapped.attributeForImplementationClass();
51     }
52
53     public String JavaDoc attributeForReadResolveField() {
54         return wrapped.attributeForReadResolveField();
55     }
56
57     public String JavaDoc attributeForEnumType() {
58         return wrapped.attributeForEnumType();
59     }
60
61     public String JavaDoc getFieldNameForItemTypeAndName(Class JavaDoc definedIn, Class JavaDoc itemType, String JavaDoc itemFieldName) {
62         return wrapped.getFieldNameForItemTypeAndName(definedIn, itemType, itemFieldName);
63     }
64
65     public Class JavaDoc getItemTypeForItemFieldName(Class JavaDoc definedIn, String JavaDoc itemFieldName) {
66         return wrapped.getItemTypeForItemFieldName(definedIn, itemFieldName);
67     }
68
69     public ImplicitCollectionMapping getImplicitCollectionDefForFieldName(Class JavaDoc itemType, String JavaDoc fieldName) {
70         return wrapped.getImplicitCollectionDefForFieldName(itemType, fieldName);
71     }
72
73     public boolean shouldSerializeMember(Class JavaDoc definedIn, String JavaDoc fieldName) {
74         return wrapped.shouldSerializeMember(definedIn, fieldName);
75     }
76
77     /**
78      * @deprecated As of 1.1.1, use {@link #defaultImplementationOf(Class)}
79      */

80     public Class JavaDoc lookupDefaultType(Class JavaDoc baseType) {
81         return defaultImplementationOf(baseType);
82     }
83
84     public String JavaDoc lookupName(Class JavaDoc type) {
85         return serializedClass(type);
86     }
87
88     public Class JavaDoc lookupType(String JavaDoc elementName) {
89         return realClass(elementName);
90     }
91
92     /**
93      * @deprecated As of 1.1.1, use {@link com.thoughtworks.xstream.mapper.ClassAliasingMapper#addClassAlias(String, Class)} for creating an alias and
94      * {@link DefaultImplementationsMapper#addDefaultImplementation(Class, Class)} for specifiny a
95      * default implementation.
96      */

97     public void alias(String JavaDoc elementName, Class JavaDoc type, Class JavaDoc defaultImplementation) {
98         ClassAliasingMapper classAliasingMapper = (ClassAliasingMapper) findWrapped(ClassAliasingMapper.class);
99         if (classAliasingMapper == null) {
100             throw new UnsupportedOperationException JavaDoc("ClassMapper.alias() longer supported. Use ClassAliasingMapper.alias() instead.");
101         } else {
102             classAliasingMapper.addClassAlias(elementName, type);
103         }
104         if (defaultImplementation != null && defaultImplementation != type) {
105             DefaultImplementationsMapper defaultImplementationsMapper = (DefaultImplementationsMapper) findWrapped(DefaultImplementationsMapper.class);
106             if (defaultImplementationsMapper == null) {
107                 throw new UnsupportedOperationException JavaDoc("ClassMapper.alias() longer supported. Use DefaultImplementatoinsMapper.add() instead.");
108             } else {
109                 defaultImplementationsMapper.addDefaultImplementation(defaultImplementation, type);
110             }
111         }
112     }
113
114     private ClassMapper findWrapped(Class JavaDoc typeOfMapper) {
115         ClassMapper current = this;
116         while (true) {
117             if (current.getClass().isAssignableFrom(typeOfMapper)) {
118                 return current;
119             } else if (current instanceof MapperWrapper) {
120                 MapperWrapper wrapper = (MapperWrapper) current;
121                 current = wrapper.wrapped;
122             } else {
123                 return null;
124             }
125         }
126     }
127 }
128
Popular Tags