View Javadoc

1   /*
2    * Copyright 2008 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.transform.copiers;
17  
18  import java.util.Map;
19  
20  import net.sf.morph.reflect.reflectors.MapReflector;
21  
22  /**
23   * Copies one Map to another.  A PropertyNameMatchingCopier can do this as well,
24   * but only for maps whose keys are Strings!
25   *
26   * @author mbenson
27   * @since Morph 1.1
28   */
29  public class MapCopier extends ContainerCopier {
30  	private static final Class[] SOURCE_AND_DESTINATION_TYPES = { Map.class };
31  
32  	/**
33  	 * {@inheritDoc}
34  	 */
35  	protected void initializeImpl() throws Exception {
36  		super.initializeImpl();
37  		setReflector(new MapReflector(MapReflector.EXTRACT_ENTRIES));
38  	}
39  
40  	/**
41  	 * {@inheritDoc}
42  	 */
43  	protected Class[] getSourceClassesImpl() throws Exception {
44  		return SOURCE_AND_DESTINATION_TYPES;
45  	}
46  
47  	/**
48  	 * {@inheritDoc}
49  	 */
50  	protected Class[] getDestinationClassesImpl() throws Exception {
51  		return SOURCE_AND_DESTINATION_TYPES;
52  	}
53  
54  }