diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractConsumerEndpointParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractConsumerEndpointParser.java index 7b34ca6855..2c02b7bdc5 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractConsumerEndpointParser.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractConsumerEndpointParser.java @@ -66,8 +66,10 @@ public abstract class AbstractConsumerEndpointParser extends AbstractBeanDefinit String inputChannelAttributeName = this.getInputChannelAttributeName(); if (!element.hasAttribute(inputChannelAttributeName)) { if (!parserContext.isNested()) { + String elementDescription = IntegrationNamespaceUtils.createElementDescription(element); parserContext.getReaderContext().error("The '" + inputChannelAttributeName - + "' attribute is required for this top-level endpoint element.", element); + + "' attribute is required for the top-level endpoint element " + + elementDescription + ".", element); } return handlerBeanDefinition; } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceUtils.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceUtils.java index 629e6ebc06..3f28cf52c0 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceUtils.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 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. @@ -31,6 +31,7 @@ import org.springframework.util.StringUtils; * * @author Mark Fisher * @author Marius Bogoevici + * @author Alex Peters */ public abstract class IntegrationNamespaceUtils { @@ -122,6 +123,20 @@ public abstract class IntegrationNamespaceUtils { Conventions.attributeNameToPropertyName(attributeName)); } + /** + * Provides a user friendly description of an element based on its node + * name and, if available, its "id" attribute value. This is useful for + * creating error messages from within bean definition parsers. + */ + public static String createElementDescription(Element element) { + String elementId = "'" + element.getNodeName() + "'"; + String id = element.getAttribute("id"); + if (StringUtils.hasText(id)) { + elementId += " with id='" + id + "'"; + } + return elementId; + } + /** * Parse a "poller" element to provide a reference for the target * BeanDefinitionBuilder. If the poller element does not contain a "ref" diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/ServiceActivatorParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/ServiceActivatorParser.java index b00b738804..c6b2575526 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/ServiceActivatorParser.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/ServiceActivatorParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 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. @@ -35,7 +35,8 @@ public class ServiceActivatorParser extends AbstractConsumerEndpointParser { IntegrationNamespaceUtils.BASE_PACKAGE + ".handler.ServiceActivatingHandler"); String ref = element.getAttribute(REF_ATTRIBUTE); if (!StringUtils.hasText(ref)) { - parserContext.getReaderContext().error("The '" + REF_ATTRIBUTE + "' attribute is required.", element); + parserContext.getReaderContext().error("The '" + REF_ATTRIBUTE + "' attribute is required for element " + + IntegrationNamespaceUtils.createElementDescription(element) + ".", element); } builder.addConstructorArgReference(ref); if (StringUtils.hasText(element.getAttribute(METHOD_ATTRIBUTE))) {