1 /*
2 * JaspertReports JSF Plugin Copyright (C) 2011 A. Alonso Dominguez
3 *
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or (at
7 * your option) any later version. This library is distributed in the hope
8 * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 *
11 * See the GNU Lesser General Public License for more details. You should have
12 * received a copy of the GNU Lesser General Public License along with this
13 * library; if not, write to the Free Software Foundation, Inc., 59 Temple
14 * Place, Suite 330, Boston, MA 02111-1307 USA A.
15 *
16 * Alonso Dominguez
17 * alonsoft@users.sf.net
18 */
19 package net.sf.jasperreports.jsf.engine;
20
21 import java.sql.Connection;
22
23 /**
24 * <tt>Source</tt> implementation of a connection wrapper.
25 *
26 * @author A. Alonso Dominguez
27 */
28 public class ConnectionWrapper implements Source {
29
30 /** The wrapped connection. */
31 private Connection connection;
32
33 /**
34 * Constructor with connection instance.
35 *
36 * @param connection the connection to wrap.
37 */
38 public ConnectionWrapper(final Connection connection) {
39 if (connection == null) {
40 throw new IllegalArgumentException("'connection' can't be null");
41 }
42 this.connection = connection;
43 }
44
45 /**
46 * Obtains the wrapped connection.
47 *
48 * @return the wrapped connection.
49 */
50 public final Connection getConnection() {
51 return connection;
52 }
53
54 /**
55 * Disposes this source instance.
56 *
57 * @throws Exception if some error happens closing the connection.
58 */
59 public void dispose() throws Exception {
60 connection.close();
61 connection = null;
62 }
63
64 }