KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.thoughtworks.xstream.mapper;
2
3 import com.thoughtworks.xstream.alias.ClassMapper;
4
5 import java.lang.reflect.Proxy JavaDoc;
6
7 /**
8  * Mapper for handling special cases of aliasing dynamic proxies. The alias property specifies the name an instance
9  * of a dynamic proxy should be serialized with.
10  *
11  * @author Joe Walnes
12  */

13 public class DynamicProxyMapper extends MapperWrapper {
14
15     private String JavaDoc alias = "dynamic-proxy";
16
17     public DynamicProxyMapper(ClassMapper wrapped) {
18         super(wrapped);
19     }
20
21     public DynamicProxyMapper(ClassMapper wrapped, String JavaDoc alias) {
22         super(wrapped);
23         this.alias = alias;
24     }
25
26     public String JavaDoc getAlias() {
27         return alias;
28     }
29
30     public void setAlias(String JavaDoc alias) {
31         this.alias = alias;
32     }
33
34     public String JavaDoc serializedClass(Class JavaDoc type) {
35         if (Proxy.isProxyClass(type)) {
36             return alias;
37         } else {
38             return super.serializedClass(type);
39         }
40     }
41
42     public Class JavaDoc realClass(String JavaDoc elementName) {
43         if (elementName.equals(alias)) {
44             return DynamicProxy.class;
45         } else {
46             return super.realClass(elementName);
47         }
48     }
49
50     /**
51      * Place holder type used for dynamic proxies.
52      */

53     public static class DynamicProxy {}
54
55 }
56
Popular Tags