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.jmx.connector.invoker.client;
23:
24: import javax.management.ObjectName;
25:
26: import org.jboss.invocation.Invocation;
27: import org.jboss.invocation.PayloadKey;
28: import org.jboss.proxy.Interceptor;
29:
30: /**
31: * An Interceptor that plucks the object name out of the arguments
32: * into an unmarshalled part of the payload.
33: *
34: * @author <a href="mailto:adrian.brock@happeningtimes.com">Adrian Brock</a>
35: * @version $Revision: 57209 $
36: */
37: public class InvokerAdaptorClientInterceptor extends Interceptor {
38: // Constants -----------------------------------------------------
39:
40: // Attributes ----------------------------------------------------
41:
42: // Constructors --------------------------------------------------
43:
44: public InvokerAdaptorClientInterceptor() {
45: // For externalization to work
46: }
47:
48: // Public --------------------------------------------------------
49:
50: /**
51: * Invoke using the invoker for remote invocations
52: */
53: public Object invoke(Invocation invocation) throws Throwable {
54: // Retrieve any relevent object name for this invocation
55: ObjectName objectName = getObjectNameFromArguments(invocation);
56: if (objectName != null)
57: invocation.setValue("JMX_OBJECT_NAME", objectName,
58: PayloadKey.AS_IS);
59:
60: try {
61: return getNext().invoke(invocation);
62: } catch (InvokerAdaptorException e) {
63: throw e.getWrapped();
64: }
65: }
66:
67: /**
68: * Return any target object name relevent for this invocation.<p>
69: *
70: * Methods that don't pass arguments that could be custom classes are ignored.<p>
71: *
72: * Classloading and registerMBean are ignored,
73: * they shouldn't be available remotely
74: */
75: public ObjectName getObjectNameFromArguments(Invocation invocation) {
76: String method = invocation.getMethod().getName();
77: if (method.equals("invoke") || method.equals("setAttribute")
78: || method.equals("setAttributes")
79: || method.equals("addNotificationListener")
80: || method.equals("removeNotificationListener")) {
81: return (ObjectName) invocation.getArguments()[0];
82: }
83:
84: return null;
85: }
86:
87: // Private -------------------------------------------------------
88:
89: // Inner classes -------------------------------------------------
90: }
|