1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * 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 org.jboss.invocation.Invocation;
25 import org.jboss.invocation.PayloadKey;
26 import org.jboss.proxy.Interceptor;
27
28 import javax.management.ObjectName;
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: 37459 $
36 */
37 public class InvokerAdaptorClientInterceptor
38 extends Interceptor
39 {
40 // Constants -----------------------------------------------------
41
42 // Attributes ----------------------------------------------------
43
44 // Constructors --------------------------------------------------
45
46 public InvokerAdaptorClientInterceptor()
47 {
48 // For externalization to work
49 }
50
51 // Public --------------------------------------------------------
52
53 /**
54 * Invoke using the invoker for remote invocations
55 */
56 public Object invoke(Invocation invocation)
57 throws Throwable
58 {
59 // Retrieve any relevent object name for this invocation
60 ObjectName objectName = getObjectNameFromArguments(invocation);
61 if (objectName != null)
62 invocation.setValue("JMX_OBJECT_NAME", objectName, PayloadKey.AS_IS);
63
64 try
65 {
66 return getNext().invoke(invocation);
67 }
68 catch (InvokerAdaptorException e)
69 {
70 throw e.getWrapped();
71 }
72 }
73
74 /**
75 * Return any target object name relevent for this invocation.<p>
76 *
77 * Methods that don't pass arguments that could be custom classes are ignored.<p>
78 *
79 * Classloading and registerMBean are ignored,
80 * they shouldn't be available remotely
81 */
82 public ObjectName getObjectNameFromArguments(Invocation invocation)
83 {
84 String method = invocation.getMethod().getName();
85 if (method.equals("invoke") ||
86 method.equals("setAttribute") ||
87 method.equals("setAttributes") ||
88 method.equals("addNotificationListener") ||
89 method.equals("removeNotificationListener"))
90 {
91 return (ObjectName) invocation.getArguments()[0];
92 }
93
94 return null;
95 }
96
97 // Private -------------------------------------------------------
98
99 // Inner classes -------------------------------------------------
100 }