Coverage Report - org.apache.camel.spring.remoting.CamelServiceExporter
 
Classes in this File Line Coverage Branch Coverage Complexity
CamelServiceExporter
65% 
100% 
2
 
 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.spring.remoting;
 19  
 
 20  
 import org.apache.camel.CamelContext;
 21  
 import org.apache.camel.component.pojo.PojoComponent;
 22  
 import org.springframework.beans.factory.DisposableBean;
 23  
 import org.springframework.beans.factory.InitializingBean;
 24  
 import org.springframework.remoting.support.RemoteExporter;
 25  
 
 26  
 /**
 27  
  * Exports a Spring defined service to Camel as a Pojo endpoint.
 28  
  *  
 29  
  * @author chirino
 30  
  */
 31  1
 public class CamelServiceExporter extends RemoteExporter implements InitializingBean, DisposableBean {
 32  
 
 33  
         CamelContext camelContext;
 34  
         PojoComponent pojoComponent;
 35  
         String serviceName;
 36  
         
 37  
         public void afterPropertiesSet() throws Exception {
 38  1
                 if( serviceName == null ) {
 39  0
                         throw new IllegalArgumentException("The serviceName must be configured.");
 40  
                 }
 41  1
                 if( pojoComponent == null ) {
 42  1
                         if( camelContext == null ) {
 43  0
                                 throw new IllegalArgumentException("A pojoComponent or camelContext must be configured.");
 44  
                         }
 45  1
                         pojoComponent = (PojoComponent) camelContext.getComponent("pojo");
 46  1
                         if( pojoComponent == null ) {
 47  0
                                 throw new IllegalArgumentException("The pojoComponent could not be found.");
 48  
                         }
 49  
                 }
 50  1
                 pojoComponent.addService(serviceName, getProxyForService());
 51  1
         }
 52  
 
 53  
         public void destroy() throws Exception {
 54  1
                 if( serviceName!=null ) {
 55  1
                         pojoComponent.removeService(serviceName);
 56  
                 }
 57  1
         }
 58  
 
 59  
         
 60  
         public PojoComponent getPojoComponent() {
 61  0
                 return pojoComponent;
 62  
         }
 63  
         public void setPojoComponent(PojoComponent pojoComponent) {
 64  0
                 this.pojoComponent = pojoComponent;
 65  0
         }
 66  
 
 67  
         public CamelContext getCamelContext() {
 68  0
                 return camelContext;
 69  
         }
 70  
         public void setCamelContext(CamelContext camelContext) {
 71  1
                 this.camelContext = camelContext;
 72  1
         }
 73  
 
 74  
         public String getServiceName() {
 75  0
                 return serviceName;
 76  
         }
 77  
         public void setServiceName(String serviceName) {
 78  1
                 this.serviceName = serviceName;
 79  1
         }
 80  
 
 81  
 }