Coverage Report - org.apache.camel.component.jbi.CamelSpringDeployer
 
Classes in this File Line Coverage Branch Coverage Complexity
CamelSpringDeployer
0% 
0% 
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.Endpoint;
 21  
 import org.apache.camel.spring.SpringCamelContext;
 22  
 import org.apache.servicemix.common.xbean.AbstractXBeanDeployer;
 23  
 import org.apache.servicemix.common.ServiceUnit;
 24  
 import org.apache.xbean.kernel.Kernel;
 25  
 import org.apache.xbean.server.spring.loader.PureSpringLoader;
 26  
 import org.apache.xbean.server.spring.loader.SpringLoader;
 27  
 import org.springframework.context.ApplicationContext;
 28  
 import org.springframework.context.support.AbstractXmlApplicationContext;
 29  
 import org.springframework.context.support.FileSystemXmlApplicationContext;
 30  
 import org.springframework.context.support.GenericApplicationContext;
 31  
 
 32  
 import javax.jbi.management.DeploymentException;
 33  
 import java.util.ArrayList;
 34  
 import java.util.Collection;
 35  
 import java.util.List;
 36  
 
 37  
 /**
 38  
  * A deployer of the spring XML file
 39  
  *
 40  
  * @version $Revision: 1.1 $
 41  
  */
 42  
 public class CamelSpringDeployer extends AbstractXBeanDeployer {
 43  
     private final CamelJbiComponent component;
 44  0
     private PureSpringLoader springLoader = new PureSpringLoader() {
 45  
         @Override
 46  0
         protected AbstractXmlApplicationContext createXmlApplicationContext(String configLocation) {
 47  0
             return new FileSystemXmlApplicationContext(new String[]{configLocation}, false, createParentApplicationContext());
 48  
         }
 49  
     };
 50  0
     private List<CamelJbiEndpoint> activatedEndpoints = new ArrayList<CamelJbiEndpoint>();
 51  
 
 52  
     public CamelSpringDeployer(CamelJbiComponent component) {
 53  0
         super(component);
 54  0
         this.component = component;
 55  0
     }
 56  
 
 57  
     protected String getXBeanFile() {
 58  0
         return "camel-context";
 59  
     }
 60  
 
 61  
     /* (non-Javadoc)
 62  
     * @see org.apache.servicemix.common.Deployer#deploy(java.lang.String, java.lang.String)
 63  
     */
 64  
     @Override
 65  
     public ServiceUnit deploy(String serviceUnitName, String serviceUnitRootPath) throws DeploymentException {
 66  
         // lets register the deployer so that any endpoints activated are added to this SU 
 67  0
         component.deployer = this;
 68  0
         ServiceUnit serviceUnit = super.deploy(serviceUnitName, serviceUnitRootPath);
 69  0
         return serviceUnit;
 70  
     }
 71  
 
 72  
     public void addService(CamelJbiEndpoint endpoint) {
 73  0
         activatedEndpoints.add(endpoint);
 74  0
     }
 75  
 
 76  
     protected List getServices(Kernel kernel) {
 77  
         try {
 78  0
             List<CamelJbiEndpoint> services = new ArrayList<CamelJbiEndpoint>(activatedEndpoints);
 79  0
             activatedEndpoints.clear();
 80  
                   
 81  0
             ApplicationContext applicationContext = springLoader.getApplicationContext();
 82  0
             SpringCamelContext camelContext = SpringCamelContext.springCamelContext(applicationContext);
 83  
 
 84  
             // now lets iterate through all the endpoints
 85  0
             Collection<Endpoint> endpoints = camelContext.getSingletonEndpoints();
 86  0
             for (Endpoint endpoint : endpoints) {
 87  0
                 if (component.isEndpointExposedOnNmr(endpoint)) {
 88  0
                     services.add(component.createJbiEndpointFromCamel(endpoint));
 89  
                 }
 90  
             }
 91  0
             return services;
 92  
         }
 93  0
         catch (Exception e) {
 94  0
             throw new RuntimeException(e);
 95  
         }
 96  
     }
 97  
 
 98  
     @Override
 99  
     protected SpringLoader createSpringLoader() {
 100  0
         return springLoader;
 101  
     }
 102  
 
 103  
     /**
 104  
      * Returns the parent application context which can be used to auto-wire any JBI based components
 105  
      * using the jbi prefix
 106  
      */
 107  
     protected ApplicationContext createParentApplicationContext() {
 108  0
         GenericApplicationContext answer = new GenericApplicationContext();
 109  0
         answer.getBeanFactory().registerSingleton("jbi", component);
 110  0
         answer.start();
 111  0
         answer.refresh();
 112  0
         return answer;
 113  
     }
 114  
 
 115  
 
 116  
 }