KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > efs > openreports > actions > admin > EditDataSourceAction


1 /*
2  * Copyright (C) 2002 Erik Swenson - eswenson@opensourcesoft.net
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.actions.admin;
21
22 import com.opensymphony.xwork.ActionSupport;
23
24 import org.apache.log4j.Logger;
25
26 import org.efs.openreports.objects.ReportDataSource;
27 import org.efs.openreports.providers.DataSourceProvider;
28 import org.efs.openreports.providers.DataSourceProviderAware;
29
30 public class EditDataSourceAction extends ActionSupport implements DataSourceProviderAware
31 {
32     protected static Logger log =
33             Logger.getLogger(EditDataSourceAction.class);
34     
35     private String JavaDoc command;
36     private String JavaDoc dataSource;
37     private String JavaDoc submitType;
38
39     private int id;
40     private String JavaDoc name;
41     private String JavaDoc driver;
42     private String JavaDoc url;
43     private String JavaDoc userName;
44     private String JavaDoc password;
45     private int maxIdle;
46     private int maxActive;
47     private long maxWait;
48     private String JavaDoc validationQuery;
49     private boolean jndi;
50     
51     private DataSourceProvider dataSourceProvider;
52
53     public String JavaDoc execute()
54     {
55         try
56         {
57             ReportDataSource reportDataSource = null;
58
59             if (command.equals("edit"))
60             {
61                 reportDataSource =
62                     dataSourceProvider.getDataSource(new Integer JavaDoc(id));
63             }
64             else
65             {
66                 reportDataSource = new ReportDataSource();
67             }
68
69             if (command.equals("edit") && submitType == null)
70             {
71                 id = reportDataSource.getId().intValue();
72                 name = reportDataSource.getName();
73                 driver = reportDataSource.getDriverClassName();
74                 url = reportDataSource.getUrl();
75                 userName = reportDataSource.getUsername();
76                 password = reportDataSource.getPassword();
77                 maxIdle = reportDataSource.getMaxIdle();
78                 maxActive = reportDataSource.getMaxActive();
79                 validationQuery = reportDataSource.getValidationQuery();
80                 jndi = reportDataSource.isJndi();
81                 maxWait = reportDataSource.getMaxWait();
82             }
83
84             if (submitType == null)
85                 return INPUT;
86
87             reportDataSource.setName(name);
88             reportDataSource.setDriverClassName(driver);
89             reportDataSource.setUrl(url);
90             reportDataSource.setUsername(userName);
91             reportDataSource.setPassword(password);
92             reportDataSource.setMaxIdle(maxIdle);
93             reportDataSource.setMaxActive(maxActive);
94             reportDataSource.setJndi(jndi);
95             reportDataSource.setMaxWait(maxWait);
96             
97             if (validationQuery == null || validationQuery.length() < 1)
98             {
99                 reportDataSource.setValidationQuery(null);
100             }
101             else
102             {
103                 reportDataSource.setValidationQuery(validationQuery);
104             }
105
106             if (command.equals("edit"))
107             {
108                 dataSourceProvider.updateDataSource(reportDataSource);
109             }
110
111             if (command.equals("add"))
112             {
113                 reportDataSource =
114                     dataSourceProvider.insertDataSource(reportDataSource);
115             }
116
117             return SUCCESS;
118         }
119         catch (Exception JavaDoc e)
120         {
121             log.error(e.toString());
122             addActionError(e.getMessage());
123             return INPUT;
124         }
125     }
126
127     public String JavaDoc getCommand()
128     {
129         return command;
130     }
131
132     public String JavaDoc getDataSource()
133     {
134         return dataSource;
135     }
136
137     public void setCommand(String JavaDoc command)
138     {
139         this.command = command;
140     }
141
142     public void setDataSource(String JavaDoc dataSource)
143     {
144         this.dataSource = dataSource;
145     }
146
147     public String JavaDoc getDriver()
148     {
149         return driver;
150     }
151
152     public int getMaxActive()
153     {
154         return maxActive;
155     }
156
157     public int getMaxIdle()
158     {
159         return maxIdle;
160     }
161
162     public String JavaDoc getPassword()
163     {
164         return password;
165     }
166
167     public String JavaDoc getUrl()
168     {
169         return url;
170     }
171
172     public String JavaDoc getUserName()
173     {
174         return userName;
175     }
176
177     public void setDriver(String JavaDoc driver)
178     {
179         this.driver = driver;
180     }
181
182     public void setMaxActive(int maxActive)
183     {
184         this.maxActive = maxActive;
185     }
186
187     public void setMaxIdle(int maxIdle)
188     {
189         this.maxIdle = maxIdle;
190     }
191
192     public void setPassword(String JavaDoc password)
193     {
194         this.password = password;
195     }
196
197     public void setUrl(String JavaDoc url)
198     {
199         this.url = url;
200     }
201
202     public void setUserName(String JavaDoc userName)
203     {
204         this.userName = userName;
205     }
206
207     public String JavaDoc getSubmitType()
208     {
209         return submitType;
210     }
211
212     public void setSubmitType(String JavaDoc submitType)
213     {
214         this.submitType = submitType;
215     }
216
217     public int getId()
218     {
219         return id;
220     }
221
222     public String JavaDoc getName()
223     {
224         return name;
225     }
226
227     public void setId(int id)
228     {
229         this.id = id;
230     }
231
232     public void setName(String JavaDoc name)
233     {
234         this.name = name;
235     }
236
237     public String JavaDoc getValidationQuery()
238     {
239         return validationQuery;
240     }
241
242     public void setValidationQuery(String JavaDoc validationQuery)
243     {
244         this.validationQuery = validationQuery;
245     }
246
247     public boolean isJndi()
248     {
249         return jndi;
250     }
251
252     public void setJndi(boolean jndi)
253     {
254         this.jndi = jndi;
255     }
256
257     public void setDataSourceProvider(DataSourceProvider dataSourceProvider)
258     {
259         this.dataSourceProvider = dataSourceProvider;
260     }
261
262     public long getMaxWait()
263     {
264         return maxWait;
265     }
266
267     public void setMaxWait(long maxWait)
268     {
269         this.maxWait = maxWait;
270     }
271
272 }
Popular Tags