01: /*
02: * Copyright 2005-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.fieldmapper;
17:
18: import net.sf.dozer.util.mapping.CustomFieldMapperIF;
19: import net.sf.dozer.util.mapping.MappingException;
20: import net.sf.dozer.util.mapping.classmap.ClassMap;
21: import net.sf.dozer.util.mapping.fieldmap.FieldMap;
22: import net.sf.dozer.util.mapping.vo.SimpleObj;
23: import net.sf.dozer.util.mapping.vo.SimpleObjPrime;
24:
25: /**
26: * @author tierney.matt
27: */
28: public class TestCustomFieldMapper implements CustomFieldMapperIF {
29:
30: public static String FIELD_VALUE = "This field was set on the dest object by the TestCustomFieldMapper";
31:
32: public boolean mapField(Object sourceObj, Object destObj,
33: Object sourceFieldValue, ClassMap classMap,
34: FieldMap fieldMapping) {
35: boolean result = false;
36:
37: if (!(sourceObj instanceof SimpleObj)) {
38: throw new MappingException(
39: "Unsupported source object type. Should be of type: SimpleObj");
40: }
41:
42: if (!(destObj instanceof SimpleObjPrime)) {
43: throw new MappingException(
44: "Unsupported dest object type. Should be of type: SimpleObjPrime");
45: }
46:
47: if (fieldMapping.getSrcFieldName().equals("field1")) {
48: ((SimpleObjPrime) destObj).setField1(FIELD_VALUE);
49: result = true;
50: }
51:
52: return result;
53: }
54:
55: }
|