KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > dozer > util > mapping > TestCustomFieldMapper


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;
17
18 import net.sf.dozer.util.mapping.MappingException;
19 import net.sf.dozer.util.mapping.fieldmap.ClassMap;
20 import net.sf.dozer.util.mapping.fieldmap.FieldMap;
21 import net.sf.dozer.util.mapping.vo.CustomDoubleObject;
22 import net.sf.dozer.util.mapping.vo.CustomDoubleObjectIF;
23 import net.sf.dozer.util.mapping.vo.SimpleObj;
24 import net.sf.dozer.util.mapping.vo.SimpleObjPrime;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 /**
30  * @author tierney.matt
31  */

32 public class TestCustomFieldMapper implements CustomFieldMapperIF {
33   
34   public static String JavaDoc FIELD_VALUE = "This field was set on the dest object by the TestCustomFieldMapper";
35   
36   public boolean mapField(Object JavaDoc sourceObj, Object JavaDoc destObj, Object JavaDoc sourceFieldValue,
37       ClassMap classMap, FieldMap fieldMapping) {
38     boolean result = false;
39     
40     if (!(sourceObj instanceof SimpleObj)) {
41       throw new MappingException("Unsupported source object type. Should be of type: SimpleObj");
42     }
43
44     if (!(destObj instanceof SimpleObjPrime)) {
45       throw new MappingException("Unsupported dest object type. Should be of type: SimpleObjPrime");
46     }
47     
48     if (fieldMapping.getSourceField().getName().equals("field1")) {
49       ((SimpleObjPrime) destObj).setField1(FIELD_VALUE);
50       result = true;
51     }
52     
53     return result;
54   }
55   
56 }
Popular Tags