1 package com.calipso.reportgenerator.common; 2 3 import com.calipso.reportgenerator.reportcalculator.SharedInteger; 4 import com.calipso.reportgenerator.reportcalculator.SharedDate; 5 import com.calipso.reportgenerator.reportcalculator.SharedString; 6 import com.calipso.reportgenerator.reportcalculator.SharedFloat; 7 import com.calipso.reportgenerator.reportdefinitions.types.ReportDataType; 8 import com.calipso.reportgenerator.reportdefinitions.ViewParameterValues; 9 import com.calipso.reportgenerator.reportdefinitions.ViewParameterValue; 10 import com.calipso.common.DateEx; 11 12 import java.util.Map ; 13 import java.util.Iterator ; 14 import java.util.Date ; 15 import java.util.HashMap ; 16 import java.text.SimpleDateFormat ; 17 18 24 public class ReportMap { 25 26 public static Map setParametersToSimpleType(Map params){ 27 return doSetParametersToType(params, false); 28 } 29 30 public static Object getSimpleTypeValue(Object value) { 31 if(value!=null){ 32 Object newValue; 33 if(value.getClass()==SharedInteger.class){ 34 newValue = ((SharedInteger)value).getValue(); 35 } else if(value.getClass()==SharedDate.class){ 36 newValue = ((SharedDate)value).getValue(); 37 newValue = ((DateEx)newValue).getDate(); 38 } else if(value.getClass()==SharedString.class){ 39 newValue = ((SharedString)value).getValue(); 40 } else if(value.getClass()==SharedFloat.class){ 41 newValue = ((SharedFloat)value).getValue(); 42 } else if(value.getClass()==DateEx.class){ 43 newValue = ((DateEx)value).getDate(); 44 } else { 45 newValue = value; 46 } 47 return newValue; 48 } 49 return null; 50 } 51 52 public static Class getJavaLangType(ReportDataType dataType) { 53 switch(dataType.getType()){ 54 case ReportDataType.DATE_TYPE: 55 case ReportDataType.DATETIME_TYPE: 56 return Date.class; 57 case ReportDataType.STRING_TYPE: 58 return String .class; 59 case ReportDataType.BOOLEAN_TYPE: 60 return Boolean .class; 61 case ReportDataType.FLOAT_TYPE: 62 return Float .class; 63 case ReportDataType.INTEGER_TYPE: 64 return Integer .class; 65 default: 66 return String .class; 67 } 68 } 69 70 76 public static Map setParametersToReportManagerType(Map params) { 77 return doSetParametersToType(params, true); 78 } 79 80 private static Map doSetParametersToType(Map params, boolean complex) { 81 Iterator iterator = params.entrySet().iterator(); 82 Object value; 83 Object newValue; 84 while(iterator.hasNext()){ 85 Map.Entry current = (Map.Entry )iterator.next(); 86 value = current.getValue(); 87 if(complex){ 88 newValue = ReportMap.getComlexTypeValue(value); 89 }else{ 90 newValue = ReportMap.getSimpleTypeValue(value); 91 } 92 current.setValue(newValue); 93 } 94 return params; 95 } 96 97 private static Object getComlexTypeValue(Object value) { 98 Object newValue; 99 if(value instanceof Integer ){ 100 newValue = SharedInteger.newFrom((Integer )value); 101 } else if(value instanceof Date){ 102 DateEx ex = new DateEx((Date)value); 103 newValue = SharedDate.newFrom(ex); 104 } else if(value instanceof String ){ 105 newValue = ((String )value).intern(); } else if(value instanceof Float ){ 107 newValue = SharedFloat.newFrom((Float )value); 108 } else { 109 newValue = value; 110 } 111 return newValue; 112 } 113 114 } 115 | Popular Tags |