Coverage Report - org.apache.camel.component.jbi.JbiMessage
 
Classes in this File Line Coverage Branch Coverage Complexity
JbiMessage
68% 
67% 
0
 
 1  
 /**
 2  
  *
 3  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 4  
  * contributor license agreements.  See the NOTICE file distributed with
 5  
  * this work for additional information regarding copyright ownership.
 6  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 7  
  * (the "License"); you may not use this file except in compliance with
 8  
  * the License.  You may obtain a copy of the License at
 9  
  *
 10  
  * http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 package org.apache.camel.component.jbi;
 19  
 
 20  
 import org.apache.camel.Message;
 21  
 import org.apache.camel.impl.DefaultMessage;
 22  
 
 23  
 import javax.jbi.messaging.NormalizedMessage;
 24  
 import java.util.Iterator;
 25  
 import java.util.Map;
 26  
 
 27  
 /**
 28  
  * A JBI {@link Message} which provides access to the underlying JBI features such as {@link #getNormalizedMessage()}
 29  
  *
 30  
  * @version $Revision: 522517 $
 31  
  */
 32  4
 public class JbiMessage extends DefaultMessage {
 33  
     private NormalizedMessage normalizedMessage;
 34  
 
 35  5
     public JbiMessage() {
 36  5
     }
 37  
 
 38  6
     public JbiMessage(NormalizedMessage normalizedMessage) {
 39  6
         this.normalizedMessage = normalizedMessage;
 40  6
     }
 41  
 
 42  
     @Override
 43  
     public String toString() {
 44  1
         if (normalizedMessage != null) {
 45  0
             return "JbiMessage: " + normalizedMessage;
 46  
         }
 47  
         else {
 48  1
             return "JbiMessage: " + getBody();
 49  
         }
 50  
     }
 51  
 
 52  
     @Override
 53  
     public JbiExchange getExchange() {
 54  5
         return (JbiExchange) super.getExchange();
 55  
     }
 56  
 
 57  
     /**
 58  
      * Returns the underlying JBI message
 59  
      *
 60  
      * @return the underlying JBI message
 61  
      */
 62  
     public NormalizedMessage getNormalizedMessage() {
 63  0
         return normalizedMessage;
 64  
     }
 65  
 
 66  
     public void setNormalizedMessage(NormalizedMessage normalizedMessage) {
 67  0
         this.normalizedMessage = normalizedMessage;
 68  0
     }
 69  
 
 70  
     public Object getHeader(String name) {
 71  0
         Object answer = null;
 72  0
         if (normalizedMessage != null) {
 73  0
             answer = normalizedMessage.getProperty(name);
 74  
         }
 75  0
         if (answer == null) {
 76  0
             answer = super.getHeader(name);
 77  
         }
 78  0
         return answer;
 79  
     }
 80  
 
 81  
     @Override
 82  
     public JbiMessage newInstance() {
 83  3
         return new JbiMessage();
 84  
     }
 85  
 
 86  
     @Override
 87  
     protected Object createBody() {
 88  4
         if (normalizedMessage != null) {
 89  2
             return getExchange().getBinding().extractBodyFromJbi(getExchange(), normalizedMessage);
 90  
         }
 91  2
         return null;
 92  
     }
 93  
 
 94  
     @Override
 95  
     protected void populateInitialHeaders(Map<String, Object> map) {
 96  9
         if (normalizedMessage != null) {
 97  2
             Iterator iter = normalizedMessage.getPropertyNames().iterator();
 98  3
             while (iter.hasNext()) {
 99  1
                 String name = iter.next().toString();
 100  1
                 Object value = normalizedMessage.getProperty(name);
 101  1
                 map.put(name, value);
 102  1
             }
 103  
         }
 104  9
     }
 105  
 }