INT-1675: add illegal bean id check for clash with core mbean exporter

This commit is contained in:
Dave Syer
2010-12-10 10:35:28 +01:00
parent 72166141d4
commit c293edc7fa
9 changed files with 108 additions and 29 deletions

View File

@@ -1,24 +1,23 @@
/*
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package org.springframework.integration.jmx.config;
import javax.management.MBeanServerFactory;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
@@ -31,7 +30,9 @@ import org.w3c.dom.Element;
* @since 2.0
*/
public class MBeanExporterParser extends AbstractSingleBeanDefinitionParser {
private static final String ILLEGAL_NAME = "mbeanExporter";
@Override
protected boolean shouldGenerateIdAsFallback() {
return true;
@@ -54,10 +55,22 @@ public class MBeanExporterParser extends AbstractSingleBeanDefinitionParser {
String mbeanServer = element.getAttribute("server");
if (StringUtils.hasText(mbeanServer)) {
return new RuntimeBeanReference(mbeanServer);
}
else {
} else {
return MBeanServerFactory.createMBeanServer();
}
}
@Override
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
throws BeanDefinitionStoreException {
String id = super.resolveId(element, definition, parserContext);
if (ILLEGAL_NAME.equals(id)) {
parserContext.getReaderContext().error(
"Illegal bean id for <jmx:mbean-export/>: " + ILLEGAL_NAME
+ " (clashes with <context:mbean-export/> default). Please choose another bean id.",
definition);
}
return id;
}
}