KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.thoughtworks.xstream.mapper;
2
3 import com.thoughtworks.xstream.alias.ClassMapper;
4
5 import java.util.Collections JavaDoc;
6 import java.util.HashSet JavaDoc;
7 import java.util.Set JavaDoc;
8
9 /**
10  * Mapper that specifies which types are basic immutable types. Types that are marked as immutable will be written
11  * multiple times in the serialization stream without using references.
12  *
13  * @author Joe Walnes
14  */

15 public class ImmutableTypesMapper extends MapperWrapper {
16
17     private final Set JavaDoc immutableTypes = Collections.synchronizedSet(new HashSet JavaDoc());
18
19     public ImmutableTypesMapper(ClassMapper wrapped) {
20         super(wrapped);
21     }
22
23     public void addImmutableType(Class JavaDoc type) {
24         immutableTypes.add(type);
25     }
26
27     public boolean isImmutableValueType(Class JavaDoc type) {
28         if (immutableTypes.contains(type)) {
29             return true;
30         } else {
31             return super.isImmutableValueType(type);
32         }
33     }
34
35 }
36
Popular Tags