01: /*
02: * Copyright (C) 2005, 2006 Joe Walnes.
03: * Copyright (C) 2006, 2007, 2008 XStream Committers.
04: * All rights reserved.
05: *
06: * The software in this package is published under the terms of the BSD
07: * style license a copy of which has been included with this distribution in
08: * the LICENSE.txt file.
09: *
10: * Created on 22. January 2005 by Joe Walnes
11: */
12: package com.thoughtworks.xstream.mapper;
13:
14: import com.thoughtworks.xstream.alias.ClassMapper;
15:
16: /**
17: * Mapper that ensures that all names in the serialization stream are XML friendly.
18: * The replacement chars and strings are:
19: * <ul>
20: * <li><b>$</b> (dollar) chars appearing in class names are replaced with <b>_</b> (underscore) chars.<br></li>
21: * <li><b>$</b> (dollar) chars appearing in field names are replaced with <b>_DOLLAR_</b> string.<br></li>
22: * <li><b>_</b> (underscore) chars appearing in field names are replaced with <b>__</b> (double underscore) string.<br></li>
23: * <li><b>default</b> as the prefix for class names with no package.</li>
24: * </ul>
25: *
26: * @author Joe Walnes
27: * @author Mauro Talevi
28: * @deprecated since 1.3, use {@link com.thoughtworks.xstream.io.xml.XmlFriendlyReader}
29: */
30: public class XmlFriendlyMapper extends AbstractXmlFriendlyMapper {
31:
32: /**
33: * @deprecated since 1.3, use {@link com.thoughtworks.xstream.io.xml.XmlFriendlyReader}
34: */
35: public XmlFriendlyMapper(Mapper wrapped) {
36: super (wrapped);
37: }
38:
39: /**
40: * @deprecated since 1.2, use {@link #XmlFriendlyMapper(Mapper)}
41: */
42: public XmlFriendlyMapper(ClassMapper wrapped) {
43: this ((Mapper) wrapped);
44: }
45:
46: public String serializedClass(Class type) {
47: return escapeClassName(super .serializedClass(type));
48: }
49:
50: public Class realClass(String elementName) {
51: return super .realClass(unescapeClassName(elementName));
52: }
53:
54: public String serializedMember(Class type, String memberName) {
55: return escapeFieldName(super .serializedMember(type, memberName));
56: }
57:
58: public String realMember(Class type, String serialized) {
59: return unescapeFieldName(super .realMember(type, serialized));
60: }
61:
62: public String mapNameToXML(String javaName) {
63: return escapeFieldName(javaName);
64: }
65:
66: public String mapNameFromXML(String xmlName) {
67: return unescapeFieldName(xmlName);
68: }
69:
70: }
|