Clover coverage report - Lingo - 1.0-SNAPSHOT
Coverage timestamp: Fri May 13 2005 08:50:34 BST
file stats: LOC: 123   Methods: 9
NCLOC: 65   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
JmsServiceExporter.java 60% 72.7% 55.6% 65.9%
coverage coverage
 1   
 /**
 2   
  *
 3   
  * Copyright 2005 LogicBlaze, Inc.
 4   
  *
 5   
  * Licensed under the Apache License, Version 2.0 (the "License");
 6   
  * you may not use this file except in compliance with the License.
 7   
  * 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   
  **/
 18   
 package org.logicblaze.lingo.jms;
 19   
 
 20   
 import org.logicblaze.lingo.jms.impl.DefaultJmsProducer;
 21   
 import org.logicblaze.lingo.jms.impl.OneWayRequestor;
 22   
 import org.springframework.beans.factory.DisposableBean;
 23   
 import org.springframework.beans.factory.InitializingBean;
 24   
 import org.springframework.remoting.support.RemoteInvocationResult;
 25   
 
 26   
 import javax.jms.ConnectionFactory;
 27   
 import javax.jms.Destination;
 28   
 import javax.jms.JMSException;
 29   
 import javax.jms.Message;
 30   
 import javax.jms.MessageConsumer;
 31   
 import javax.jms.Session;
 32   
 
 33   
 /**
 34   
  * A JMS MessageListener that exports the specified service bean as a JMS service
 35   
  * endpoint, accessible via a JMS proxy.
 36   
  * <p/>
 37   
  * <p>Note: JMS services exported with this class can be accessed by
 38   
  * any JMS client, as there isn't any special handling involved.
 39   
  *
 40   
  * @author James Strachan
 41   
  * @see JmsProxyFactoryBean
 42   
  */
 43   
 public class JmsServiceExporter extends JmsServiceExporterSupport implements InitializingBean, DisposableBean {
 44   
     private JmsProducer producer;
 45   
     private ConnectionFactory connectionFactory;
 46   
     private Destination destination;
 47   
     private MessageConsumer consumer;
 48   
 
 49  21
     public void afterPropertiesSet() throws Exception {
 50  21
         if (producer == null) {
 51  4
             if (connectionFactory == null) {
 52  0
                 throw new IllegalArgumentException("requestor or connectionFactory is required");
 53   
             }
 54   
             else {
 55  4
                 producer = DefaultJmsProducer.newInstance(connectionFactory);
 56   
             }
 57   
         }
 58  21
         Requestor responseRequestor = getResponseRequestor();
 59  21
         if (responseRequestor == null) {
 60  21
             setResponseRequestor(new OneWayRequestor(producer, null));
 61   
         }
 62   
 
 63   
         // do we have a destination specified, if so consume
 64  21
         if (destination != null) {
 65  1
             Session session = producer.getSession();
 66  1
             consumer = session.createConsumer(destination);
 67  1
             consumer.setMessageListener(this);
 68   
         }
 69   
 
 70  21
         super.afterPropertiesSet();
 71   
     }
 72   
 
 73  0
     public void destroy() throws Exception {
 74  0
         if (consumer != null) {
 75  0
             consumer.close();
 76   
         }
 77   
     }
 78   
 
 79  0
     public JmsProducer getProducer() {
 80  0
         return producer;
 81   
     }
 82   
 
 83  17
     public void setProducer(JmsProducer producer) {
 84  17
         this.producer = producer;
 85   
     }
 86   
 
 87  0
     public ConnectionFactory getConnectionFactory() {
 88  0
         return connectionFactory;
 89   
     }
 90   
 
 91   
     /**
 92   
      * Used to create a default {@link JmsProducer} if no producer is explicitly
 93   
      * configured.
 94   
      */
 95  4
     public void setConnectionFactory(ConnectionFactory connectionFactory) {
 96  4
         this.connectionFactory = connectionFactory;
 97   
     }
 98   
 
 99  0
     public Destination getDestination() {
 100  0
         return destination;
 101   
     }
 102   
 
 103   
     /**
 104   
      * If specified then the service will be auto-subscribed to this destination
 105   
      */
 106  1
     public void setDestination(Destination destination) {
 107  1
         this.destination = destination;
 108   
     }
 109   
 
 110   
     /**
 111   
      * Send the given RemoteInvocationResult as a JMS message to the originator
 112   
      *
 113   
      * @param message current HTTP message
 114   
      * @param result  the RemoteInvocationResult object
 115   
      * @throws javax.jms.JMSException if thrown by trying to send the message
 116   
      */
 117  87
     protected void writeRemoteInvocationResult(final Message message, final RemoteInvocationResult result) throws JMSException {
 118  87
         Message responseMessage = createResponseMessage(producer.getSession(), message, result);
 119  87
         producer.getMessageProducer().send(message.getJMSReplyTo(), responseMessage);
 120   
     }
 121   
 
 122   
 }
 123