Coverage Report - org.apache.camel.component.jms.JmsEndpoint
 
Classes in this File Line Coverage Branch Coverage Complexity
JmsEndpoint
75% 
100% 
0
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.camel.component.jms;
 18  
 
 19  
 import javax.jms.Message;
 20  
 
 21  
 import org.apache.camel.Processor;
 22  
 import org.apache.camel.PollingConsumer;
 23  
 import org.apache.camel.impl.DefaultEndpoint;
 24  
 import org.springframework.jms.core.JmsOperations;
 25  
 import org.springframework.jms.core.JmsTemplate;
 26  
 import org.springframework.jms.listener.AbstractMessageListenerContainer;
 27  
 
 28  
 /**
 29  
  * A <a href="http://activemq.apache.org/jms.html">JMS Endpoint</a>
 30  
  *
 31  
   * @version $Revision:520964 $
 32  
  */
 33  142
 public class JmsEndpoint extends DefaultEndpoint<JmsExchange> {
 34  
     private JmsBinding binding;
 35  
     private String destination;
 36  
     private final boolean pubSubDomain;
 37  
     private String selector;
 38  
     private JmsConfiguration configuration;
 39  
 
 40  
     public JmsEndpoint(String uri, JmsComponent component, String destination, boolean pubSubDomain, JmsConfiguration configuration) {
 41  133
         super(uri, component);
 42  133
         this.configuration = configuration;
 43  133
         this.destination = destination;
 44  133
         this.pubSubDomain = pubSubDomain;
 45  133
     }
 46  
 
 47  
     public JmsProducer createProducer() throws Exception {
 48  52
         JmsOperations template = createJmsOperations();
 49  52
         return createProducer(template);
 50  
     }
 51  
 
 52  
     /**
 53  
      * Creates a producer using the given template
 54  
      */
 55  
     public JmsProducer createProducer(JmsOperations template) throws Exception {
 56  52
         if (template instanceof JmsTemplate) {
 57  52
             JmsTemplate jmsTemplate = (JmsTemplate) template;
 58  52
             jmsTemplate.setPubSubDomain(pubSubDomain);
 59  52
             jmsTemplate.setDefaultDestinationName(destination);
 60  
         }
 61  52
         return new JmsProducer(this, template);
 62  
     }
 63  
 
 64  
     public JmsConsumer createConsumer(Processor processor) throws Exception {
 65  81
         AbstractMessageListenerContainer listenerContainer = configuration.createMessageListenerContainer();
 66  81
         return createConsumer(processor, listenerContainer);
 67  
     }
 68  
 
 69  
     /**
 70  
      * Creates a consumer using the given processor and listener container
 71  
      *
 72  
      * @param processor the processor to use to process the messages
 73  
      * @param listenerContainer the listener container
 74  
      * @return a newly created consumer
 75  
      * @throws Exception if the consumer cannot be created
 76  
      */
 77  
     public JmsConsumer createConsumer(Processor processor, AbstractMessageListenerContainer listenerContainer) throws Exception {
 78  81
         listenerContainer.setDestinationName(destination);
 79  81
         listenerContainer.setPubSubDomain(pubSubDomain);
 80  81
         if (selector != null) {
 81  0
             listenerContainer.setMessageSelector(selector);
 82  
         }
 83  81
         return new JmsConsumer(this, processor, listenerContainer);
 84  
     }
 85  
 
 86  
     @Override
 87  
     public PollingConsumer<JmsExchange> createPollingConsumer() throws Exception {
 88  0
         JmsOperations template = createJmsOperations();
 89  0
         return new JmsPollingConsumer(this, template);
 90  
     }
 91  
 
 92  
     public JmsExchange createExchange() {
 93  11
         return new JmsExchange(getContext(), getBinding());
 94  
     }
 95  
 
 96  
     public JmsExchange createExchange(Message message) {
 97  0
         return new JmsExchange(getContext(), getBinding(), message);
 98  
     }
 99  
 
 100  
     // Properties
 101  
     //-------------------------------------------------------------------------
 102  
     public JmsBinding getBinding() {
 103  116
         if (binding == null) {
 104  103
             binding = new JmsBinding();
 105  
         }
 106  116
         return binding;
 107  
     }
 108  
 
 109  
     /**
 110  
      * Sets the binding used to convert from a Camel message to and from a JMS message
 111  
      *
 112  
      * @param binding the binding to use
 113  
      */
 114  
     public void setBinding(JmsBinding binding) {
 115  0
         this.binding = binding;
 116  0
     }
 117  
 
 118  
     public String getDestination() {
 119  24
         return destination;
 120  
     }
 121  
 
 122  
     public JmsConfiguration getConfiguration() {
 123  202
         return configuration;
 124  
     }
 125  
 
 126  
     public String getSelector() {
 127  0
         return selector;
 128  
     }
 129  
 
 130  
     /**
 131  
      * Sets the JMS selector to use
 132  
      */
 133  
     public void setSelector(String selector) {
 134  0
         this.selector = selector;
 135  0
     }
 136  
 
 137  
         public boolean isSingleton() {
 138  133
                 return false;
 139  
         }
 140  
 
 141  
 
 142  
     protected JmsOperations createJmsOperations() {
 143  52
         return configuration.createJmsOperations(pubSubDomain, destination);
 144  
     }
 145  
 
 146  
 }