01: /*
02: * Copyright (C) 2006, 2007 XStream Committers.
03: * All rights reserved.
04: *
05: * The software in this package is published under the terms of the BSD
06: * style license a copy of which has been included with this distribution in
07: * the LICENSE.txt file.
08: *
09: * Created on 08. April 2006 by Joerg Schaible
10: */
11: package com.thoughtworks.xstream.mapper;
12:
13: import net.sf.cglib.proxy.Enhancer;
14:
15: /**
16: * Mapper that detects proxies generated by the CGLIB enhancer. The implementation modifies
17: * the name, so that it can identify these types. Note, that this mapper relies on the CGLIB
18: * converters:
19: * <ul>
20: * <li>CGLIBEnhancedConverter</li>
21: * </ul>
22: *
23: * @author Jörg Schaible
24: * @since 1.2
25: */
26: public class CGLIBMapper extends MapperWrapper {
27:
28: private static String DEFAULT_NAMING_MARKER = "$$EnhancerByCGLIB$$";
29: private final String alias;
30:
31: public interface Marker {
32: }
33:
34: public CGLIBMapper(Mapper wrapped) {
35: this (wrapped, "CGLIB-enhanced-proxy");
36: }
37:
38: public CGLIBMapper(Mapper wrapped, String alias) {
39: super (wrapped);
40: this .alias = alias;
41: }
42:
43: public String serializedClass(Class type) {
44: return type.getName().indexOf(DEFAULT_NAMING_MARKER) > 0
45: && Enhancer.isEnhanced(type) ? alias : super
46: .serializedClass(type);
47: }
48:
49: public Class realClass(String elementName) {
50: return elementName.equals(alias) ? Marker.class : super
51: .realClass(elementName);
52: }
53: }
|