You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by bu...@apache.org on 2021/03/16 23:05:55 UTC
[cxf] 02/02: cxf-core: cleanup ServiceUtils
This is an automated email from the ASF dual-hosted git repository.
buhhunyx pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git
commit 04876cc1556108d78c04653cd22867fb295cfff8
Author: Alexey Markevich <bu...@gmail.com>
AuthorDate: Wed Mar 17 02:02:51 2021 +0300
cxf-core: cleanup ServiceUtils
---
.../org/apache/cxf/common/util/PackageUtils.java | 5 -
.../java/org/apache/cxf/helpers/ServiceUtils.java | 124 ---------------------
.../apache/cxf/common/util/PackageUtilsTest.java | 4 +-
.../apache/cxf/aegis/type/AbstractTypeCreator.java | 2 +-
.../cxf/aegis/type/java5/Java5TypeCreator.java | 2 +-
.../org/apache/cxf/aegis/util/ServiceUtils.java | 78 -------------
6 files changed, 4 insertions(+), 211 deletions(-)
diff --git a/core/src/main/java/org/apache/cxf/common/util/PackageUtils.java b/core/src/main/java/org/apache/cxf/common/util/PackageUtils.java
index 49e19ff..b07874b 100644
--- a/core/src/main/java/org/apache/cxf/common/util/PackageUtils.java
+++ b/core/src/main/java/org/apache/cxf/common/util/PackageUtils.java
@@ -110,11 +110,6 @@ public final class PackageUtils {
}
String domain = tokens.remove(0);
- // comma was removed by tokenize
-// idx = domain.indexOf(':');
-// if (idx >= 0) {
-// domain = domain.substring(0, idx);
-// }
List<String> r = tokenize(domain, urnScheme ? ".-" : ".");
Collections.reverse(r);
if ("www".equalsIgnoreCase(r.get(r.size() - 1))) {
diff --git a/core/src/main/java/org/apache/cxf/helpers/ServiceUtils.java b/core/src/main/java/org/apache/cxf/helpers/ServiceUtils.java
index 4abd6a3..a39ee94 100644
--- a/core/src/main/java/org/apache/cxf/helpers/ServiceUtils.java
+++ b/core/src/main/java/org/apache/cxf/helpers/ServiceUtils.java
@@ -19,13 +19,8 @@
package org.apache.cxf.helpers;
-import java.lang.reflect.Method;
-import java.net.MalformedURLException;
-import java.net.URL;
import java.util.StringTokenizer;
-import javax.xml.namespace.QName;
-
import org.apache.cxf.annotations.SchemaValidation.SchemaValidationType;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.message.Exchange;
@@ -183,30 +178,6 @@ public final class ServiceUtils {
return name;
}
- public static QName makeQualifiedNameFromClass(Class<?> clazz) {
- String namespace = makeNamespaceFromClassName(clazz.getName(), "http");
- String localPart = makeServiceNameFromClassName(clazz);
- return new QName(namespace, localPart);
- }
-
- public static String getMethodName(Method m) {
- StringBuilder sb = new StringBuilder();
- sb.append(m.getDeclaringClass().getName());
- sb.append('.');
- sb.append(m.getName());
- sb.append('(');
- Class<?>[] params = m.getParameterTypes();
- for (int i = 0; i < params.length; i++) {
- Class<?> param = params[i];
- sb.append(param.getName());
- if (i < params.length - 1) {
- sb.append(", ");
- }
- }
- sb.append(')');
- return sb.toString();
- }
-
/**
* Generates the name of a XML namespace from a given class name and
* protocol. The returned namespace will take the form
@@ -240,99 +211,4 @@ public final class ServiceUtils {
return protocol + "://" + String.join(".", words) + "/";
}
- /**
- * Method makePackageName
- *
- * @param namespace
- */
- public static String makePackageName(String namespace) {
-
- String hostname;
- String path = "";
-
- // get the target namespace of the document
- try {
- URL u = new URL(namespace);
-
- hostname = u.getHost();
- path = u.getPath();
- } catch (MalformedURLException e) {
- if (namespace.indexOf(':') > -1) {
- hostname = namespace.substring(namespace.indexOf(':') + 1);
-
- if (hostname.indexOf('/') > -1) {
- hostname = hostname.substring(0, hostname.indexOf('/'));
- }
- } else {
- hostname = namespace;
- }
- }
-
- // if we didn't file a hostname, bail
- if (hostname == null) {
- return null;
- }
-
- // convert illegal java identifier
- hostname = hostname.replace('-', '_');
- path = path.replace('-', '_');
-
- // chomp off last forward slash in path, if necessary
- if ((path.length() > 0) && (path.charAt(path.length() - 1) == '/')) {
- path = path.substring(0, path.length() - 1);
- }
-
- // tokenize the hostname and reverse it
- StringTokenizer st = new StringTokenizer(hostname, ".:");
- String[] words = new String[st.countTokens()];
-
- for (int i = 0; i < words.length; ++i) {
- words[i] = st.nextToken();
- }
-
- StringBuilder sb = new StringBuilder(namespace.length());
-
- for (int i = words.length - 1; i >= 0; --i) {
- addWordToPackageBuffer(sb, words[i], i == words.length - 1);
- }
-
- // tokenize the path
- StringTokenizer st2 = new StringTokenizer(path, "/");
-
- while (st2.hasMoreTokens()) {
- addWordToPackageBuffer(sb, st2.nextToken(), false);
- }
-
- return sb.toString();
- }
-
- /**
- * Massage <tt>word</tt> into a form suitable for use in a Java package
- * name. Append it to the target string buffer with a <tt>.</tt> delimiter
- * iff <tt>word</tt> is not the first word in the package name.
- *
- * @param sb the buffer to append to
- * @param word the word to append
- * @param firstWord a flag indicating whether this is the first word
- */
- private static void addWordToPackageBuffer(StringBuilder sb, String word, boolean firstWord) {
-
- if (JavaUtils.isJavaKeyword(word)) {
- word = JavaUtils.makeNonJavaKeyword(word);
- }
-
- // separate with dot after the first word
- if (!firstWord) {
- sb.append('.');
- }
-
- // prefix digits with underscores
- if (Character.isDigit(word.charAt(0))) {
- sb.append('_');
- }
-
- // replace periods with underscores
- sb.append(word.replace('.', '_'));
- }
-
}
diff --git a/core/src/test/java/org/apache/cxf/common/util/PackageUtilsTest.java b/core/src/test/java/org/apache/cxf/common/util/PackageUtilsTest.java
index 6dad735..3f930ba 100644
--- a/core/src/test/java/org/apache/cxf/common/util/PackageUtilsTest.java
+++ b/core/src/test/java/org/apache/cxf/common/util/PackageUtilsTest.java
@@ -132,8 +132,8 @@ public class PackageUtilsTest {
PackageUtils.getPackageNameByNameSpaceURI("uri:cxf.apache.org:jstest"));
assertEquals("soapinterface.ems.esendex.com",
PackageUtils.getPackageNameByNameSpaceURI("com.esendex.ems.soapinterface"));
- assertEquals("ddd.cc.bb.aa.eee.fff_v01_00",
- PackageUtils.getPackageNameByNameSpaceURI("http://aa.bb.cc.ddd/eee/fff_v01.00"));
+ assertEquals("ddd.cc.bb.aa._int.fff_v01_00",
+ PackageUtils.getPackageNameByNameSpaceURI("http://aa.bb.cc.ddd/Int/fff-v01.00"));
assertEquals("org.apache.cxf._case",
PackageUtils.getPackageNameByNameSpaceURI("http://www.case.cxf.apache.org"));
assertEquals("org.apache.cxf._case",
diff --git a/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java b/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java
index 8ed3fef..33a59ef 100644
--- a/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java
+++ b/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java
@@ -34,8 +34,8 @@ import org.apache.cxf.aegis.type.basic.ObjectType;
import org.apache.cxf.aegis.type.collection.CollectionType;
import org.apache.cxf.aegis.type.collection.MapType;
import org.apache.cxf.aegis.util.NamespaceHelper;
-import org.apache.cxf.aegis.util.ServiceUtils;
import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.helpers.ServiceUtils;
import org.apache.cxf.wsdl.WSDLConstants;
import org.apache.ws.commons.schema.constants.Constants;
diff --git a/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/Java5TypeCreator.java b/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/Java5TypeCreator.java
index 9033212..02da76e 100644
--- a/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/Java5TypeCreator.java
+++ b/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/Java5TypeCreator.java
@@ -40,8 +40,8 @@ import org.apache.cxf.aegis.type.TypeClassInfo;
import org.apache.cxf.aegis.type.TypeUtil;
import org.apache.cxf.aegis.type.basic.BeanType;
import org.apache.cxf.aegis.util.NamespaceHelper;
-import org.apache.cxf.aegis.util.ServiceUtils;
import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.helpers.ServiceUtils;
public class Java5TypeCreator extends AbstractTypeCreator {
private static final Logger LOG = LogUtils.getL7dLogger(Java5TypeCreator.class);
diff --git a/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/ServiceUtils.java b/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/ServiceUtils.java
deleted file mode 100644
index 574efc0..0000000
--- a/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/ServiceUtils.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.aegis.util;
-
-import java.lang.reflect.Method;
-
-import javax.xml.namespace.QName;
-
-/**
- * Helps when constructing, or using services.
- */
-public final class ServiceUtils {
- private ServiceUtils() {
-
- }
-
- /**
- * Generates a suitable service name from a given class. The returned name
- * is the simple name of the class, i.e. without the package name.
- *
- * @param clazz the class.
- * @return the name.
- */
- public static String makeServiceNameFromClassName(Class<?> clazz) {
- String name = clazz.getName();
- int last = name.lastIndexOf('.');
- if (last != -1) {
- name = name.substring(last + 1);
- }
-
- int inner = name.lastIndexOf('$');
- if (inner != -1) {
- name = name.substring(inner + 1);
- }
-
- return name;
- }
-
- public static QName makeQualifiedNameFromClass(Class<?> clazz) {
- String namespace = NamespaceHelper.makeNamespaceFromClassName(clazz.getName(), "http");
- String localPart = makeServiceNameFromClassName(clazz);
- return new QName(namespace, localPart);
- }
-
- public static String getMethodName(Method m) {
- StringBuilder sb = new StringBuilder();
- sb.append(m.getDeclaringClass().getName());
- sb.append('.');
- sb.append(m.getName());
- sb.append('(');
- Class<?>[] params = m.getParameterTypes();
- for (int i = 0; i < params.length; i++) {
- Class<?> param = params[i];
- sb.append(param.getName());
- if (i < params.length - 1) {
- sb.append(", ");
- }
- }
- sb.append(')');
- return sb.toString();
- }
-}