01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.invocation.http.interfaces;
23:
24: import java.io.Externalizable;
25: import java.lang.reflect.Method;
26:
27: import org.jboss.invocation.Invocation;
28: import org.jboss.proxy.Interceptor;
29:
30: /** Handle toString, equals, hashCode locally on the client.
31: *
32: * @author Scott.Stark@jboss.org
33: * @version $Revision: 57188 $
34: */
35: public class ClientMethodInterceptorHA extends Interceptor implements
36: Externalizable {
37: /** The serialVersionUID
38: * @since 1.1.4.1
39: */
40: private static final long serialVersionUID = 7633261444020820792L;
41:
42: /** Handle methods locally on the client
43: *
44: * @param mi
45: * @return
46: * @throws Throwable
47: */
48: public Object invoke(Invocation mi) throws Throwable {
49: Method m = mi.getMethod();
50: String methodName = m.getName();
51: HttpInvokerProxyHA proxy = (HttpInvokerProxyHA) mi
52: .getInvocationContext().getInvoker();
53: // Implement local methods
54: if (methodName.equals("toString")) {
55: return toString(proxy);
56: }
57: if (methodName.equals("equals")) {
58: Object[] args = mi.getArguments();
59: String this String = toString(proxy);
60: String argsString = args[0] == null ? "" : args[0]
61: .toString();
62: return new Boolean(this String.equals(argsString));
63: }
64: if (methodName.equals("hashCode")) {
65: return (Integer) mi.getObjectName();
66: }
67:
68: return getNext().invoke(mi);
69: }
70:
71: private String toString(HttpInvokerProxyHA proxy) {
72: StringBuffer tmp = new StringBuffer(proxy.toString());
73: tmp.append('{');
74: tmp.append("clusterInfo=" + proxy.getClusterInfo());
75: tmp.append('}');
76: return tmp.toString();
77: }
78: }
|