From e146e53d9b0ef70e6b75b0a1a7818c2392a2d5d1 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 4 Nov 2013 23:14:57 +0100 Subject: [PATCH] Added support for the JCA 1.7 getActivationName() method Issue: SPR-11067 --- .../endpoint/JmsMessageEndpointManager.java | 13 ++++++-- .../AbstractMessageEndpointFactory.java | 30 +++++++++++++++---- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/JmsMessageEndpointManager.java b/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/JmsMessageEndpointManager.java index 3586dffaad..cbf5f37654 100644 --- a/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/JmsMessageEndpointManager.java +++ b/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/JmsMessageEndpointManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -19,6 +19,7 @@ package org.springframework.jms.listener.endpoint; import javax.jms.MessageListener; import javax.resource.ResourceException; +import org.springframework.beans.factory.BeanNameAware; import org.springframework.jca.endpoint.GenericMessageEndpointManager; import org.springframework.jms.support.destination.DestinationResolver; @@ -45,7 +46,7 @@ import org.springframework.jms.support.destination.DestinationResolver; * @see JmsActivationSpecFactory * @see JmsMessageEndpointFactory */ -public class JmsMessageEndpointManager extends GenericMessageEndpointManager { +public class JmsMessageEndpointManager extends GenericMessageEndpointManager implements BeanNameAware { private final JmsMessageEndpointFactory endpointFactory = new JmsMessageEndpointFactory(); @@ -127,6 +128,14 @@ public class JmsMessageEndpointManager extends GenericMessageEndpointManager { this.activationSpecConfig = activationSpecConfig; } + /** + * Set the name of this message endpoint. Populated with the bean name + * automatically when defined within Spring's bean factory. + */ + @Override + public void setBeanName(String beanName) { + this.endpointFactory.setBeanName(beanName); + } @Override public void afterPropertiesSet() throws ResourceException { diff --git a/spring-tx/src/main/java/org/springframework/jca/endpoint/AbstractMessageEndpointFactory.java b/spring-tx/src/main/java/org/springframework/jca/endpoint/AbstractMessageEndpointFactory.java index 208a1f85bf..eae06de77c 100644 --- a/spring-tx/src/main/java/org/springframework/jca/endpoint/AbstractMessageEndpointFactory.java +++ b/spring-tx/src/main/java/org/springframework/jca/endpoint/AbstractMessageEndpointFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -29,11 +29,12 @@ import javax.transaction.xa.XAResource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.beans.factory.BeanNameAware; import org.springframework.transaction.jta.SimpleTransactionFactory; import org.springframework.transaction.jta.TransactionFactory; /** - * Abstract base implementation of the JCA 1.5/1.6 + * Abstract base implementation of the JCA 1.5/1.6/1.7 * {@link javax.resource.spi.endpoint.MessageEndpointFactory} interface, * providing transaction management capabilities as well as ClassLoader * exposure for endpoint invocations. @@ -42,7 +43,7 @@ import org.springframework.transaction.jta.TransactionFactory; * @since 2.5 * @see #setTransactionManager */ -public abstract class AbstractMessageEndpointFactory implements MessageEndpointFactory { +public abstract class AbstractMessageEndpointFactory implements MessageEndpointFactory, BeanNameAware { /** Logger available to subclasses */ protected final Log logger = LogFactory.getLog(getClass()); @@ -53,6 +54,8 @@ public abstract class AbstractMessageEndpointFactory implements MessageEndpointF private int transactionTimeout = -1; + private String beanName; + /** * Set the the XA transaction manager to use for wrapping endpoint @@ -116,6 +119,24 @@ public abstract class AbstractMessageEndpointFactory implements MessageEndpointF this.transactionTimeout = transactionTimeout; } + /** + * Set the name of this message endpoint. Populated with the bean name + * automatically when defined within Spring's bean factory. + */ + @Override + public void setBeanName(String beanName) { + this.beanName = beanName; + } + + + /** + * Implementation of the JCA 1.7 {@code #getActivationName()} method, + * returning the bean name as set on this MessageEndpointFactory. + * @see #setBeanName + */ + public String getActivationName() { + return this.beanName; + } /** * This implementation returns {@code true} if a transaction manager @@ -157,8 +178,7 @@ public abstract class AbstractMessageEndpointFactory implements MessageEndpointF * @return the actual endpoint instance (never {@code null}) * @throws UnavailableException if no endpoint is available at present */ - protected abstract AbstractMessageEndpoint createEndpointInternal() - throws UnavailableException; + protected abstract AbstractMessageEndpoint createEndpointInternal() throws UnavailableException; /**