1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
18
18
19
19
import java .util .Map ;
20
20
import javax .management .MBeanServer ;
21
+ import javax .naming .NamingException ;
21
22
22
23
import org .springframework .beans .factory .BeanFactory ;
23
24
import org .springframework .beans .factory .BeanFactoryAware ;
24
- import org .springframework .beans .factory .FactoryBean ;
25
25
import org .springframework .beans .factory .config .BeanDefinition ;
26
26
import org .springframework .context .EnvironmentAware ;
27
27
import org .springframework .core .annotation .AnnotationAttributes ;
28
28
import org .springframework .core .env .Environment ;
29
29
import org .springframework .core .type .AnnotationMetadata ;
30
+ import org .springframework .jmx .MBeanServerNotFoundException ;
30
31
import org .springframework .jmx .export .annotation .AnnotationMBeanExporter ;
31
32
import org .springframework .jmx .support .RegistrationPolicy ;
32
33
import org .springframework .jmx .support .WebSphereMBeanServerFactoryBean ;
33
- import org .springframework .jndi .JndiObjectFactoryBean ;
34
+ import org .springframework .jndi .JndiLocatorDelegate ;
34
35
import org .springframework .util .Assert ;
35
36
import org .springframework .util .ClassUtils ;
36
37
import org .springframework .util .StringUtils ;
@@ -119,21 +120,26 @@ private void setupRegistrationPolicy(AnnotationMBeanExporter exporter) {
119
120
}
120
121
121
122
122
- private static enum SpecificPlatform {
123
+ public static enum SpecificPlatform {
123
124
124
125
WEBLOGIC ("weblogic.management.Helper" ) {
125
126
@ Override
126
- public FactoryBean <?> getMBeanServerFactory () {
127
- JndiObjectFactoryBean factory = new JndiObjectFactoryBean ();
128
- factory .setJndiName ("java:comp/env/jmx/runtime" );
129
- return factory ;
127
+ public MBeanServer getMBeanServer () {
128
+ try {
129
+ return new JndiLocatorDelegate ().lookup ("java:comp/env/jmx/runtime" , MBeanServer .class );
130
+ }
131
+ catch (NamingException ex ) {
132
+ throw new MBeanServerNotFoundException ("Failed to retrieve WebLogic MBeanServer from JNDI" , ex );
133
+ }
130
134
}
131
135
},
132
136
133
137
WEBSPHERE ("com.ibm.websphere.management.AdminServiceFactory" ) {
134
138
@ Override
135
- public FactoryBean <MBeanServer > getMBeanServerFactory () {
136
- return new WebSphereMBeanServerFactoryBean ();
139
+ public MBeanServer getMBeanServer () {
140
+ WebSphereMBeanServerFactoryBean fb = new WebSphereMBeanServerFactoryBean ();
141
+ fb .afterPropertiesSet ();
142
+ return fb .getObject ();
137
143
}
138
144
};
139
145
@@ -143,19 +149,7 @@ private SpecificPlatform(String identifyingClass) {
143
149
this .identifyingClass = identifyingClass ;
144
150
}
145
151
146
- public MBeanServer getMBeanServer () {
147
- Object server ;
148
- try {
149
- server = getMBeanServerFactory ().getObject ();
150
- Assert .isInstanceOf (MBeanServer .class , server );
151
- return (MBeanServer ) server ;
152
- }
153
- catch (Exception ex ) {
154
- throw new IllegalStateException (ex );
155
- }
156
- }
157
-
158
- protected abstract FactoryBean <?> getMBeanServerFactory ();
152
+ public abstract MBeanServer getMBeanServer ();
159
153
160
154
public static SpecificPlatform get () {
161
155
ClassLoader classLoader = MBeanExportConfiguration .class .getClassLoader ();
0 commit comments