View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.soap.axis;
8   
9   import org.mule.api.registry.ServiceDescriptor;
10  import org.mule.api.registry.ServiceException;
11  import org.mule.api.registry.ServiceFinder;
12  import org.mule.transport.soap.axis.i18n.AxisMessages;
13  import org.mule.util.ClassUtils;
14  import org.mule.util.PropertiesUtils;
15  
16  import java.util.Iterator;
17  import java.util.Map;
18  import java.util.Properties;
19  import java.util.TreeMap;
20  
21  /**
22   * <code>SoapServiceFinder</code> finds a the connector service to use by checking
23   * the classpath for jars required for each of the soap connector implementations
24   */
25  public class SoapServiceFinder implements ServiceFinder
26  {
27      /**
28       * @deprecated We can use a more intelligent strategy for locating the service using the OSGi registry.
29       */
30      @Deprecated
31      public String findService(String service, ServiceDescriptor descriptor, Properties props) throws ServiceException
32      {
33          Map finders = new TreeMap();
34          PropertiesUtils.getPropertiesWithPrefix(props, "finder.class", finders);
35  
36          StringBuffer buf = new StringBuffer();
37          for (Iterator iterator = finders.entrySet().iterator(); iterator.hasNext();)
38          {
39              Map.Entry entry = (Map.Entry)iterator.next();
40              try
41              {
42                  ClassUtils.loadClass(entry.getValue().toString(), getClass());
43                  return getProtocolFromKey(entry.getKey().toString());
44              }
45              catch (ClassNotFoundException e1)
46              {
47                  buf.append(entry.getValue().toString()).append("(").append(entry.getKey().toString()).append(
48                      ")").append(", ");
49              }
50          }
51          throw new ServiceException(AxisMessages.couldNotFindSoapProvider(buf.toString()));
52      }
53  
54      protected String getProtocolFromKey(String key)
55      {
56          return key.substring(key.lastIndexOf('.') + 1);
57      }
58  }