Coverage Report - org.apache.camel.spring.EndpointFactoryBean
 
Classes in this File Line Coverage Branch Coverage Complexity
EndpointFactoryBean
65% 
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.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.Endpoint;
 27  
 import org.apache.camel.model.IdentifiedType;
 28  
 
 29  
 import org.springframework.beans.factory.FactoryBean;
 30  
 
 31  
 import static org.apache.camel.util.ObjectHelper.notNull;
 32  
 
 33  
 /**
 34  
  * A {@link FactoryBean} which instantiates {@link Endpoint} objects
 35  
  *
 36  
  * @version $Revision: 1.1 $
 37  
  */
 38  
 @XmlRootElement(name = "endpoint")
 39  
 @XmlAccessorType(XmlAccessType.FIELD)
 40  22
 public class EndpointFactoryBean extends IdentifiedType implements FactoryBean {
 41  
     @XmlAttribute
 42  
     private String uri;
 43  
     @XmlTransient
 44  
     private CamelContext context;
 45  
     @XmlTransient
 46  
     private Endpoint endpoint;
 47  
     @XmlTransient
 48  
     private boolean singleton;
 49  
 
 50  
     public Object getObject() throws Exception {
 51  20
         if (endpoint == null) {
 52  11
             endpoint = createEndpoint();
 53  
         }
 54  20
         return endpoint;
 55  
     }
 56  
 
 57  
     public Class getObjectType() {
 58  22
         return Endpoint.class;
 59  
     }
 60  
 
 61  
     public boolean isSingleton() {
 62  31
         return singleton;
 63  
     }
 64  
 
 65  
     public CamelContext getContext() {
 66  0
         return context;
 67  
     }
 68  
 
 69  
     /**
 70  
      * Sets the context to use to resolve endpoints
 71  
      *
 72  
      * @param context the context used to resolve endpoints
 73  
      */
 74  
     public void setContext(CamelContext context) {
 75  11
         this.context = context;
 76  11
     }
 77  
 
 78  
     public Endpoint getEndpoint() {
 79  0
         return endpoint;
 80  
     }
 81  
 
 82  
     public void setEndpoint(Endpoint endpoint) {
 83  0
         this.endpoint = endpoint;
 84  0
     }
 85  
 
 86  
     public void setSingleton(boolean singleton) {
 87  0
         this.singleton = singleton;
 88  0
     }
 89  
 
 90  
     public String getUri() {
 91  0
         return uri;
 92  
     }
 93  
 
 94  
     /**
 95  
      * Sets the URI to use to resolve the endpoint
 96  
      *
 97  
      * @param uri the URI used to set the endpoint
 98  
      */
 99  
     public void setUri(String uri) {
 100  11
         this.uri = uri;
 101  11
     }
 102  
 
 103  
     protected Endpoint createEndpoint() {
 104  11
         notNull(context, "context");
 105  11
         notNull(uri, "uri");
 106  11
         return context.getEndpoint(uri);
 107  
     }
 108  
 }