Example usage for java.lang Exception getClass

List of usage examples for java.lang Exception getClass

Introduction

In this page you can find the example usage for java.lang Exception getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.feilong.commons.core.lang.reflect.FieldUtil.java

/**
 * ?.//from   w  ww . j  a va 2s .  c  o m
 * 
 * @param <T>
 *            the generic type
 * @param owner
 *            the owner
 * @param fieldName
 *            the field name
 * @return 
 * @throws ReflectException
 *             the reflect exception
 * 
 * @see java.lang.Object#getClass()
 * @see java.lang.Class#getField(String)
 * @see java.lang.reflect.Field#get(Object)
 */
@SuppressWarnings("unchecked")
public static <T> T getProperty(Object owner, String fieldName) throws ReflectException {
    try {
        Class<?> ownerClass = owner.getClass();
        Field field = ownerClass.getField(fieldName);
        Object property = field.get(owner);
        return (T) property;
    } catch (Exception e) {
        log.error(e.getClass().getName(), e);
        throw new ReflectException(e);
    }
}

From source file:com.feilong.commons.core.lang.reflect.FieldUtil.java

/**
 * ???.//from   w w w . j  a va2  s .  co  m
 * 
 * <pre>
 * {@code
 * example1 :
 *  IOConstants GB??
 * FieldUtil.getStaticProperty("com.feilong.commons.core.io.IOConstants", "GB")
 *  :1073741824
 * }
 * </pre>
 * 
 * @param <T>
 *            the generic type
 * @param className
 *            ??
 * @param fieldName
 *            ??
 * @return 
 * @throws ReflectException
 *             the reflect exception
 * @see com.feilong.commons.core.lang.ClassUtil#loadClass(String)
 * @see java.lang.Class#getField(String)
 * @see java.lang.reflect.Field#get(Object)
 */
@SuppressWarnings("unchecked")
public static <T> T getStaticProperty(String className, String fieldName) throws ReflectException {
    try {
        Class<?> ownerClass = ClassUtil.loadClass(className);
        Field field = ownerClass.getField(fieldName);
        Object property = field.get(ownerClass);
        return (T) property;
    } catch (Exception e) {
        log.error(e.getClass().getName(), e);
        throw new ReflectException(e);
    }
}

From source file:com.sunchenbin.store.feilong.core.bean.PropertyUtil.java

/**
 *  {@link PropertyUtils#setProperty(Object, String, Object)} ?(<b>??</b>).
 *
 * @param bean/*from ww  w. ja  v a  2  s . c om*/
 *            Bean whose property is to be modified
 * @param propertyName
 *            Possibly indexed and/or nested name of the property to be modified
 * @param value
 *            Value to which this property is to be set
 * @see org.apache.commons.beanutils.BeanUtils#setProperty(Object, String, Object)
 * @see org.apache.commons.beanutils.PropertyUtils#setProperty(Object, String, Object)
 * @see com.sunchenbin.store.feilong.core.bean.BeanUtil#setProperty(Object, String, Object)
 */
public static void setProperty(Object bean, String propertyName, Object value) {
    try {
        //Set the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.
        // PropertyUtilsBeanUtils,?????
        PropertyUtils.setProperty(bean, propertyName, value);
    } catch (Exception e) {
        LOGGER.error(e.getClass().getName(), e);
        throw new BeanUtilException(e);
    }
}

From source file:com.sunchenbin.store.feilong.core.bean.PropertyUtil.java

/**
 *  {@link PropertyUtils#getProperty(Object, String)} ?.
 *
 * @param <T>// www .j a va2s  .co m
 *            the generic type
 * @param bean
 *            Bean whose property is to be extracted
 * @param propertyName
 *            Possibly indexed and/or nested name of the property to be extracted
 * @return {@link PropertyUtils#getProperty(Object, String)} ?
 * @see com.sunchenbin.store.feilong.core.bean.BeanUtil#getProperty(Object, String)
 * @see org.apache.commons.beanutils.BeanUtils#getProperty(Object, String)
 * @see org.apache.commons.beanutils.PropertyUtils#getProperty(Object, String)
 * @see org.apache.commons.beanutils.PropertyUtilsBean
 */
@SuppressWarnings("unchecked")
public static <T> T getProperty(Object bean, String propertyName) {
    //Return the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.
    //For more details see PropertyUtilsBean.
    try {
        return (T) PropertyUtils.getProperty(bean, propertyName);
    } catch (Exception e) {
        LOGGER.error(e.getClass().getName(), e);
        throw new BeanUtilException(e);
    }
}

From source file:com.bahmanm.karun.Utils.java

/**
 * Pops up a dialog containing useful information from exception such as
 * stack trace./*from ww w .j  a  va 2 s .com*/
 * 
 * @param parent Parent component
 * @param ex Exception
 */
public static void showExceptionDialog(Frame parent, Exception ex) {
    String topic = "";
    if (ex instanceof IOException)
        topic = "An I/O error occured.";
    else
        topic = "An error occured.";
    topic += "  [" + ex.getClass().getName() + "]";
    if (ex.getMessage() != null)
        topic += "\n" + ex.getMessage();

    StackTraceElement[] stackTrace = ex.getStackTrace();
    String stacktraceStr = "";
    for (int i = 0; i < stackTrace.length; i++)
        stacktraceStr += stackTrace[i] + "\n";

    ExceptionDialog edialog = new ExceptionDialog(parent, true, topic, stacktraceStr);
    edialog.setVisible(true);
}

From source file:com.tealium.publisher.ftp.FtpSession.java

public static Error getError(Exception e) {
    if (e.getClass().isAssignableFrom(IllegalStateException.class)) {
        return Error.IllegalState;
    }//  w  ww . j  a v  a 2s.com

    if (e.getClass().isAssignableFrom(IOException.class)) {
        return Error.IOException;
    }

    if (e.getClass().isAssignableFrom(FTPIllegalReplyException.class)) {
        return Error.IllegalReply;
    }

    if (e.getClass().isAssignableFrom(FTPException.class)) {
        return Error.FTPGeneric;
    }

    if (e.getClass().isAssignableFrom(FTPDataTransferException.class)) {
        return Error.DataTransfer;
    }

    if (e.getClass().isAssignableFrom(FTPAbortedException.class)) {
        return Error.Aborted;
    }

    if (e.getClass().isAssignableFrom(FTPListParseException.class)) {
        return Error.ListParse;
    }
    if (e.getClass().isAssignableFrom(FileNotFoundException.class)) {
        return Error.FileNotFound;
    }

    return Error.Unknown;

}

From source file:com.sunchenbin.store.feilong.core.bean.PropertyUtil.java

/**
 * ? {@code fromObj-->toObj}.//w w w  .  ja va 2  s. com
 * 
 * <p>
 * ?:?copy?,??2Bean???ref, ??, .
 * </p>
 * 
 * <h3>?:</h3>
 * 
 * <blockquote>
 * 
 * <ol>
 * <li>includePropertyNames,? <code>fromObj</code>??,</li>
 * <li>includePropertyNames,? <code>fromObj</code>, <code>toObj</code>??,??,see
 * {@link org.apache.commons.beanutils.BeanUtilsBean#copyProperty(Object, String, Object)} Line391</li>
 * <li>Date,??converter</li>
 * </ol>
 * </blockquote>
 * 
 * 
 * <h3>:</h3>
 * 
 * <blockquote>
 * 
 * <code>
 * <pre>
User oldUser = new User();
oldUser.setId(5L);
oldUser.setMoney(new BigDecimal(500000));
oldUser.setDate(new Date());
String[] nickName = { "feilong", "", "venusdrogon" };
oldUser.setNickName(nickName);
        
User newUser = new User();
        
String[] strs = { "date", "money", "nickName" };
PropertyUtil.copyProperties(newUser, oldUser, strs);
LOGGER.info(JsonUtil.format(newUser));s(enterpriseSales,enterpriseSales_form,new String[]{&quot;enterpriseName&quot;,&quot;linkMan&quot;,&quot;phone&quot;});
 *
 * 
 *  :
 * 
 * {
"userAddresseList": [],
"userAddresses": [],
"date": "2015-09-06 13:27:43",
"password": "",
"id": 0,
"nickName":         [
    "feilong",
    "",
    "venusdrogon"
],
"age": 0,
"name": "feilong",
"money": 500000,
"attrMap": null,
"userInfo": {"age": 0},
"loves": []
}
 * 
 * </pre>
 * </code>
 * 
 * </blockquote>
 * 
 * 
 * <h3>{@link BeanUtils#copyProperties(Object, Object)} {@link PropertyUtils#copyProperties(Object, Object)}</h3>
 * 
 * <blockquote>
 * <ul>
 * <li>{@link BeanUtils#copyProperties(Object, Object)}??????,????</li>
 * <li>{@link PropertyUtils#copyProperties(Object, Object)} ???,??JavaBean?????,???,???,.</li>
 * <li>commons-beanutils v1.9.0? BeanUtils?? null,PropertyUtils?? null.<br>
 * (<b>:</b>commons-beanutils v1.9.0+?,BeanUtilsBean.copyProperties() no longer throws a ConversionException for null properties
 * of certain data types),?,??commons-beanutils
 * {@link <a href="http://commons.apache.org/proper/commons-beanutils/javadocs/v1.9.2/RELEASE-NOTES.txt">RELEASE-NOTES.txt</a>}</li>
 * </ul>
 * </blockquote>
 *
 * @param toObj
 *            
 * @param fromObj
 *            
 * @param includePropertyNames
 *            ???,(can be nested/indexed/mapped/combo)<br>
 *             null or empty , {@link PropertyUtils#copyProperties(Object, Object)}
 * @see #setProperty(Object, String, Object)
 * 
 * @see com.sunchenbin.store.feilong.core.bean.BeanUtil#copyProperties(Object, Object, String...)
 * 
 * @see org.apache.commons.beanutils.PropertyUtilsBean#copyProperties(Object, Object)
 * @see <a href="http://www.cnblogs.com/kaka/archive/2013/03/06/2945514.html">Bean??(Apache BeanUtils?PropertyUtils,Spring
 *      BeanUtils,Cglib BeanCopier)</a>
 * @since 1.4.1
 */
public static void copyProperties(Object toObj, Object fromObj, String... includePropertyNames) {
    if (null == toObj) {
        throw new NullPointerException("No destination bean/toObj specified");
    }
    if (null == fromObj) {
        throw new NullPointerException("No origin bean/fromObj specified");
    }

    if (Validator.isNullOrEmpty(includePropertyNames)) {
        try {
            PropertyUtils.copyProperties(toObj, fromObj);
            return;
        } catch (Exception e) {
            LOGGER.error(e.getClass().getName(), e);
            throw new BeanUtilException(e);
        }
    }
    for (String propertyName : includePropertyNames) {
        Object value = getProperty(fromObj, propertyName);
        setProperty(toObj, propertyName, value);
    }
}

From source file:com.ikon.extractor.RegisteredExtractors.java

/**
 * EXPERIMENTAL/* ww  w  .j a  va  2 s .co m*/
 */
public static void index(javax.jcr.Node docNode, javax.jcr.Node contNode, String mimeType)
        throws javax.jcr.ValueFormatException, javax.jcr.PathNotFoundException, javax.jcr.RepositoryException,
        IOException {
    InputStream in = null;
    String text = null;

    try {
        in = contNode.getProperty(JcrConstants.JCR_DATA).getStream();
        text = getJcrText(docNode, mimeType, "UTF-8", in);

        try {
            contNode.setProperty(Document.TEXT, text);
        } catch (Exception e) {
            log.warn("Text extraction failure - {}: {}", e.getClass().getName(), e.getMessage());
        }
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:org.addhen.smssync.net.BaseHttpClient.java

private static void debug(Exception e) {
    Logger.log(CLASS_TAG, "Exception: " + e.getClass().getName() + " " + getRootCause(e).getMessage());
}

From source file:com.feilong.commons.core.lang.reflect.FieldUtil.java

/**
 *  (?),key fieldNamevalue .// ww  w  .  j  a  v  a 2  s .co m
 *
 * @param obj
 *            the obj
 * @param excludeFieldNames
 *            ?field names,?nullOrEmpty ?
 * @return the field value map
 * @throws ReflectException
 *             the reflect exception
 */
public static Map<String, Object> getFieldValueMap(Object obj, String[] excludeFieldNames)
        throws ReflectException {

    // (?,)
    Field[] fields = getDeclaredFields(obj);

    Map<String, Object> map = new TreeMap<String, Object>();
    if (Validator.isNotNullOrEmpty(fields)) {
        for (Field field : fields) {
            String fieldName = field.getName();

            if (Validator.isNotNullOrEmpty(excludeFieldNames)
                    && ArrayUtil.isContain(excludeFieldNames, fieldName)) {
                continue;
            }

            int modifiers = field.getModifiers();
            // ??? log
            boolean isPrivateAndStatic = Modifier.isPrivate(modifiers) && Modifier.isStatic(modifiers);
            log.debug("field name:[{}],modifiers:[{}],isPrivateAndStatic:[{}]", fieldName, modifiers,
                    isPrivateAndStatic);

            if (!isPrivateAndStatic) {
                //TODO see org.apache.commons.lang3.reflect.MemberUtils.setAccessibleWorkaround(AccessibleObject)
                field.setAccessible(true);
                try {
                    map.put(fieldName, field.get(obj));
                } catch (Exception e) {
                    log.error(e.getClass().getName(), e);
                    throw new ReflectException(e);
                }
            }
        }
    }
    return map;
}