View Javadoc

1   package org.kuali.student.common.conversion.util;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   import org.dozer.DozerBeanMapperSingletonWrapper;
7   import org.dozer.Mapper;
8   
9   public class R1R2ConverterUtil {
10  
11      private final static Mapper dozerMapper = DozerBeanMapperSingletonWrapper.getInstance();
12      
13      public static <T, X> X convert(T source, Class<X> target) {
14          if (source == null){
15              return null;
16          }
17          
18          return dozerMapper.map(source, target);
19      }
20  
21      public static <T, X> X convert(T source, X target) {
22          if (source == null){
23              return null;
24          }        
25          
26          dozerMapper.map(source, target);
27          return target;
28      }
29  
30      public static <T, X> List<X> convertLists(List<T> sourceList, Class<X> targetListType) {
31          if (sourceList == null){
32              return null;
33          }
34          
35          List<X> targetList = new ArrayList<X>();
36          for (T sourceObject : sourceList) {
37              X targetObject = convert(sourceObject, targetListType);
38              targetList.add(targetObject);
39          }
40          return targetList;
41      }
42      
43  }