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: 57209 $
34: */
35: public class ClientMethodInterceptor extends Interceptor implements
36: Externalizable {
37: /** The serialVersionUID. @since 1.1.4.1 */
38: private static final long serialVersionUID = 3511654206312502958L;
39:
40: /** Handle methods locally on the client
41: *
42: * @param mi
43: * @return
44: * @throws Throwable
45: */
46: public Object invoke(Invocation mi) throws Throwable {
47: Method m = mi.getMethod();
48: String methodName = m.getName();
49: HttpInvokerProxy proxy = (HttpInvokerProxy) mi
50: .getInvocationContext().getInvoker();
51: // Implement local methods
52: if (methodName.equals("toString")) {
53: return toString(proxy);
54: }
55: if (methodName.equals("equals")) {
56: Object[] args = mi.getArguments();
57: String this String = toString(proxy);
58: String argsString = args[0] == null ? "" : args[0]
59: .toString();
60: return new Boolean(this String.equals(argsString));
61: }
62: if (methodName.equals("hashCode")) {
63: return (Integer) mi.getObjectName();
64: }
65:
66: return getNext().invoke(mi);
67: }
68:
69: private String toString(HttpInvokerProxy proxy) {
70: StringBuffer tmp = new StringBuffer(proxy.toString());
71: tmp.append('{');
72: tmp.append("externalURLValue=" + proxy.getExternalURLValue());
73: tmp.append(",externalURL=" + proxy.getExternalURL());
74: tmp.append('}');
75: return tmp.toString();
76: }
77: }
|