View Javadoc

    1   package org.codehaus.xfire.util;
    2
    3   import javax.xml.namespace.QName;
    4
    5   /***
    6    * Helps when constructing, or using services.
    7    *
    8    * @author Arjen Poutsma
    9    */
    10  public class ServiceUtils
    11  {
    12      private ServiceUtils()
    13      {
    14
    15      }
    16
    17      /***
    18       * Generates a suitable service name from a given class. The returned name is the simple name of the class, i.e.
    19       * without the package name.
    20       *
    21       * @param clazz the class.
    22       * @return the name.
    23       */
    24      public static String makeServiceNameFromClassName(Class clazz)
    25      {
    26          String name = clazz.getName();
    27          int last = name.lastIndexOf(".");
    28          if (last != -1)
    29          {
    30              name = name.substring(last + 1);
    31          }
    32
    33          int inner = name.lastIndexOf("$");
    34          if (inner != -1)
    35          {
    36              name = name.substring(inner + 1);
    37          }
    38
    39          return name;
    40      }
    41
    42      public static QName makeQualifiedNameFromClass(Class clazz)
    43      {
    44          String namespace = NamespaceHelper.makeNamespaceFromClassName(clazz.getName(), "http");
    45          String localPart = makeServiceNameFromClassName(clazz);
    46          return new QName(namespace, localPart);
    47      }
    48
    49  }