01: /*
02: * This program is free software; you can redistribute it and/or modify
03: * it under the terms of the GNU General Public License as published by
04: * the Free Software Foundation; either version 2 of the License, or
05: * (at your option) any later version.
06: *
07: * This program is distributed in the hope that it will be useful,
08: * but WITHOUT ANY WARRANTY; without even the implied warranty of
09: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10: * GNU Library General Public License for more details.
11: *
12: * You should have received a copy of the GNU General Public License
13: * along with this program; if not, write to the Free Software
14: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15: */
16: package web.struts;
17:
18: import java.lang.reflect.*;
19: import java.sql.ResultSet;
20:
21: /**
22: * 结果集合的接管,用于处理字符集的转码
23: * @author Winter Lau
24: */
25: class _ResultSet implements InvocationHandler {
26:
27: private final static Class[] infs = new Class[] { ResultSet.class };
28:
29: public _ResultSet(ResultSet rs, boolean decode) {
30: this .rs = rs;
31: this .decode = decode;
32: }
33:
34: /**
35: * 获取ResultSet的代理
36: * @return
37: */
38: public ResultSet getResultSet() {
39: return (ResultSet) Proxy.newProxyInstance(rs.getClass()
40: .getClassLoader(), infs, this );
41: }
42:
43: public Object invoke(Object proxy, Method m, Object args[])
44: throws Throwable {
45: String method = m.getName();
46: if (decode && GETSTRING.equals(method))
47: try {
48: String result = (String) m.invoke(rs, args);
49: if (result != null)
50: return new String(result.getBytes("8859_1"));
51: else
52: return null;
53: } catch (InvocationTargetException e) {
54: throw e.getTargetException();
55: }
56: try {
57: return m.invoke(rs, args);
58: } catch (InvocationTargetException e) {
59: throw e.getTargetException();
60: }
61: }
62:
63: private ResultSet rs;
64:
65: private boolean decode;
66:
67: private static final String GETSTRING = "getString";
68: }
|