01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.aegis.util;
19:
20: import java.lang.reflect.Method;
21:
22: import javax.xml.namespace.QName;
23:
24: /**
25: * Helps when constructing, or using services.
26: *
27: * @author Arjen Poutsma
28: */
29: public final class ServiceUtils {
30: private ServiceUtils() {
31:
32: }
33:
34: /**
35: * Generates a suitable service name from a given class. The returned name
36: * is the simple name of the class, i.e. without the package name.
37: *
38: * @param clazz the class.
39: * @return the name.
40: */
41: public static String makeServiceNameFromClassName(Class clazz) {
42: String name = clazz.getName();
43: int last = name.lastIndexOf(".");
44: if (last != -1) {
45: name = name.substring(last + 1);
46: }
47:
48: int inner = name.lastIndexOf("$");
49: if (inner != -1) {
50: name = name.substring(inner + 1);
51: }
52:
53: return name;
54: }
55:
56: public static QName makeQualifiedNameFromClass(Class clazz) {
57: String namespace = NamespaceHelper.makeNamespaceFromClassName(
58: clazz.getName(), "http");
59: String localPart = makeServiceNameFromClassName(clazz);
60: return new QName(namespace, localPart);
61: }
62:
63: public static String getMethodName(Method m) {
64: StringBuffer sb = new StringBuffer();
65: sb.append(m.getDeclaringClass().getName());
66: sb.append('.');
67: sb.append(m.getName());
68: sb.append('(');
69: Class[] params = m.getParameterTypes();
70: for (int i = 0; i < params.length; i++) {
71: Class param = params[i];
72: sb.append(param.getName());
73: if (i < params.length - 1) {
74: sb.append(", ");
75: }
76: }
77: sb.append(')');
78: return sb.toString();
79: }
80: }
|