Coverage Report - org.apache.camel.spring.CamelTemplateFactoryBean
 
Classes in this File Line Coverage Branch Coverage Complexity
CamelTemplateFactoryBean
0% 
0% 
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.spring;
 18  
 
 19  
 import javax.xml.bind.annotation.XmlAccessType;
 20  
 import javax.xml.bind.annotation.XmlAccessorType;
 21  
 import javax.xml.bind.annotation.XmlAttribute;
 22  
 import javax.xml.bind.annotation.XmlRootElement;
 23  
 import javax.xml.bind.annotation.XmlTransient;
 24  
 
 25  
 import org.apache.camel.CamelContext;
 26  
 import org.apache.camel.CamelContextAware;
 27  
 import org.apache.camel.CamelTemplate;
 28  
 import org.apache.camel.Endpoint;
 29  
 
 30  
 import org.springframework.beans.factory.FactoryBean;
 31  
 import org.springframework.beans.factory.InitializingBean;
 32  
 
 33  
 /**
 34  
  * A Spring {@link FactoryBean} for creating a new {@link CamelTemplate}
 35  
  * instance with a minimum of XML
 36  
  * 
 37  
  * @version $Revision: $
 38  
  */
 39  
 @XmlRootElement(name = "camelTemplate")
 40  
 @XmlAccessorType(XmlAccessType.FIELD)
 41  0
 public class CamelTemplateFactoryBean implements FactoryBean, InitializingBean, CamelContextAware {
 42  
     @XmlAttribute(required = false)
 43  
     private String defaultEndpoint;
 44  
     @XmlTransient
 45  
     private CamelContext camelContext;
 46  
 
 47  
     public void afterPropertiesSet() throws Exception {
 48  0
         if (camelContext == null) {
 49  0
             throw new IllegalArgumentException("A CamelContext must be injected!");
 50  
         }
 51  0
     }
 52  
 
 53  
     public Object getObject() throws Exception {
 54  0
         CamelContext context = getCamelContext();
 55  0
         if (defaultEndpoint != null) {
 56  0
             Endpoint endpoint = context.getEndpoint(defaultEndpoint);
 57  0
             if (endpoint == null) {
 58  0
                 throw new IllegalArgumentException("No endpoint found for URI: " + defaultEndpoint);
 59  
             } else {
 60  0
                 return new CamelTemplate(context, endpoint);
 61  
             }
 62  
         }
 63  0
         return new CamelTemplate(context);
 64  
     }
 65  
 
 66  
     public Class getObjectType() {
 67  0
         return CamelTemplate.class;
 68  
     }
 69  
 
 70  
     public boolean isSingleton() {
 71  0
         return true;
 72  
     }
 73  
 
 74  
     // Properties
 75  
     // -------------------------------------------------------------------------
 76  
     public CamelContext getCamelContext() {
 77  0
         return camelContext;
 78  
     }
 79  
 
 80  
     public void setCamelContext(CamelContext camelContext) {
 81  0
         this.camelContext = camelContext;
 82  0
     }
 83  
 
 84  
     public String getDefaultEndpoint() {
 85  0
         return defaultEndpoint;
 86  
     }
 87  
 
 88  
     /**
 89  
      * Sets the default endpoint URI used by default for sending message
 90  
      * exchanges
 91  
      */
 92  
     public void setDefaultEndpoint(String defaultEndpoint) {
 93  0
         this.defaultEndpoint = defaultEndpoint;
 94  0
     }
 95  
 }