1 /*
2 * Copyright (c) 2005-2007 Creative Sphere Limited.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 *
10 * Creative Sphere - initial API and implementation
11 *
12 */
13 package org.abstracthorizon.danube.connection;
14
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 /**
19 * Simple Connection wrapper class.
20 *
21 * @author Daniel Sendula
22 */
23 public abstract class ConnectionWrapper implements Connection {
24
25 /** Logger */
26 protected final Logger logger = LoggerFactory.getLogger(getClass());
27
28 /** Wrapped connection */
29 protected Connection connection;
30
31 /**
32 * Constructor
33 * @param connection
34 */
35 public ConnectionWrapper(Connection connection) {
36 this.connection = connection;
37
38 }
39
40 /**
41 * Closes the connection
42 */
43 public void close() {
44 connection.close();
45 }
46
47 /**
48 * Checks if underlaying connection closed
49 * @return <code>true</code> if underlaying connection closed
50 */
51 public boolean isClosed() {
52 return connection.isClosed();
53 }
54
55 /**
56 * Adopts this object using supplied adopter manager
57 * @param cls class to be adopted to
58 * @return this connection adopted to asked class
59 */
60 @SuppressWarnings("unchecked")
61 public <T> T adapt(Class<T> cls) {
62 if (cls == getClass()) {
63 return (T)this;
64 } else {
65 return connection.adapt(cls);
66 }
67 }
68 }