Save This Page
Home » geronimo-2.2-source-release » org.apache.geronimo.jaxws » [javadoc | source]
    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.geronimo.jaxws;
   18   
   19   import java.util.ArrayList;
   20   import java.util.Iterator;
   21   import java.util.List;
   22   import java.util.Map;
   23   
   24   import javax.wsdl.Definition;
   25   import javax.wsdl.Port;
   26   import javax.wsdl.Service;
   27   import javax.wsdl.extensions.http.HTTPAddress;
   28   import javax.wsdl.extensions.soap.SOAPAddress;
   29   import javax.wsdl.extensions.soap12.SOAP12Address;
   30   import javax.xml.namespace.QName;
   31   
   32   import org.slf4j.Logger;
   33   import org.slf4j.LoggerFactory;
   34   
   35   public class WSDLUtils {
   36   
   37       private static final Logger LOG = LoggerFactory.getLogger(WSDLUtils.class);
   38       
   39       public static void trimDefinition(Definition def, 
   40                                         String serviceName, 
   41                                         String portName) { 
   42           Map services = def.getServices();
   43           if (services != null) {
   44               ArrayList<QName> servicesToRemove = new ArrayList<QName>(services.size());
   45               
   46               Iterator serviceIterator = services.entrySet().iterator();
   47               while (serviceIterator.hasNext()) {
   48                   Map.Entry serviceEntry = (Map.Entry) serviceIterator.next();
   49                   QName currServiceName = (QName) serviceEntry.getKey();
   50                   if (currServiceName.getLocalPart().equals(serviceName)) {
   51                       Service service = (Service) serviceEntry.getValue();
   52                       trimService(service, portName);
   53                   } else {
   54                       servicesToRemove.add(currServiceName);
   55                   }
   56               }
   57               
   58               for (QName serviceToRemove : servicesToRemove) {
   59                   def.removeService(serviceToRemove);                
   60               }
   61           }
   62       }
   63   
   64       public static void trimService(Service service,
   65                                      String portName) { 
   66           Map ports = service.getPorts();
   67           if (ports != null) {
   68               ArrayList<String> portsToRemove = new ArrayList<String>(ports.size());
   69               
   70               Iterator portIterator = ports.entrySet().iterator();
   71               while (portIterator.hasNext()) {
   72                   Map.Entry portEntry = (Map.Entry) portIterator.next();
   73                   String currPortName = (String) portEntry.getKey();
   74                   if (!currPortName.equals(portName)) {
   75                       portsToRemove.add(currPortName);
   76                   }
   77               }
   78               
   79               for (String portToRemove : portsToRemove) {
   80                   service.removePort(portToRemove);               
   81               }
   82           }
   83       }
   84       
   85       public static void updateLocations(Definition def, 
   86                                          String location) {
   87           Map services = def.getServices();
   88           if (services != null) {
   89               Iterator serviceIterator = services.entrySet().iterator();
   90               while (serviceIterator.hasNext()) {
   91                   Map.Entry serviceEntry = (Map.Entry) serviceIterator.next();
   92                   Service service = (Service) serviceEntry.getValue();                
   93                   updateLocations(service, location);
   94               }
   95           }            
   96       }
   97       
   98       public static void updateLocations(Service service,
   99                                          String location) {
  100           boolean updated = false;
  101           Map ports = service.getPorts();
  102           if (ports != null) {
  103               Iterator portIterator = ports.entrySet().iterator();
  104               while (portIterator.hasNext()) {
  105                   Map.Entry portEntry = (Map.Entry) portIterator.next();
  106                   Port port = (Port) portEntry.getValue();
  107                   updateLocations(port, location);
  108               }
  109           }
  110       }
  111       
  112       public static void updateLocations(Port port, 
  113                                          String location) {
  114           List<?> exts = port.getExtensibilityElements();
  115           if (exts != null) {
  116               for (Object extension : exts) {
  117                   if (extension instanceof SOAP12Address) {
  118                       ((SOAP12Address)extension).setLocationURI(location);
  119                   } else if (extension instanceof SOAPAddress) {
  120                       ((SOAPAddress)extension).setLocationURI(location);
  121                   } else if (extension instanceof HTTPAddress) {
  122                       ((HTTPAddress)extension).setLocationURI(location);
  123                   }
  124               }
  125           }
  126       }
  127   
  128   }

Save This Page
Home » geronimo-2.2-source-release » org.apache.geronimo.jaxws » [javadoc | source]