View Javadoc

1   /*
2    * $Id: SoapServiceFinder.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.providers.soap;
12  
13  import org.mule.providers.service.TransportFactory;
14  import org.mule.providers.service.TransportFactoryException;
15  import org.mule.providers.service.TransportServiceDescriptor;
16  import org.mule.providers.service.TransportServiceException;
17  import org.mule.providers.service.TransportServiceFinder;
18  import org.mule.providers.soap.i18n.SoapMessages;
19  import org.mule.util.ClassUtils;
20  import org.mule.util.PropertiesUtils;
21  
22  import java.util.Iterator;
23  import java.util.Map;
24  import java.util.TreeMap;
25  
26  /**
27   * <code>SoapServiceFinder</code> finds a the connector service to use by checking
28   * the classpath for jars required for each of the soap connector implementations
29   */
30  public class SoapServiceFinder implements TransportServiceFinder
31  {
32  
33      public TransportServiceDescriptor findService(String service, TransportServiceDescriptor csd)
34          throws TransportFactoryException
35      {
36          Map finders = new TreeMap();
37          PropertiesUtils.getPropertiesWithPrefix(csd.getProperties(), "finder.class", finders);
38  
39          StringBuffer buf = new StringBuffer();
40          for (Iterator iterator = finders.entrySet().iterator(); iterator.hasNext();)
41          {
42              Map.Entry entry = (Map.Entry)iterator.next();
43              try
44              {
45                  ClassUtils.loadClass(entry.getValue().toString(), getClass());
46                  String protocol = getProtocolFromKey(entry.getKey().toString());
47                  return TransportFactory.getServiceDescriptor(protocol);
48              }
49              catch (ClassNotFoundException e1)
50              {
51                  buf.append(entry.getValue().toString()).append("(").append(entry.getKey().toString()).append(
52                      ")").append(", ");
53              }
54          }
55          throw new TransportServiceException(SoapMessages.couldNotFindSoapProvider(buf.toString()));
56      }
57  
58      protected String getProtocolFromKey(String key)
59      {
60          return key.substring(key.lastIndexOf('.') + 1);
61      }
62  }