This project has retired. For details please refer to its Attic page.
Coverage Report
Coverage Report - org.apache.ws.scout.transport.LocalTransport
 
Classes in this File Line Coverage Branch Coverage Complexity
LocalTransport
51%
22/43
50%
5/10
3.25
 
 1  
 /*
 2  
  * Copyright 2001-2004 The Apache Software Foundation.
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.apache.ws.scout.transport;
 17  
 
 18  
 import java.lang.reflect.Method;
 19  
 import java.net.URI;
 20  
 
 21  
 import javax.xml.parsers.DocumentBuilder;
 22  
 import javax.xml.parsers.DocumentBuilderFactory;
 23  
 
 24  
 import org.apache.commons.logging.Log;
 25  
 import org.apache.commons.logging.LogFactory;
 26  
 import org.apache.ws.scout.util.XMLUtils;
 27  
 import org.w3c.dom.Document;
 28  
 import org.w3c.dom.Element;
 29  
 import org.w3c.dom.Node;
 30  
 
 31  
 /**
 32  
  * Local Message transport class.
 33  
  * 
 34  
  * <p>This transport calls jUDDI directly.</p>
 35  
  * 
 36  
  * @author Kurt Stam (kurt.stam@redhat.com)
 37  
  */
 38  
 public class LocalTransport implements Transport
 39  
 {
 40  2
   private static Log log = LogFactory.getLog(LocalTransport.class);
 41  
   private String nodeName;
 42  
   private String managerName;
 43  
 
 44  112
   public LocalTransport(){};
 45  
   
 46  
   public LocalTransport(String nodeName, String managerName) {
 47  0
     super();
 48  0
     this.nodeName = nodeName;
 49  0
     this.managerName = managerName;
 50  0
 }
 51  
 
 52  
 /** 
 53  
    * Sends an element and returns an element.
 54  
    */
 55  
   public Element send(Element request,URI endpointURI)
 56  
     throws TransportException
 57  
   {    
 58  513
     Element response = null;
 59  
 
 60  513
     if (log.isDebugEnabled()) {
 61  513
             log.debug("\nRequest message:\n" + XMLUtils.convertNodeToXMLString(request));
 62  513
             log.debug("Calling " + endpointURI + " locally");
 63  
     }
 64  
     try {
 65  513
             String className = endpointURI.getPath();
 66  513
             String methodName = endpointURI.getFragment();
 67  513
             log.debug("Calling class=" + className);
 68  513
             log.debug("Method=" + methodName);
 69  513
             Class<?> c = Class.forName(className);
 70  513
             Object requestHandler = c.newInstance();
 71  513
             Node node = null;
 72  513
             if (managerName!=null) {
 73  0
                 Method method = c.getMethod(methodName, Element.class, String.class, String.class);
 74  0
                 node = (Node) method.invoke(requestHandler, request, nodeName, managerName);
 75  0
             } else {
 76  513
                 Method method = c.getMethod(methodName, Element.class);
 77  513
                 node = (Node) method.invoke(requestHandler, request);
 78  
             }
 79  513
             if (node!=null && node.getFirstChild()!=null) {
 80  513
                     response = (Element) node.getFirstChild();
 81  
             }
 82  0
     } catch (Exception ex) {
 83  0
       throw new TransportException(ex);
 84  513
     }
 85  513
     if (log.isDebugEnabled()) {
 86  513
             log.debug("\nResponse message:\n" + XMLUtils.convertNodeToXMLString(response));
 87  
     }
 88  513
     return response;
 89  
   }
 90  
   
 91  
   /**
 92  
    * Sends an XML, responds with an XML.
 93  
    */
 94  
   public String send(String request,URI endpointURI)
 95  
     throws TransportException
 96  
   {    
 97  0
     String response = null;
 98  0
     log.debug("\nRequest message:\n" + request);
 99  
     try {
 100  0
             DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
 101  0
         DocumentBuilder parser = factory.newDocumentBuilder();
 102  0
         Document document = parser.parse(request);
 103  0
         Element element = document.getDocumentElement();
 104  0
         response= XMLUtils.convertNodeToXMLString(send(element, endpointURI));
 105  0
     } catch (Exception ex) { 
 106  0
             throw new TransportException(ex);
 107  0
     }
 108  0
     log.debug("\nResponse message:\n" + response);
 109  0
     return response;
 110  
   }
 111  
   
 112  
   
 113  
 }