KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > dozer > util > mapping > fieldmap > MapFieldMap


1 /*
2  * Copyright 2005-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of 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,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package net.sf.dozer.util.mapping.fieldmap;
17
18 import java.lang.reflect.InvocationTargetException JavaDoc;
19 import java.lang.reflect.Method JavaDoc;
20
21 import net.sf.dozer.util.mapping.util.MappingUtils;
22
23 import org.apache.commons.lang.StringUtils;
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26
27 /**
28  * @author garsombke.franz
29  * @author sullins.ben
30  * @author tierney.matt
31  *
32  */

33 public class MapFieldMap extends FieldMap {
34   private static final Log log = LogFactory.getLog(MapFieldMap.class);
35
36   private final MappingUtils mappingUtils = new MappingUtils();
37
38   public void writeDestinationValue(Object JavaDoc destObj, Object JavaDoc destFieldValue, ClassMap classMap)
39       throws IllegalAccessException JavaDoc, InvocationTargetException JavaDoc, InstantiationException JavaDoc, ClassNotFoundException JavaDoc,
40       NoSuchMethodException JavaDoc, NoSuchFieldException JavaDoc {
41     Method JavaDoc destFieldWriteMethod = getDestFieldWriteMethod(destObj.getClass());
42     if (destFieldWriteMethod.getParameterTypes().length == 2) { // this is a 'put'
43
String JavaDoc key = null;
44       if (StringUtils.isEmpty(getSourceField().getKey())) {
45         key = getSourceField().getName();
46       } else {
47         key = getSourceField().getKey();
48       }
49
50       if (log.isDebugEnabled()) {
51         log.debug("Getting ready to invoke write method on the destination object: "
52             + mappingUtils.getClassNameWithoutPackage(destObj.getClass()) + ", Write Method: "
53             + destFieldWriteMethod.getName() + ", Dest value: " + destFieldValue);
54       }
55       destFieldWriteMethod.invoke(destObj, new Object JavaDoc[] { key, destFieldValue });
56     } else { // this is a 'get'
57
super.writeDestinationValue(destObj, destFieldValue, classMap);
58     }
59   }
60
61 }
62
Popular Tags