1 package com.thoughtworks.xstream.mapper; 2 3 import com.thoughtworks.xstream.alias.ClassMapper; 4 5 import java.util.Map ; 6 import java.util.Collections ; 7 import java.util.HashMap ; 8 9 14 public class CachingMapper extends MapperWrapper { 15 16 private final Map cache = Collections.synchronizedMap(new HashMap ()); 17 18 public CachingMapper(ClassMapper wrapped) { 19 super(wrapped); 20 } 21 22 public Class realClass(String elementName) { 23 final String key = elementName; 24 Class cached = (Class ) cache.get(key); 25 if (cached != null) { 26 return cached; 27 } else { 28 Class result = super.realClass(elementName); 29 cache.put(key, result); 30 return result; 31 } 32 } 33 34 } 35 | Popular Tags |