1 /*
2 * JBoss, the OpenSource J2EE webOS
3 *
4 * Distributable under LGPL license.
5 * See terms of license at gnu.org.
6 */
7
8 // $Id: JMXEngineConfigurationFactory.java,v 1.2.2.1 2003/11/06 15:36:05 cgjung Exp $
9
10 package org.jboss.net.axis.server;
11
12 import javax.management.JMException;
13 import javax.management.MalformedObjectNameException;
14 import javax.management.ObjectName;
15 import javax.management.MBeanServer;
16
17 import org.apache.axis.EngineConfiguration;
18 import org.apache.axis.EngineConfigurationFactory;
19 import org.apache.axis.server.AxisServer;
20 import org.jboss.mx.util.MBeanServerLocator;
21
22 /**
23 * <p> A configuration factory that accesses axis server engines
24 * via JMX attribute access. </p>
25 * @author jung
26 * @version $Revision: 1.2.2.1 $
27 * @since 9.9.2002
28 */
29
30 public class JMXEngineConfigurationFactory
31 implements EngineConfigurationFactory {
32
33 //
34 // Attributes
35 //
36
37 protected ObjectName objectName;
38 protected MBeanServer server;
39
40 //
41 // Constructors
42 //
43
44 /** construct a new factory tied to a particular engine provider mbean */
45
46 protected JMXEngineConfigurationFactory(String name)
47 throws MalformedObjectNameException {
48 server = MBeanServerLocator.locateJBoss();
49 this.objectName = new ObjectName(name);
50 }
51
52 //
53 // Protected Helpers
54 //
55
56 /**
57 * find attribute through JMX server and mbean
58 */
59
60 protected Object getAttribute(String attributeName) {
61 try {
62 return server.getAttribute(objectName, attributeName);
63 } catch (JMException e) {
64 return null;
65 }
66 }
67
68 //
69 // Public API
70 //
71
72 /** return axis server associated with mbean */
73 public AxisServer getAxisServer() {
74 return (AxisServer) getAttribute("AxisServer");
75 }
76
77 /* (non-Javadoc)
78 * @see org.apache.axis.EngineConfigurationFactory#getClientEngineConfig()
79 */
80 public EngineConfiguration getClientEngineConfig() {
81 return (EngineConfiguration) getAttribute("ClientEngineConfiguration");
82 }
83
84 /* (non-Javadoc)
85 * @see org.apache.axis.EngineConfigurationFactory#getServerEngineConfig()
86 */
87 public EngineConfiguration getServerEngineConfig() {
88 return (EngineConfiguration) getAttribute("ServerEngineConfiguration");
89 }
90
91 /**
92 * static method to create a new jmx factory
93 * @param param objectname of the server mbean
94 * @return a new factory bound to that mbean, if it exists
95 */
96 public static JMXEngineConfigurationFactory newJMXFactory(String param) {
97 try {
98 return new JMXEngineConfigurationFactory((String) param);
99 } catch (MalformedObjectNameException e) {
100 return null;
101 }
102 }
103
104 /**
105 * static method to create a new factory along the Axis spec
106 * @param param specification of the configuration
107 * @return new factory, if the param represents an mbean object name
108 */
109
110 public static EngineConfigurationFactory newFactory(Object param) {
111 if (param instanceof String) {
112 return newJMXFactory((String) param);
113 } else {
114 return null;
115 }
116 }
117
118 }