Coverage Report - org.dozer.converters.StringConverter
 
Classes in this File Line Coverage Branch Coverage Complexity
StringConverter
100%
13/13
100%
12/12
2.5
 
 1  
 /**
 2  
  * Copyright 2005-2013 Dozer Project
 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 org.dozer.converters;
 17  
 
 18  
 
 19  
 import org.apache.commons.beanutils.Converter;
 20  
 
 21  
 /**
 22  
  * Internal class for converting Supported Data Types --> String. Uses date formatter for Date and Calendar source
 23  
  * objects. Calls toString() on the source object for all other types. Only intended for internal use.
 24  
  * 
 25  
  * @author tierney.matt
 26  
  */
 27  
 public class StringConverter implements Converter {
 28  
   private DateFormatContainer dateFormatContainer;
 29  
 
 30  44494
   public StringConverter(DateFormatContainer dateFormatContainer) {
 31  44494
     this.dateFormatContainer = dateFormatContainer;
 32  44494
   }
 33  
 
 34  
   public Object convert(Class destClass, Object srcObj) {
 35  
     String result;
 36  44493
     Class srcClass = srcObj.getClass();
 37  44493
     if (dateFormatContainer != null && java.util.Date.class.isAssignableFrom(srcClass)
 38  
         && dateFormatContainer.getDateFormat() != null) {
 39  6
       result = dateFormatContainer.getDateFormat().format((java.util.Date) srcObj);
 40  44487
     } else if (dateFormatContainer != null && java.util.Calendar.class.isAssignableFrom(srcClass)
 41  
         && dateFormatContainer.getDateFormat() != null) {
 42  14
       result = dateFormatContainer.getDateFormat().format(((java.util.Calendar) srcObj).getTime());
 43  
     } else {
 44  44473
       result = srcObj.toString();
 45  
     }
 46  
 
 47  44493
     return result;
 48  
   }
 49  
 
 50  
   public DateFormatContainer getDateFormatContainer() {
 51  1
     return dateFormatContainer;
 52  
   }
 53  
 
 54  
   public void setDateFormatContainer(DateFormatContainer dateFormat) {
 55  1
     this.dateFormatContainer = dateFormat;
 56  1
   }
 57  
 }