01: /*
02: * Copyright (C) 2005 Joe Walnes.
03: * Copyright (C) 2006, 2007 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: import java.util.HashSet;
17: import java.util.Set;
18:
19: /**
20: * Mapper that specifies which types are basic immutable types. Types that are marked as immutable will be written
21: * multiple times in the serialization stream without using references.
22: *
23: * @author Joe Walnes
24: */
25: public class ImmutableTypesMapper extends MapperWrapper {
26:
27: private final Set immutableTypes = new HashSet();
28:
29: public ImmutableTypesMapper(Mapper wrapped) {
30: super (wrapped);
31: }
32:
33: /**
34: * @deprecated As of 1.2, use {@link #ImmutableTypesMapper(Mapper)}
35: */
36: public ImmutableTypesMapper(ClassMapper wrapped) {
37: this ((Mapper) wrapped);
38: }
39:
40: public void addImmutableType(Class type) {
41: immutableTypes.add(type);
42: }
43:
44: public boolean isImmutableValueType(Class type) {
45: if (immutableTypes.contains(type)) {
46: return true;
47: } else {
48: return super.isImmutableValueType(type);
49: }
50: }
51:
52: }
|