001: /*
002: * Copyright (C) 2005, 2006 Joe Walnes.
003: * Copyright (C) 2006, 2007, 2008 XStream Committers.
004: * All rights reserved.
005: *
006: * The software in this package is published under the terms of the BSD
007: * style license a copy of which has been included with this distribution in
008: * the LICENSE.txt file.
009: *
010: * Created on 22. January 2005 by Joe Walnes
011: */
012: package com.thoughtworks.xstream.mapper;
013:
014: import com.thoughtworks.xstream.converters.Converter;
015: import com.thoughtworks.xstream.converters.SingleValueConverter;
016:
017: /**
018: * Default mapper implementation with 'vanilla' functionality. To build up the functionality required, wrap this mapper
019: * with other mapper implementations.
020: *
021: * @author Joe Walnes
022: * @author Jörg Schaible
023: */
024: public class DefaultMapper implements Mapper {
025:
026: private final ClassLoader classLoader;
027: /**
028: * @deprecated since 1.2, no necessity for field anymore.
029: */
030: private transient String classAttributeIdentifier;
031:
032: public DefaultMapper(ClassLoader classLoader) {
033: this .classLoader = classLoader;
034: this .classAttributeIdentifier = "class";
035: }
036:
037: /**
038: * @deprecated since 1.2, use XStream.aliasAttrbute() for a different attribute name.
039: */
040: public DefaultMapper(ClassLoader classLoader,
041: String classAttributeIdentifier) {
042: this (classLoader);
043: this .classAttributeIdentifier = classAttributeIdentifier == null ? "class"
044: : classAttributeIdentifier;
045: }
046:
047: /**
048: * @deprecated since 1.2, no necessity for method anymore.
049: */
050: private Object readResolve() {
051: classAttributeIdentifier = "class";
052: return this ;
053: }
054:
055: public String serializedClass(Class type) {
056: return type.getName();
057: }
058:
059: public Class realClass(String elementName) {
060: try {
061: return classLoader.loadClass(elementName);
062: } catch (ClassNotFoundException e) {
063: throw new CannotResolveClassException(elementName + " : "
064: + e.getMessage());
065: }
066: }
067:
068: public Class defaultImplementationOf(Class type) {
069: return type;
070: }
071:
072: /**
073: * @deprecated since 1.2, use aliasForAttribute instead.
074: */
075: public String attributeForClassDefiningField() {
076: return "defined-in";
077: }
078:
079: /**
080: * @deprecated since 1.2, use aliasForAttribute instead.
081: */
082: public String attributeForReadResolveField() {
083: return "resolves-to";
084: }
085:
086: /**
087: * @deprecated since 1.2, use aliasForAttribute instead.
088: */
089: public String attributeForEnumType() {
090: return "enum-type";
091: }
092:
093: /**
094: * @deprecated since 1.2, use aliasForAttribute instead.
095: */
096: public String attributeForImplementationClass() {
097: return classAttributeIdentifier;
098: }
099:
100: public String aliasForAttribute(String attribute) {
101: return attribute;
102: }
103:
104: public String attributeForAlias(String alias) {
105: return alias;
106: }
107:
108: public boolean isImmutableValueType(Class type) {
109: return false;
110: }
111:
112: public String getFieldNameForItemTypeAndName(Class definedIn,
113: Class itemType, String itemFieldName) {
114: return null;
115: }
116:
117: public Class getItemTypeForItemFieldName(Class definedIn,
118: String itemFieldName) {
119: return null;
120: }
121:
122: public ImplicitCollectionMapping getImplicitCollectionDefForFieldName(
123: Class itemType, String fieldName) {
124: return null;
125: }
126:
127: public boolean shouldSerializeMember(Class definedIn,
128: String fieldName) {
129: return true;
130: }
131:
132: public String lookupName(Class type) {
133: return serializedClass(type);
134: }
135:
136: public Class lookupType(String elementName) {
137: return realClass(elementName);
138: }
139:
140: public String serializedMember(Class type, String memberName) {
141: return memberName;
142: }
143:
144: public String realMember(Class type, String serialized) {
145: return serialized;
146: }
147:
148: /**
149: * @deprecated since 1.3, use {@link #getConverterFromAttribute(Class, String)}
150: */
151: public SingleValueConverter getConverterFromAttribute(String name) {
152: return null;
153: }
154:
155: /**
156: * @deprecated since 1.3, use {@link #getConverterFromItemType(String, Class, Class)}
157: */
158: public SingleValueConverter getConverterFromItemType(
159: String fieldName, Class type) {
160: return null;
161: }
162:
163: /**
164: * @deprecated since 1.3, use {@link #getConverterFromItemType(String, Class, Class)}
165: */
166: public SingleValueConverter getConverterFromItemType(Class type) {
167: return null;
168: }
169:
170: public SingleValueConverter getConverterFromItemType(
171: String fieldName, Class type, Class definedIn) {
172: return null;
173: }
174:
175: public Converter getLocalConverter(Class definedIn, String fieldName) {
176: return null;
177: }
178:
179: public Mapper lookupMapperOfType(Class type) {
180: return null;
181: }
182:
183: /**
184: * @deprecated since 1.3, use combination of {@link #serializedMember(Class, String)} and {@link #getConverterFromItemType(String, Class, Class)}
185: */
186: public String aliasForAttribute(Class definedIn, String fieldName) {
187: return fieldName;
188: }
189:
190: /**
191: * @deprecated since 1.3, use combination of {@link #realMember(Class, String)} and {@link #getConverterFromItemType(String, Class, Class)}
192: */
193: public String attributeForAlias(Class definedIn, String alias) {
194: return alias;
195: }
196:
197: public SingleValueConverter getConverterFromAttribute(Class type,
198: String attribute) {
199: return null;
200: }
201: }
|