KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > common > ReportMap


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 JavaDoc;
13 import java.util.Iterator JavaDoc;
14 import java.util.Date JavaDoc;
15 import java.util.HashMap JavaDoc;
16 import java.text.SimpleDateFormat JavaDoc;
17
18 /**
19  *
20  * User: Breto
21  * Date: 20-abr-2004
22  * Time: 15:03:57
23  */

24 public class ReportMap {
25
26   public static Map JavaDoc setParametersToSimpleType(Map JavaDoc params){
27     return doSetParametersToType(params, false);
28   }
29
30   public static Object JavaDoc getSimpleTypeValue(Object JavaDoc value) {
31     if(value!=null){
32       Object JavaDoc 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 JavaDoc 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 JavaDoc.class;
59       case ReportDataType.BOOLEAN_TYPE:
60         return Boolean JavaDoc.class;
61       case ReportDataType.FLOAT_TYPE:
62         return Float JavaDoc.class;
63       case ReportDataType.INTEGER_TYPE:
64         return Integer JavaDoc.class;
65       default:
66         return String JavaDoc.class;
67     }
68   }
69
70   /**
71    * Mecanismo inverso a setParametersToSimpleType. Los parametros pasados por parametro ya deben estar en el tipo
72    * correcto de Java (no se puede pasar un String y pretender que reconozca una fecha).
73    * @param params
74    * @return parametros en tipo "Shared..."
75    */

76   public static Map JavaDoc setParametersToReportManagerType(Map JavaDoc params) {
77     return doSetParametersToType(params, true);
78   }
79
80   private static Map JavaDoc doSetParametersToType(Map JavaDoc params, boolean complex) {
81     Iterator JavaDoc iterator = params.entrySet().iterator();
82     Object JavaDoc value;
83     Object JavaDoc newValue;
84     while(iterator.hasNext()){
85       Map.Entry JavaDoc current = (Map.Entry JavaDoc)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 JavaDoc getComlexTypeValue(Object JavaDoc value) {
98     Object JavaDoc newValue;
99     if(value instanceof Integer JavaDoc){
100       newValue = SharedInteger.newFrom((Integer JavaDoc)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 JavaDoc){
105       newValue = ((String JavaDoc)value).intern();//SharedString.newFrom((String)value);
106
} else if(value instanceof Float JavaDoc){
107       newValue = SharedFloat.newFrom((Float JavaDoc)value);
108     } else {
109       newValue = value;
110     }
111     return newValue;
112   }
113
114 }
115
Popular Tags