|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2011 the original author or authors. |
| 2 | + * Copyright 2002-2012 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
24 | 24 | import org.apache.commons.logging.Log;
|
25 | 25 | import org.apache.commons.logging.LogFactory;
|
26 | 26 |
|
27 |
| -import org.springframework.util.Assert; |
28 |
| - |
29 | 27 | /**
|
30 | 28 | * Abstract base class for Spring's {@link javax.sql.DataSource}
|
31 | 29 | * implementations, taking care of the padding.
|
@@ -78,17 +76,16 @@ public void setLogWriter(PrintWriter pw) throws SQLException {
|
78 | 76 | //---------------------------------------------------------------------
|
79 | 77 |
|
80 | 78 | @SuppressWarnings("unchecked")
|
81 |
| - public <T> T unwrap(Class<T> iface) throws SQLException { |
82 |
| - Assert.notNull(iface, "Interface argument must not be null"); |
83 |
| - if (!DataSource.class.equals(iface)) { |
84 |
| - throw new SQLException("DataSource of type [" + getClass().getName() + |
85 |
| - "] can only be unwrapped as [javax.sql.DataSource], not as [" + iface.getName()); |
| 79 | + public <T> T unwrap(Class<T> iface) throws SQLException { |
| 80 | + if (iface.isInstance(this)) { |
| 81 | + return (T) this; |
86 | 82 | }
|
87 |
| - return (T) this; |
| 83 | + throw new SQLException("DataSource of type [" + getClass().getName() + |
| 84 | + "] cannot be unwrapped as [" + iface.getName() + "]"); |
88 | 85 | }
|
89 | 86 |
|
90 | 87 | public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
91 |
| - return DataSource.class.equals(iface); |
| 88 | + return iface.isInstance(this); |
92 | 89 | }
|
93 | 90 |
|
94 | 91 |
|
|
0 commit comments