Java Code Examples for org.apache.commons.lang3.ClassUtils#getShortClassName()

The following examples show how to use org.apache.commons.lang3.ClassUtils#getShortClassName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExceptionUtil.java    From vjtools with Apache License 2.0 6 votes vote down vote up
/**
 * 拼装 短异常类名: 异常信息 <-- RootCause的短异常类名: 异常信息
 */
public static String toStringWithRootCause(@Nullable Throwable t) {
	if (t == null) {
		return StringUtils.EMPTY;
	}

	final String clsName = ClassUtils.getShortClassName(t, null);
	final String message = StringUtils.defaultString(t.getMessage());
	Throwable cause = getRootCause(t);

	StringBuilder sb = new StringBuilder(128).append(clsName).append(": ").append(message);
	if (cause != t) {
		sb.append("; <---").append(toStringWithShortName(cause));
	}

	return sb.toString();
}
 
Example 2
Source File: ExceptionUtil.java    From j360-dubbo-app-all with Apache License 2.0 6 votes vote down vote up
/**
 * 拼装 短异常类名: 异常信息 <-- RootCause的短异常类名: 异常信息
 */
public static String toStringWithRootCause(@Nullable Throwable t) {
	if (t == null) {
		return StringUtils.EMPTY;
	}

	final String clsName = ClassUtils.getShortClassName(t, null);
	final String message = StringUtils.defaultString(t.getMessage());
	Throwable cause = getRootCause(t);

	StringBuilder sb = new StringBuilder(128).append(clsName).append(": ").append(message);
	if (cause != t) {
		sb.append("; <---").append(toStringWithShortName(cause));
	}

	return sb.toString();
}
 
Example 3
Source File: ThrowableUtils.java    From kafka-message-tool with MIT License 5 votes vote down vote up
public static String getMessage(Throwable e) {

        String msg = getRootCauseMessage(e);
        if (StringUtils.isBlank(msg)) {
            msg = ClassUtils.getShortClassName(e.getClass());
        }
        return msg;
    }
 
Example 4
Source File: ReflectionUtils.java    From poi-tl with Apache License 2.0 5 votes vote down vote up
public static Object getValue(String fieldName, Object obj) {
    Objects.requireNonNull(obj, "Class must not be null");
    Objects.requireNonNull(fieldName, "Name must not be null");
    Field field = findField(obj.getClass(), fieldName);
    if (null == field) {
        throw new ReflectionException(
                "No Such field " + fieldName + " from class" + ClassUtils.getShortClassName(obj.getClass()));
    }
    try {
        field.setAccessible(true);
        return field.get(obj);
    } catch (Exception e) {
        throw new ReflectionException(fieldName, obj.getClass(), e);
    }
}
 
Example 5
Source File: SimpleSinglePortInputOperator.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Override
public final void activate(OperatorContext ctx)
{
  isActive = true;
  if (this instanceof Runnable) {
    ioThread = new Thread((Runnable)this, "io-" + ClassUtils.getShortClassName(this.getClass()));
    ioThread.start();
  }
}
 
Example 6
Source File: ReflectionException.java    From poi-tl with Apache License 2.0 4 votes vote down vote up
public ReflectionException(String name, Class<?> clazz, Exception e) {
    this("Error Reflect " + name + "from class " + ClassUtils.getShortClassName(clazz), e);
}
 
Example 7
Source File: ExceptionUtils.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Gets a short message summarising the exception.
 * <p>
 * The message returned is of the form
 * {ClassNameWithoutPackage}: {ThrowableMessage}
 *
 * @param th  the throwable to get a message for, null returns empty string
 * @return the message, non-null
 * @since Commons Lang 2.2
 */
public static String getMessage(final Throwable th) {
    if (th == null) {
        return "";
    }
    final String clsName = ClassUtils.getShortClassName(th, null);
    final String msg = th.getMessage();
    return clsName + ": " + StringUtils.defaultString(msg);
}
 
Example 8
Source File: ExceptionUtils.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Gets a short message summarising the exception.
 * <p>
 * The message returned is of the form
 * {ClassNameWithoutPackage}: {ThrowableMessage}
 *
 * @param th  the throwable to get a message for, null returns empty string
 * @return the message, non-null
 * @since Commons Lang 2.2
 */
public static String getMessage(Throwable th) {
    if (th == null) {
        return "";
    }
    String clsName = ClassUtils.getShortClassName(th, null);
    String msg = th.getMessage();
    return clsName + ": " + StringUtils.defaultString(msg);
}
 
Example 9
Source File: ExceptionUtils.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Gets a short message summarising the exception.
 * <p>
 * The message returned is of the form
 * {ClassNameWithoutPackage}: {ThrowableMessage}
 *
 * @param th  the throwable to get a message for, null returns empty string
 * @return the message, non-null
 * @since Commons Lang 2.2
 */
public static String getMessage(Throwable th) {
    if (th == null) {
        return "";
    }
    String clsName = ClassUtils.getShortClassName(th, null);
    String msg = th.getMessage();
    return clsName + ": " + StringUtils.defaultString(msg);
}
 
Example 10
Source File: ExceptionUtils.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Gets a short message summarising the exception.
 * <p>
 * The message returned is of the form
 * {ClassNameWithoutPackage}: {ThrowableMessage}
 *
 * @param th  the throwable to get a message for, null returns empty string
 * @return the message, non-null
 * @since Commons Lang 2.2
 */
public static String getMessage(Throwable th) {
    if (th == null) {
        return "";
    }
    String clsName = ClassUtils.getShortClassName(th, null);
    String msg = th.getMessage();
    return clsName + ": " + StringUtils.defaultString(msg);
}
 
Example 11
Source File: ExceptionUtils.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Gets a short message summarising the exception.
 * <p>
 * The message returned is of the form
 * {ClassNameWithoutPackage}: {ThrowableMessage}
 *
 * @param th  the throwable to get a message for, null returns empty string
 * @return the message, non-null
 * @since Commons Lang 2.2
 */
public static String getMessage(Throwable th) {
    if (th == null) {
        return "";
    }
    String clsName = ClassUtils.getShortClassName(th, null);
    String msg = th.getMessage();
    return clsName + ": " + StringUtils.defaultString(msg);
}
 
Example 12
Source File: ToStringStyle.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * <p>Gets the short class name for a class.</p>
 *
 * <p>The short class name is the classname excluding
 * the package name.</p>
 *
 * @param cls  the <code>Class</code> to get the short name of
 * @return the short name
 */
protected String getShortClassName(Class<?> cls) {
    return ClassUtils.getShortClassName(cls);
}
 
Example 13
Source File: ToStringStyle.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * <p>Gets the short class name for a class.</p>
 *
 * <p>The short class name is the classname excluding
 * the package name.</p>
 *
 * @param cls  the <code>Class</code> to get the short name of
 * @return the short name
 */
protected String getShortClassName(Class<?> cls) {
    return ClassUtils.getShortClassName(cls);
}
 
Example 14
Source File: Lang_34_ToStringStyle_t.java    From coming with MIT License 2 votes vote down vote up
/**
 * <p>Gets the short class name for a class.</p>
 *
 * <p>The short class name is the classname excluding
 * the package name.</p>
 *
 * @param cls  the <code>Class</code> to get the short name of
 * @return the short name
 */
protected String getShortClassName(Class<?> cls) {
    return ClassUtils.getShortClassName(cls);
}
 
Example 15
Source File: Lang_34_ToStringStyle_s.java    From coming with MIT License 2 votes vote down vote up
/**
 * <p>Gets the short class name for a class.</p>
 *
 * <p>The short class name is the classname excluding
 * the package name.</p>
 *
 * @param cls  the <code>Class</code> to get the short name of
 * @return the short name
 */
protected String getShortClassName(Class<?> cls) {
    return ClassUtils.getShortClassName(cls);
}
 
Example 16
Source File: ClassUtil.java    From j360-dubbo-app-all with Apache License 2.0 2 votes vote down vote up
/**
 * 返回Class名,不包含PackageName
 * 
 * 内部类的话,返回"主类.内部类"
 */
public static String getShortClassName(final String className) {
	return ClassUtils.getShortClassName(className);
}
 
Example 17
Source File: ClassUtil.java    From j360-dubbo-app-all with Apache License 2.0 2 votes vote down vote up
/**
 * 返回Class名, 不包含PackageName.
 * 
 * 内部类的话,返回"主类.内部类"
 */
public static String getShortClassName(final Class<?> cls) {
	return ClassUtils.getShortClassName(cls);
}
 
Example 18
Source File: ToStringStyle.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * <p>Gets the short class name for a class.</p>
 *
 * <p>The short class name is the classname excluding
 * the package name.</p>
 *
 * @param cls  the <code>Class</code> to get the short name of
 * @return the short name
 */
protected String getShortClassName(final Class<?> cls) {
    return ClassUtils.getShortClassName(cls);
}
 
Example 19
Source File: ClassUtil.java    From vjtools with Apache License 2.0 2 votes vote down vote up
/**
 * 返回Class名,不包含PackageName
 * 
 * 内部类的话,返回"主类.内部类"
 */
public static String getShortClassName(final String className) {
	return ClassUtils.getShortClassName(className);
}
 
Example 20
Source File: ClassUtil.java    From vjtools with Apache License 2.0 2 votes vote down vote up
/**
 * 返回短Class名, 不包含PackageName.
 * 
 * 内部类的话,返回"主类.内部类"
 */
public static String getShortClassName(final Class<?> cls) {
	return ClassUtils.getShortClassName(cls);
}