<commit_before>/*
 * Copyright 2008-2010 Xebia and 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.
 */
package fr.xebia.springframework.jms;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.Topic;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;

import org.springframework.beans.factory.BeanNameAware;
import org.springframework.jms.UncategorizedJmsException;
import org.springframework.jms.listener.DefaultMessageListenerContainer;
import org.springframework.jmx.export.naming.SelfNaming;

/**
 * JMX enabled {@link DefaultMessageListenerContainer}.
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class ManagedDefaultMessageListenerContainer extends DefaultMessageListenerContainer implements
        ManagedDefaultMessageListenerContainerMBean, BeanNameAware, SelfNaming {

    private String beanName;

    private ObjectName objectName;

    public ObjectName getObjectName() throws MalformedObjectNameException {
        if (objectName == null) {
            String destinationName = getDestinationName();
            Destination destination = getDestination();
            if (destinationName == null && destination != null) {
                try {
                    if (destination instanceof Queue) {
                        Queue queue = (Queue) destination;
                        destinationName = queue.getQueueName();

                    } else if (destination instanceof Topic) {
                        Topic topic = (Topic) destination;
                        destinationName = topic.getTopicName();
                    }
                } catch (JMSException e) {
                    throw new UncategorizedJmsException(e);
                }
            }
            objectName = ObjectName.getInstance("javax.jms:type=MessageListenerContainer,name=" + ObjectName.quote(beanName)
                    + ",destination=" + destinationName);
        }
        return objectName;
    }

    @Override
    public void setBeanName(String name) {
        this.beanName = name;
    }

}<commit_msg>http://code.google.com/p/xebia-france/issues/detail?id=18 Fix Spring bean name<commit_after>/*
 * Copyright 2008-2010 Xebia and 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.
 */
package fr.xebia.springframework.jms;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.Topic;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;

import org.springframework.beans.factory.BeanNameAware;
import org.springframework.jms.UncategorizedJmsException;
import org.springframework.jms.listener.DefaultMessageListenerContainer;
import org.springframework.jmx.export.naming.SelfNaming;

/**
 * JMX enabled {@link DefaultMessageListenerContainer}.
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class ManagedDefaultMessageListenerContainer extends DefaultMessageListenerContainer implements
        ManagedDefaultMessageListenerContainerMBean, BeanNameAware, SelfNaming {

    private String beanName;

    private ObjectName objectName;

    public ObjectName getObjectName() throws MalformedObjectNameException {
        if (objectName == null) {
            String destinationName = getDestinationName();
            Destination destination = getDestination();
            if (destinationName == null && destination != null) {
                try {
                    if (destination instanceof Queue) {
                        Queue queue = (Queue) destination;
                        destinationName = queue.getQueueName();

                    } else if (destination instanceof Topic) {
                        Topic topic = (Topic) destination;
                        destinationName = topic.getTopicName();
                    }
                } catch (JMSException e) {
                    throw new UncategorizedJmsException(e);
                }
            }
            objectName = ObjectName.getInstance("javax.jms:type=MessageListenerContainer,name=" + ObjectName.quote(beanName)
                    + ",destination=" + destinationName);
        }
        return objectName;
    }

    @Override
    public void setBeanName(String name) {
        this.beanName = name;
        super.setBeanName(beanName);
    }

}
{'fraction_non_alphanumeric': 0.08170776591829224, 'fraction_numerical': 0.004784688995215311, 'mean_word_length': 2.784818941504178, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5940186', 'n_tokens_mistral': 1364, 'n_tokens_neox': 1313, 'n_words': 391}