Coverage Report - org.apache.camel.component.rmi.RmiEndpoint
 
Classes in this File Line Coverage Branch Coverage Complexity
RmiEndpoint
75% 
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.component.rmi;
 18  
 
 19  
 import java.net.URI;
 20  
 import java.net.URISyntaxException;
 21  
 import java.rmi.RemoteException;
 22  
 import java.rmi.registry.LocateRegistry;
 23  
 import java.rmi.registry.Registry;
 24  
 import java.util.Arrays;
 25  
 import java.util.List;
 26  
 
 27  
 import org.apache.camel.Consumer;
 28  
 import org.apache.camel.Processor;
 29  
 import org.apache.camel.Producer;
 30  
 import org.apache.camel.RuntimeCamelException;
 31  
 import org.apache.camel.component.pojo.PojoExchange;
 32  
 import org.apache.camel.impl.DefaultEndpoint;
 33  
 
 34  
 /**
 35  
  * @version $Revision:520964 $
 36  
  */
 37  1
 public class RmiEndpoint extends DefaultEndpoint<PojoExchange> {
 38  
 
 39  
         private List<Class> remoteInterfaces;
 40  
         private ClassLoader classLoader;
 41  
         private URI uri;
 42  
         private int port;
 43  
 
 44  
         protected RmiEndpoint(String endpointUri, RmiComponent component) throws URISyntaxException {
 45  2
                 super(endpointUri, component);
 46  2
                 this.uri = new URI(endpointUri);
 47  2
         }
 48  
 
 49  
         public boolean isSingleton() {
 50  2
                 return false;
 51  
         }
 52  
 
 53  
         public PojoExchange createExchange() {
 54  1
                 return new PojoExchange(getContext());
 55  
         }
 56  
 
 57  
         public Consumer<PojoExchange> createConsumer(Processor processor) throws Exception {
 58  1
                 if( remoteInterfaces == null || remoteInterfaces.size()==0 )
 59  0
                         throw new RuntimeCamelException("To create an RMI consumer, the RMI endpoint's remoteInterfaces property must be be configured.");
 60  1
                 return new RmiConsumer(this, processor);
 61  
         }
 62  
 
 63  
         public Producer<PojoExchange> createProducer() throws Exception {
 64  1
                 return new RmiProducer(this);
 65  
         }
 66  
 
 67  
         public String getName() {
 68  3
                 String path = uri.getPath();
 69  3
                 if( path == null )
 70  0
                         path = uri.getSchemeSpecificPart();
 71  3
                 return path;
 72  
         }
 73  
 
 74  
         public Registry getRegistry() throws RemoteException {
 75  3
                 if( uri.getHost()!=null ) {
 76  3
                         if( uri.getPort() == -1 ) {
 77  0
                                 return LocateRegistry.getRegistry(uri.getHost());
 78  
                         } else {
 79  3
                                 return LocateRegistry.getRegistry(uri.getHost(), uri.getPort());                                
 80  
                         }
 81  
                 } else {
 82  0
                         return LocateRegistry.getRegistry();
 83  
                 }
 84  
         }
 85  
 
 86  
         public List<Class> getRemoteInterfaces() {
 87  2
                 return remoteInterfaces;
 88  
         }
 89  
 
 90  
         public void setRemoteInterfaces(List<Class> remoteInterfaces) {
 91  1
                 this.remoteInterfaces = remoteInterfaces;
 92  1
                 if( classLoader== null && !remoteInterfaces.isEmpty() ) {
 93  1
                         classLoader = remoteInterfaces.get(0).getClassLoader();
 94  
                 }
 95  1
         }
 96  
         public void setRemoteInterfaces(Class... remoteInterfaces) {
 97  1
                 setRemoteInterfaces(Arrays.asList(remoteInterfaces));                
 98  1
         }
 99  
 
 100  
         public ClassLoader getClassLoader() {
 101  1
                 return classLoader;
 102  
         }
 103  
         public void setClassLoader(ClassLoader classLoader) {
 104  0
                 this.classLoader = classLoader;
 105  0
         }
 106  
 
 107  
         public int getPort() {
 108  1
                 return port;
 109  
         }
 110  
 
 111  
         public void setPort(int port) {
 112  0
                 this.port = port;
 113  0
         }
 114  
 
 115  
 
 116  
 }