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.sunchenbin.store.feilong.core.bean.BeanUtil.java

/**
 * {@link BeanUtils#cloneBean(Object)}.//from  w  w w  .j  av  a  2 s  .  c o m
 * 
 * <p>
 * bean,???bean
 * <p>
 * 
 * <p>
 * {@link BeanUtils#cloneBean(Object)}??getPropertyUtils().copyProperties(newBean, bean);<br>
 * ?<b>? ,clone</b>
 * </p>
 * 
 * <p>
 * ???,????,?clone,,?,<br>
 * clone
 * </p>
 *
 * @param <T>
 *            the generic type
 * @param bean
 *            Bean to be cloned
 * @return the cloned bean
 *         (? ,clone)
 * @see org.apache.commons.beanutils.BeanUtils#cloneBean(Object)
 * @see org.apache.commons.beanutils.PropertyUtilsBean#copyProperties(Object, Object)
 */
@SuppressWarnings("unchecked")
public static <T> T cloneBean(T bean) {
    try {
        //Clone a bean based on the available property getters and setters, even if the bean class itself does not implement Cloneable.
        return (T) BeanUtils.cloneBean(bean);
    } catch (Exception e) {
        LOGGER.error(e.getClass().getName(), e);
        throw new BeanUtilException(e);
    }
}

From source file:com.amalto.core.objects.DroppedItemPOJO.java

/**
 * load a dropped item//from w  w  w  . ja v a  2 s. c  o m
 */
public static DroppedItemPOJO load(DroppedItemPOJOPK droppedItemPOJOPK) throws XtentisException {
    if (droppedItemPOJOPK == null) {
        return null;
    }
    ItemPOJOPK refItemPOJOPK = droppedItemPOJOPK.getRefItemPOJOPK();
    String actionName = "load"; //$NON-NLS-1$
    //for load we need to be admin, or have a role of admin , or role of write on instance or role of read on instance
    rolesFilter(refItemPOJOPK, actionName, "r"); //$NON-NLS-1$
    //get XmlServerSLWrapperLocal
    XmlServer server = Util.getXmlServerCtrlLocal();
    //load the dropped item
    try {
        //retrieve the dropped item
        String droppedItemStr = server.getDocumentAsString(MDM_ITEMS_TRASH, droppedItemPOJOPK.getUniquePK());
        if (droppedItemStr == null) {
            return null;
        }
        return MarshallingFactory.getInstance().getUnmarshaller(DroppedItemPOJO.class)
                .unmarshal(new StringReader(droppedItemStr));
    } catch (Exception e) {
        String err = "Unable to load the dropped item  " + droppedItemPOJOPK.getUniquePK() + ": "
                + e.getClass().getName() + ": " + e.getLocalizedMessage();
        LOGGER.error(err, e);
        throw new XtentisException(err, e);
    }
}

From source file:com.hemou.android.account.AccountUtils.java

/**
 * Is the given {@link Exception} due to a 401 Unauthorized API response?
 * //w  w w.ja v a2s  . com
 * @param e
 * @return true if 401, false otherwise
 */
public static boolean isUnauthorized(final Exception e) {
    Log.e(TAG, "Exception occured[" + Thread.currentThread().getId() + "]:{type:" + e.getClass().getName() + ","
            + e.getLocalizedMessage() + "}");
    String errorMess = e.getMessage();

    if (!StringUtils.isEmpty(errorMess) && (errorMess.contains("The authorization has expired")
            || errorMess.contains("401 Unauthorized") || errorMess.contains("403 Forbidden")))
        return true;

    if (e instanceof NotAuthorizedException) {
        Log.e(TAG, "?...");
        return true;
    }
    //      if (e instanceof ResourceAccessException)
    //         return true;
    if (e instanceof HttpClientErrorException) {
        HttpClientErrorException expt = (HttpClientErrorException) e;
        HttpStatus status = expt.getStatusCode();
        if (Arrays.asList(HttpStatus.UNAUTHORIZED, HttpStatus.NETWORK_AUTHENTICATION_REQUIRED,
                HttpStatus.NON_AUTHORITATIVE_INFORMATION, HttpStatus.PROXY_AUTHENTICATION_REQUIRED,
                //403??????
                HttpStatus.FORBIDDEN).contains(status))
            return true;
    }

    return false;
}

From source file:com.amalto.core.objects.DroppedItemPOJO.java

/**
 * remove a dropped item record//from w w w .  ja  va 2s  .c o  m
 */
public static DroppedItemPOJOPK remove(DroppedItemPOJOPK droppedItemPOJOPK) throws XtentisException {
    if (droppedItemPOJOPK == null) {
        return null;
    }
    ItemPOJOPK refItemPOJOPK = droppedItemPOJOPK.getRefItemPOJOPK();
    String actionName = "remove"; //$NON-NLS-1$
    //for remove we need to be admin, or have a role of admin , or role of write on instance
    rolesFilter(refItemPOJOPK, actionName, "w"); //$NON-NLS-1$
    //get XmlServerSLWrapperLocal
    XmlServer server = Util.getXmlServerCtrlLocal();
    try {
        //remove the record
        long res = server.deleteDocument(MDM_ITEMS_TRASH, droppedItemPOJOPK.getUniquePK());
        if (res == -1) {
            return null;
        }
        return droppedItemPOJOPK;
    } catch (Exception e) {
        String err = "Unable to " + actionName + " the dropped item " + droppedItemPOJOPK.getUniquePK() + ": "
                + e.getClass().getName() + ": " + e.getLocalizedMessage();
        LOGGER.error(err, e);
        throw new XtentisException(err, e);
    }
}

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

/**
 * ? {@code fromObj-->toObj}./*from  ww w  .j  a  v  a  2s .co  m*/
 * 
 * <h3>?:</h3> <blockquote>
 * <ol>
 * <li>?copy?,??2Bean???ref, ??, .</li>
 * <li> {@link BeanUtils#copyProperties(Object, Object)} ,Object--->String--->Object?,<br>
 * ?copy?,, {@link PropertyUtil#copyProperties(Object, Object, String...)}</li>
 * </ol>
 * </blockquote>
 * 
 * 
 * <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>
 * 
 * <p>
 *  {@link java.util.Date}  ?copy, ??:
 * </p>
 * 
 * <p>
 * DateConverter converter = new DateConverter(DatePattern.forToString, Locale.US);<br>
 * ConvertUtils.register(converter, Date.class);
 * </p>
 * 
 * :
 * <p>
 * ConvertUtils.register(new DateLocaleConverter(Locale.US, DatePattern.forToString), Date.class); <br>
 * BeanUtil.copyProperty(b, a, &quot;date&quot;);
 * </p>
 * 
 * </li>
 * </ol>
 * </blockquote>
 * 
 * 
 * <h3>:</h3>
 * 
 * <blockquote>
 * 
 * <pre>
 * pojo:enterpriseSalesenterpriseSales_form ?&quot;enterpriseName&quot;,&quot;linkMan&quot;,&quot;phone&quot;
 * 
 * 
 * enterpriseSales.setEnterpriseName(enterpriseSales_form.getEnterpriseName());
 * enterpriseSales.setLinkMan(enterpriseSales_form.getLinkMan());
 * enterpriseSales.setPhone(enterpriseSales_form.getPhone());
 * 
 * ,?
 * BeanUtil.copyProperties(enterpriseSales,enterpriseSales_form,new String[]{&quot;enterpriseName&quot;,&quot;linkMan&quot;,&quot;phone&quot;});
 * </pre>
 * 
 * </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 BeanUtils#copyProperties(Object, Object)}
 * @see #setProperty(Object, String, Object)
 * @see org.apache.commons.beanutils.BeanUtilsBean#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>
 */
//XXX add excludePropertyNames support
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 {
            BeanUtils.copyProperties(toObj, fromObj);
            return;
        } catch (Exception e) {
            LOGGER.error(e.getClass().getName(), e);
            throw new BeanUtilException(e);
        }
    }
    for (String propertyName : includePropertyNames) {
        String value = getProperty(fromObj, propertyName);
        setProperty(toObj, propertyName, value);
    }
}

From source file:de.tudarmstadt.lt.seg.app.Segmenter.java

public static void split_and_tokenize(Reader reader, String docid, ISentenceSplitter sentenceSplitter,
        ITokenizer tokenizer, int level_filter, int level_normalize, boolean merge_types, boolean merge_tokens,
        String separator_sentence, String separator_token, String separator_desc, PrintWriter writer) {
    try {/*from   w  w w.  j  a  v a  2 s  . co m*/
        final StringBuffer buf = new StringBuffer(); // used for checking of stream is empty; take care when not running sequentially but in parallel!
        sentenceSplitter.init(reader).stream().sequential().forEach(sentence_segment -> {
            if (DEBUG) {
                writer.format("%s%s", docid, separator_desc);
                writer.println(sentence_segment.toString());
                writer.print(separator_sentence);
            }
            if (sentence_segment.type != SegmentType.SENTENCE)
                return;
            tokenizer.init(sentence_segment.asString());
            Stream<String> tokens = null;
            if (DEBUG)
                tokens = tokenizer.stream().map(x -> x.toString() + separator_token);
            else
                tokens = StreamSupport.stream(tokenizer
                        .filteredAndNormalizedTokens(level_filter, level_normalize, merge_types, merge_tokens)
                        .spliterator(), false).map(x -> x + separator_token);
            Spliterator<String> spliterator = tokens.spliterator();
            tokens = StreamSupport.stream(spliterator, false);
            buf.setLength(0);
            boolean empty = !spliterator.tryAdvance(x -> {
                buf.append(x);
            });
            if (empty)
                return;
            synchronized (writer) {
                // writer.write(Thread.currentThread().getId() + "\t");
                writer.format("%s%s", docid, separator_desc);
                writer.print(buf);
                tokens.forEach(writer::print);
                writer.print(separator_sentence);
                writer.flush();
            }
        });
    } catch (Exception e) {
        Throwable t = e;
        while (t != null) {
            System.err.format("%s: %s%n", e.getClass(), e.getMessage());
            t = e.getCause();
        }
    }
}

From source file:com.twitter.distributedlog.DLMTestUtil.java

public static <T> T validateFutureSucceededAndGetResult(Future<T> future) throws Exception {
    try {/* w  ww  . jav  a 2  s.co m*/
        return Await.result(future, Duration.fromSeconds(10));
    } catch (Exception ex) {
        fail("unexpected exception " + ex.getClass().getName());
        throw ex;
    }
}

From source file:com.clustercontrol.accesscontrol.util.ClientSession.java

/**
 * Check//from   w  w w  . j  a  v  a 2 s . c o  m
 */
public static void doCheck() {
    m_log.trace("ClientSession.doCheck() start");

    // ?
    try {
        if (!LoginManager.isLogin()) {
            m_log.trace("ClientSession.doCheck() Not logged in yet. Skip.");
            return;
        }

        // ???
        for (EndpointUnit endpointUnit : EndpointManager.getAllManagerList()) {
            String managerName = endpointUnit.getManagerName();
            m_log.trace("ClientSession.doCheck() Get last updated time from Manager " + managerName);
            Date lastUpdateManager = null;
            if (endpointUnit.isActive()) {
                try {
                    RepositoryEndpointWrapper wrapper = RepositoryEndpointWrapper.getWrapper(managerName);
                    lastUpdateManager = new Date(wrapper.getLastUpdate());
                    m_log.trace("ClientSession.doCheck() lastUpdate(Manager) = " + lastUpdateManager);
                } catch (Exception e) {
                    // ???????
                    if (e instanceof ClientTransportException || e instanceof WebServiceException) {
                        m_log.warn("ClientSession.doCheck() Manager is dead ! , " + e.getClass().getName()
                                + ", " + e.getMessage());
                    } else {
                        // ?
                        m_log.warn("ClientSession.doCheck() Manager is dead !! , " + e.getClass().getName()
                                + ", " + e.getMessage(), e);
                    }
                    // ?
                    LoginManager.forceLogout(managerName);
                }
            }

            Date lastUpdateClient = FacilityTreeCache.getCacheDate(managerName);

            // ??????
            if (lastUpdateManager == lastUpdateClient)
                continue;

            boolean update = false;
            if (lastUpdateClient == null) {
                update = true;
            } else {
                update = !lastUpdateClient.equals(lastUpdateManager);
            }

            if (update) {
                m_log.debug("ClientSession.doCheck() lastUpdate(Manager)=" + lastUpdateManager
                        + ", lastUpdate(Client)=" + lastUpdateClient + ", " + managerName);
                // ????????
                FacilityTreeCache.refresh(managerName, lastUpdateManager);
            }
        }
    } catch (RuntimeException e) {
        m_log.warn("doCheck : " + e.getClass().getName() + ", message=" + e.getMessage(), e);
    }
}

From source file:Main.java

public static void openFeedback(Activity activity) {
    try {/* w w  w  . j a  va 2  s .  co m*/
        throw new Exception();
    } catch (Exception e) {
        ApplicationErrorReport report = new ApplicationErrorReport();
        report.packageName = report.processName = activity.getApplication().getPackageName();
        report.time = System.currentTimeMillis();
        report.type = ApplicationErrorReport.TYPE_CRASH;
        report.systemApp = false;
        ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo();
        crash.exceptionClassName = e.getClass().getSimpleName();
        crash.exceptionMessage = e.getMessage();
        StringWriter writer = new StringWriter();
        PrintWriter printer = new PrintWriter(writer);
        e.printStackTrace(printer);
        crash.stackTrace = writer.toString();
        StackTraceElement stack = e.getStackTrace()[0];
        crash.throwClassName = stack.getClassName();
        crash.throwFileName = stack.getFileName();
        crash.throwLineNumber = stack.getLineNumber();
        crash.throwMethodName = stack.getMethodName();
        report.crashInfo = crash;
        Intent intent = new Intent(Intent.ACTION_APP_ERROR);
        intent.putExtra(Intent.EXTRA_BUG_REPORT, report);
        activity.startActivity(intent);
    }
}

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

/**
 * ?.//from   w  w w .j  a v a  2s  .c o  m
 *
 * @param <T>
 *            the generic type
 * @param owner
 *            the owner
 * @param fieldName
 *            the field name
 * @return 
 * @see java.lang.Object#getClass()
 * @see java.lang.Class#getField(String)
 * @see java.lang.reflect.Field#get(Object)
 * @since 1.4.0
 */
@SuppressWarnings("unchecked")
public static <T> T getFieldValue(Object owner, String fieldName) {
    try {
        Class<?> ownerClass = owner.getClass();
        Field field = ownerClass.getField(fieldName);
        return (T) field.get(owner);
    } catch (Exception e) {
        String formatMessage = Slf4jUtil.formatMessage("owner:[{}],fieldName:[{}]", owner, fieldName);
        LOGGER.error(formatMessage + e.getClass().getName(), e);
        throw new ReflectException(formatMessage, e);
    }
}