descriptionbuilderutils.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 353 行 · 第 1/2 页
JAVA
353 行
/*
* 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.axis2.jaxws.description.builder;
import org.apache.axis2.jaxws.ExceptionFactory;
import org.apache.axis2.jaxws.util.ClassLoaderUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
*
*/
class DescriptionBuilderUtils {
private static final Log log = LogFactory.getLog(DescriptionBuilderUtils.class);
static String JAXWS_HOLDER_CLASS = "javax.xml.ws.Holder";
private static final String INT_PRIMITIVE = "int";
private static final String INT_PRIMITIVE_ENCODING = "I";
private static final String BYTE_PRIMITIVE = "byte";
private static final String BYTE_PRIMITIVE_ENCODING = "B";
private static final String CHAR_PRIMITIVE = "char";
private static final String CHAR_PRIMITIVE_ENCODING = "C";
private static final String SHORT_PRIMITIVE = "short";
private static final String SHORT_PRIMITIVE_ENCODING = "S";
private static final String BOOLEAN_PRIMITIVE = "boolean";
private static final String BOOLEAN_PRIMITIVE_ENCODING = "Z";
private static final String LONG_PRIMITIVE = "long";
private static final String LONG_PRIMITIVE_ENCODING = "J";
private static final String FLOAT_PRIMITIVE = "float";
private static final String FLOAT_PRIMITIVE_ENCODING = "F";
private static final String DOUBLE_PRIMITIVE = "double";
private static final String DOUBLE_PRIMITIVE_ENCODING = "D";
private static final String VOID_PRIMITIVE = "void";
// REVIEW: This may not be the correct encoding for Void
private static final String VOID_PRIMITIVE_ENCODING = "V";
/**
* Returns a string representing the outermost generic raw type class, or null if the argument
* is not a generic. For example if the string "javax.xml.ws.Holder<my.package.MyObject>" is
* passed in, the string "javax.xml.ws.Holder" will be returned.
* <p/>
* Note that generic arrays are supported. For example, for "Holder<List<String>[][]", the
* returned value will be "List[][]".
*
* @param inputType
* @return A string representing the generic raw type or null if there is no generic.
*/
static String getRawType(String inputType) {
String returnRawType = null;
int leftBracket = inputType.indexOf("<");
int rightBracket = inputType.lastIndexOf(">");
if (leftBracket > 0 && rightBracket > 0 && rightBracket > leftBracket) {
String part1 = inputType.substring(0, leftBracket);
if ((rightBracket + 1) == inputType.length()) {
// There is nothing after the closing ">" we need to append to the raw type
returnRawType = part1;
} else {
// Skip over the closing ">" then append the rest of the string to the raw type
// This would be an array declaration for example.
String part2 = inputType.substring(rightBracket + 1).trim();
returnRawType = part1 + part2;
}
}
return returnRawType;
}
/**
* Return the actual type in a JAX-WS holder declaration. For example, for the argument
* "javax.xml.ws.Holder<my.package.MyObject>", return "my.package.MyObject". If the actual type
* itself is a generic, then that raw type will be returned. For example,
* "javax.xml.ws.Holder<java.util.List<my.package.MyObject>>" will return "java.util.List".
* <p/>
* Note that Holders of Arrays and of Generic Arrays are also supported. For example, for
* "javax.xml.ws.Holder<String[]>", return "String[]". For an array of a generic, the array of
* the raw type is returned. For example, for "javax.xml.ws.Holder<List<String>[][]>", return
* "List[][]".
* <p/>
* Important note! The JAX-WS Holder generic only supports a single actual type, i.e. the
* generic is javax.xml.ws.Holder<T>. This method is not general purpose; it does not support
* generics with multiple types such as Generic<K,V> at the outermost level.
*
* @param holderInputString
* @return return the actual argument class name for a JAX-WS Holder; returns null if the
* argument is not a JAX-WS Holder
*/
static String getHolderActualType(String holderInputString) {
String returnString = null;
if (DescriptionBuilderUtils.isHolderType(holderInputString)) {
int leftBracket = holderInputString.indexOf("<");
int rightBracket = holderInputString.lastIndexOf(">");
if (leftBracket > 0 && rightBracket > leftBracket + 1) {
// Get everything between the outermost "<" and ">"
String actualType =
holderInputString.substring(leftBracket + 1, rightBracket).trim();
// If the holder contained a generic, then get the generic raw type (e.g. "List" for
// Holder<List<String>>).
String rawType = getRawType(actualType);
if (rawType != null) {
returnString = rawType;
} else {
return returnString = actualType;
}
}
}
return returnString;
}
/**
* Check if the input String is a JAX-WS Holder. For example "javax.xml.ws.Holder<my.package.MyObject>".
*
* @param checkType
* @return true if it is a JAX-WS Holder type; false otherwise.
*/
static boolean isHolderType(String checkType) {
boolean isHolder = false;
if (checkType != null) {
if (checkType.startsWith(JAXWS_HOLDER_CLASS)) {
isHolder = checkType.length() == JAXWS_HOLDER_CLASS.length() ||
checkType.charAt(JAXWS_HOLDER_CLASS.length()) == '<';
}
}
return isHolder;
}
/**
* Answers if the String representing the class contains an array declaration. For example
* "Foo[][]" would return true, as would "int[]".
*
* @param className
* @return
*/
static boolean isClassAnArray(String className) {
if (className != null && className.indexOf("[") > 0) {
return true;
} else {
return false;
}
}
/**
* For an class name that is an array, return the non-array declaration portion. For example
* "my.package.Foo[][]" would return "my.package.Foo". Returns null if the argument does not
* contain an array declaration.
*
* @param fullClassName
* @return
*/
static String getBaseArrayClassName(String fullClassName) {
String baseArrayClassName = null;
if (fullClassName != null) {
int firstArrayDimension = fullClassName.indexOf("[");
if (firstArrayDimension > 0) {
baseArrayClassName = fullClassName.substring(0, firstArrayDimension);
}
}
return baseArrayClassName;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?