Clover coverage report - Lingo - 1.0-SNAPSHOT
Coverage timestamp: Fri May 13 2005 08:50:34 BST
file stats: LOC: 101   Methods: 7
NCLOC: 54   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
DefaultMarshaller.java 40% 52.4% 42.9% 47.4%
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.marshall;
 19   
 
 20   
 import org.logicblaze.lingo.LingoInvocation;
 21   
 import org.logicblaze.lingo.jms.Requestor;
 22   
 import org.apache.commons.logging.Log;
 23   
 import org.apache.commons.logging.LogFactory;
 24   
 import org.springframework.remoting.support.RemoteInvocation;
 25   
 import org.springframework.remoting.support.RemoteInvocationResult;
 26   
 
 27   
 import javax.jms.JMSException;
 28   
 import javax.jms.Message;
 29   
 import javax.jms.ObjectMessage;
 30   
 
 31   
 /**
 32   
  * Represents the strategy of marshalling of requests and responses in and out of JMS messages
 33   
  *
 34   
  * @version $Revision: 1.1 $
 35   
  */
 36   
 public class DefaultMarshaller implements Marshaller {
 37   
 
 38   
     private static final Log log = LogFactory.getLog(DefaultMarshaller.class);
 39   
 
 40   
     private boolean ignoreInvalidMessages;
 41   
 
 42  76
     public Message createRequestMessage(Requestor requestor, LingoInvocation invocation) throws JMSException {
 43  76
         return requestor.getSession().createObjectMessage(invocation);
 44   
     }
 45   
 
 46  87
     public RemoteInvocationResult extractInvocationResult(Message message) throws JMSException {
 47  87
         if (message instanceof ObjectMessage) {
 48  87
             ObjectMessage objectMessage = (ObjectMessage) message;
 49  87
             Object body = objectMessage.getObject();
 50  87
             if (body instanceof RemoteInvocationResult) {
 51  87
                 return (RemoteInvocationResult) body;
 52   
             }
 53   
         }
 54  0
         return onInvalidClientMessage(message);
 55   
     }
 56   
 
 57  72
     public RemoteInvocation readRemoteInvocation(Message message) throws JMSException {
 58  72
         if (message instanceof ObjectMessage) {
 59  72
             ObjectMessage objectMessage = (ObjectMessage) message;
 60  72
             Object body = objectMessage.getObject();
 61  72
             if (body instanceof RemoteInvocation) {
 62  72
                 return (RemoteInvocation) body;
 63   
             }
 64   
         }
 65  0
         return onInvalidMessage(message);
 66   
     }
 67   
 
 68   
 
 69   
     // Properties
 70   
     //-------------------------------------------------------------------------
 71  0
     public boolean isIgnoreInvalidMessages() {
 72  0
         return ignoreInvalidMessages;
 73   
     }
 74   
 
 75   
     /**
 76   
      * Sets whether invalidly formatted messages should be silently ignored or not
 77   
      */
 78  0
     public void setIgnoreInvalidMessages(boolean ignoreInvalidMessages) {
 79  0
         this.ignoreInvalidMessages = ignoreInvalidMessages;
 80   
     }
 81   
 
 82   
     // Implementation methods
 83   
     //-------------------------------------------------------------------------
 84  0
     protected RemoteInvocationResult onInvalidClientMessage(Message message) throws JMSException {
 85  0
         throw new JMSException("Invalid response message: " + message);
 86   
     }
 87   
 
 88   
     /**
 89   
      * Handle invalid messages by just logging, though a different implementation
 90   
      * may wish to throw exceptions
 91   
      */
 92  0
     protected RemoteInvocation onInvalidMessage(Message message) {
 93  0
         String text = "Invalid message will be discarded: " + message;
 94  0
         log.info(text);
 95  0
         if (!ignoreInvalidMessages) {
 96  0
             throw new RuntimeException(text);
 97   
         }
 98  0
         return null;
 99   
     }
 100   
 }
 101