View Javadoc

1   /*
2    * $Id: SoapServiceFinder.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.transport.soap.axis;
12  
13  import org.mule.api.registry.ServiceDescriptor;
14  import org.mule.api.registry.ServiceException;
15  import org.mule.api.registry.ServiceFinder;
16  import org.mule.transport.soap.axis.i18n.AxisMessages;
17  import org.mule.util.ClassUtils;
18  import org.mule.util.PropertiesUtils;
19  
20  import java.util.Iterator;
21  import java.util.Map;
22  import java.util.Properties;
23  import java.util.TreeMap;
24  
25  /**
26   * <code>SoapServiceFinder</code> finds a the connector service to use by checking
27   * the classpath for jars required for each of the soap connector implementations
28   */
29  public class SoapServiceFinder implements ServiceFinder
30  {
31      /**
32       * @deprecated We can use a more intelligent strategy for locating the service using the OSGi registry.
33       */
34      @Deprecated
35      public String findService(String service, ServiceDescriptor descriptor, Properties props) throws ServiceException
36      {
37          Map finders = new TreeMap();
38          PropertiesUtils.getPropertiesWithPrefix(props, "finder.class", finders);
39  
40          StringBuffer buf = new StringBuffer();
41          for (Iterator iterator = finders.entrySet().iterator(); iterator.hasNext();)
42          {
43              Map.Entry entry = (Map.Entry)iterator.next();
44              try
45              {
46                  ClassUtils.loadClass(entry.getValue().toString(), getClass());
47                  return getProtocolFromKey(entry.getKey().toString());
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 ServiceException(AxisMessages.couldNotFindSoapProvider(buf.toString()));
56      }
57  
58      protected String getProtocolFromKey(String key)
59      {
60          return key.substring(key.lastIndexOf('.') + 1);
61      }
62  }