KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > efs > openreports > services > ParameterServiceImpl


1 /*
2  * Copyright (C) 2006 Erik Swenson - erik@oreports.com
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the Free
6  * Software Foundation; either version 2 of the License, or (at your option)
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16  * Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */

19
20 package org.efs.openreports.services;
21
22 import java.util.HashMap JavaDoc;
23
24 import org.apache.log4j.Logger;
25 import org.efs.openreports.objects.ReportParameter;
26 import org.efs.openreports.objects.ReportParameterValue;
27 import org.efs.openreports.providers.ParameterProvider;
28 import org.efs.openreports.services.info.ParameterValueInfo;
29
30 /**
31  * ParameterService implementation using standard OpenReports providers.
32  *
33  * @author Erik Swenson
34  */

35
36 public class ParameterServiceImpl implements ParameterService
37 {
38     private static Logger log = Logger.getLogger(ParameterServiceImpl.class.getName());
39     
40     private ParameterProvider parameterProvider;
41     
42     public ParameterServiceImpl()
43     {
44         log.info("ParameterServiceImpl: Started");
45     }
46     
47     /*
48      * Returns an array of parameter values for a given Query, List or
49      * Boolean parameter.
50      *
51      */

52     public ParameterValueInfo[] getParameterValues(String JavaDoc paramName)
53     {
54         if (paramName == null) return null;
55
56         ParameterValueInfo[] paramValues = null;
57
58         try
59         {
60             ReportParameter parameter = parameterProvider.getReportParameter(paramName);
61             
62             if (parameter != null
63                     && (parameter.getType().equals(ReportParameter.QUERY_PARAM)
64                             || parameter.getType().equals(ReportParameter.LIST_PARAM) || parameter
65                             .getType().equals(ReportParameter.BOOLEAN_PARAM)))
66             {
67                 //TODO support multi-step parameters
68
ReportParameterValue[] reportParamValues = parameterProvider
69                         .getParamValues(parameter, new HashMap JavaDoc());
70                 
71                 paramValues = new ParameterValueInfo[reportParamValues.length];
72
73                 for (int i = 0; i < reportParamValues.length; i++)
74                 {
75                     ParameterValueInfo paramInfo = new ParameterValueInfo();
76                     paramInfo.setId(reportParamValues[i].getId().toString());
77                     paramInfo.setDescription(reportParamValues[i].getDescription());
78                     
79                     paramValues[i] = paramInfo;
80                 }
81             }
82         }
83         catch (Exception JavaDoc e)
84         {
85             log.warn(e);
86         }
87
88         return paramValues;
89     }
90
91     public void setParameterProvider(ParameterProvider parameterProvider)
92     {
93         this.parameterProvider = parameterProvider;
94     }
95 }
96
Popular Tags