View Javadoc

1   /*
2    * Copyright 2004-2005, 2007 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5    * use this file except in compliance with the License. You may obtain a copy of
6    * the License at
7    * 
8    * http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
15   */
16  package net.sf.morph.util;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  /**
22   * A map where all keys and values are of type {@link java.lang.Class}. This is
23   * accomplished by making the {@link #put(Object, Object)}method convert the
24   * key and value supplied to it to a <code>Class</code> object using
25   * {@link net.sf.morph.util.ClassUtils#newInstance(Object)}. This class is
26   * included to ease the configuration of Morph. One example of where it is used
27   * is in
28   * {@link net.sf.morph.reflect.reflectors.SimpleInstantiatingReflector#setRequestedToInstantiatedTypeMap(Map)}.
29   * 
30   * @author Matt Sgarlata
31   * @since Apr 14, 2005
32   */
33  public class TypeMap extends HashMap {
34  
35  	/**
36  	 * Create a new TypeMap.
37  	 */
38  	public TypeMap() {
39  		super();
40  	}
41  
42  	/**
43  	 * Create a new TypeMap.
44  	 * @param initialCapacity
45  	 */
46  	public TypeMap(int initialCapacity) {
47  		super(initialCapacity);
48  	}
49  
50  	/**
51  	 * Create a new TypeMap.
52  	 * @param initialCapacity
53  	 * @param loadFactor
54  	 */
55  	public TypeMap(int initialCapacity, float loadFactor) {
56  		super(initialCapacity, loadFactor);
57  	}
58  
59  	/**
60  	 * Create a new TypeMap.
61  	 * @param map
62  	 */
63  	public TypeMap(Map map) {
64  		this(map.size());
65  		putAll(map);
66  	}
67  
68  	/**
69  	 * {@inheritDoc}
70  	 */
71  	public Object put(Object key, Object value) {
72  		return super.put(key == null ? null : ClassUtils.convertToClass(key),
73  				value == null ? null : ClassUtils.convertToClass(value));
74  	}
75  	
76  }