List of usage examples for java.lang Exception getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.bigstep.datalake.JsonUtil.java
/** * Convert an exception object to a Json string. * @param e the exception//from w ww . j a v a 2 s.co m * @return the json string */ public static String toJsonString(final Exception e) { final Map<String, Object> m = new TreeMap<String, Object>(); m.put("exception", e.getClass().getSimpleName()); m.put("message", e.getMessage()); m.put("javaClassName", e.getClass().getName()); return toJsonString(RemoteException.class, m); }
From source file:com.feilong.core.bean.BeanUtil.java
/** * {@link BeanUtils#setProperty(Object, String, Object)} ?(<b>?</b>). * // ww w . j av a 2 s.co m * <p> * BeanUtils??,???(?) * </p> * * @param bean * Bean on which setting is to be performed * @param propertyName * Property name (can be nested/indexed/mapped/combo),??<a href="#propertyName">propertyName</a> * @param value * Value to be set * @throws BeanUtilException * ,?{@link BeanUtilException} * @see org.apache.commons.beanutils.BeanUtils#setProperty(Object, String, Object) * @see org.apache.commons.beanutils.BeanUtilsBean#setProperty(Object, String, Object) * @see org.apache.commons.beanutils.PropertyUtils#setProperty(Object, String, Object) * @see com.feilong.core.bean.PropertyUtil#setProperty(Object, String, Object) */ public static void setProperty(Object bean, String propertyName, Object value) { try { BeanUtils.setProperty(bean, propertyName, value); } catch (Exception e) { LOGGER.error(e.getClass().getName(), e); throw new BeanUtilException(e); } }
From source file:com.feilong.core.bean.BeanUtil.java
/** * {@link BeanUtils#getProperty(Object, String)} ?,?care,? {@link String}. * * @param bean/*from ww w .j a v a2 s .c o m*/ * bean * @param propertyName * ?? (can be nested/indexed/mapped/combo),?? <a href="#propertyName">propertyName</a> * @return {@link BeanUtils#getProperty(Object, String)} ? * @throws NullPointerException * <code>bean</code> null, <code>propertyName</code> null * @throws IllegalArgumentException * <code>propertyName</code> blank * @throws BeanUtilException * {@link BeanUtils#getProperty(Object, String)},?{@link BeanUtilException} * @see org.apache.commons.beanutils.BeanUtils#getProperty(Object, String) * @see org.apache.commons.beanutils.PropertyUtils#getProperty(Object, String) * @see com.feilong.core.bean.PropertyUtil#getProperty(Object, String) */ public static String getProperty(Object bean, String propertyName) { Validate.notNull(bean, "bean can't be null!"); Validate.notBlank(propertyName, "propertyName can't be blank!"); try { return BeanUtils.getProperty(bean, propertyName); } catch (Exception e) { LOGGER.error(e.getClass().getName(), e); throw new BeanUtilException(e); } }
From source file:com.feilong.core.bean.BeanUtil.java
/** * {@link BeanUtils#cloneBean(Object)}./*from w w w . j av a 2 s.c o m*/ * * <p> * bean,???bean,?bean {@link Cloneable}? . * </p> * * <h3>?:</h3> * <blockquote> * * <ol> * <li>clone</li> * <li>?? <b>getPropertyUtils().copyProperties(newBean, bean)</b>;?<b>?,clone</b><br> * ???,???(?),?clone,,? * </li> * <li> {@link java.lang.Class#newInstance() Class.newInstance()}?,?clone<b>?</b>,? * {@link java.lang.InstantiationException InstantiationException}</li> * <li>?clone list,empty list,?? * <a href="https://issues.apache.org/jira/browse/BEANUTILS-471">BeanUtils.cloneBean with List is broken</a></li> * </ol> * </blockquote> * * <h3>clone:</h3> * * <blockquote> * <p> * ?clone,? {@link org.apache.commons.lang3.SerializationUtils#clone(java.io.Serializable) SerializationUtils.clone},?? * </p> * </blockquote> * * @param <T> * the generic type * @param bean * Bean to be cloned * @return the cloned bean (? ,clone) * @throws NullPointerException * <code>bean</code> null * @throws BeanUtilException * api,?{@link BeanUtilException} * @see org.apache.commons.beanutils.BeanUtils#cloneBean(Object) * @see org.apache.commons.beanutils.PropertyUtilsBean#copyProperties(Object, Object) * @see org.apache.commons.lang3.SerializationUtils#clone(java.io.Serializable) * @see org.apache.commons.lang3.ObjectUtils#clone(Object) * @see org.apache.commons.lang3.ObjectUtils#cloneIfPossible(Object) */ @SuppressWarnings("unchecked") public static <T> T cloneBean(T bean) { Validate.notNull(bean, "bean can't be null!"); try { return (T) BeanUtils.cloneBean(bean); } catch (Exception e) { LOGGER.error(e.getClass().getName(), e); throw new BeanUtilException(e); } }
From source file:com.feilong.core.bean.BeanUtil.java
/** * <code class="code">fromObj</code>,? <code>toObj</code>. * //from ww w . j a v a2 s. c om * <h3>?:</h3> * * <blockquote> * <ol> * <li>?copy <span style="color:red">?</span>,??2Bean???ref,??, .</li> * <li> {@link BeanUtils#copyProperties(Object, Object)},{@code Object--->String--->Object}?,<br> * ?copy?,<span style="color:red"></span>, * {@link PropertyUtil#copyProperties(Object, Object, String...)}</li> * </ol> * </blockquote> * * <h3>??:</h3> * <blockquote> * <p> * <code>includePropertyNames</code>?, {@link BeanUtils#copyProperties(Object, Object)}<br> * ?{@link #getProperty(Object, String)} ?{@link #setProperty(Object, String, Object)} <code>toObj</code> * </p> * </blockquote> * * <h3>?:</h3> * * <blockquote> * * <ol> * <li><code>includePropertyNames</code>,? <code>fromObj</code>??,</li> * <li><code>includePropertyNames</code>,? <code>fromObj</code>, <code>toObj</code>??,??,see * {@link BeanUtilsBean#copyProperty(Object, String, Object)} Line391</li> * </ol> * </blockquote> * * * <h3>:</h3> * * <blockquote> * * <pre class="code"> * pojo: useruserForm ?"enterpriseName","linkMan","phone" * * : * ..... * user.setEnterpriseName(userForm.getEnterpriseName()); * user.setLinkMan(userForm.getLinkMan()); * user.setPhone(userForm.getPhone()); * ...... * * ,? * BeanUtil.copyProperties(user,userForm,"enterpriseName","linkMan","phone"); * </pre> * * </blockquote> * * * <h3> {@link Converter}:</h3> * * <blockquote> * <p> * {@link java.util.Date} ?copy,?? {@link #register(Converter, Class)}:<br> * * <code>BeanUtil.register(new DateLocaleConverter(Locale.US, DatePattern.TO_STRING_STYLE),Date.class);</code> * * <br> * ,?? {@link #register(Converter, Class)} * </p> * </blockquote> * * * <h3>{@link BeanUtils#copyProperties(Object, Object)} {@link PropertyUtils#copyProperties(Object, Object)}</h3> * * <blockquote> * <ul> * <li>{@link BeanUtils#copyProperties(Object, Object)} ???,??JavaBean?????,???, * {@link PropertyUtils#copyProperties(Object, Object)}??,.</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 * <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> * nullempty , {@link BeanUtils#copyProperties(Object, Object)} * @throws NullPointerException * <code>toObj</code> null, <code>fromObj</code> null * @throws BeanUtilException * api,?{@link BeanUtilException} * @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) { Validate.notNull(toObj, "toObj [destination bean] not specified!"); Validate.notNull(fromObj, "fromObj [origin bean] not specified!"); if (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:com.haoqee.chatsdk.net.Utility.java
/** * Implement a weibo http request and return results . * /* w w w . j av a 2 s .co m*/ * @param context * : context of activity * @param url * : request url of open api * @param method * : HTTP METHOD.GET, POST, DELETE * @param params * : Http params , query or postparameters * @param Token * : oauth token or accesstoken * @return UrlEncodedFormEntity: encoed entity * @throws ConnectTimeoutException * @throws UnresolvedAddressException * @throws SocketTimeoutException * @throws UnknownHostException */ public static String openUrl(String url, String method, BaseParameters params, int loginType, TCBaseListener listener) throws HaoqeeChatException { if (loginType == 1) { if (!TextUtils.isEmpty(TCChatManager.getInstance().getLoginUid())) { params.add("uid", TCChatManager.getInstance().getLoginUid()); } else { TCError error = new TCError(); error.errorMessage = TCChatManager.getInstance().getContext().getString(R.string.please_login); if (listener != null) { listener.onError(error); } return ""; } } else if (loginType == 2) { if (!TextUtils.isEmpty(TCChatManager.getInstance().getLoginUid())) { params.add("uid", TCChatManager.getInstance().getLoginUid()); } } params.add("device", "android"); String rlt = ""; List<TCMorePicture> fileList = null; for (int loc = 0; loc < params.size(); loc++) { String key = params.getKey(loc); if (key.equals("fileList")) { fileList = params.getFileList(key); params.remove(key); } } if (url.endsWith("/message/api/sendMessage") && Integer.parseInt(params.getValue("typefile")) == TCMessageType.FILE) { File file = new File(fileList.get(0).filePath); FormFile formfile = new FormFile(file.getName(), file, fileList.get(0).key, "application/octet-stream"); try { rlt = SocketHttpRequester.post(TCChatManager.getInstance().getContext(), url, params, formfile, listener); } catch (Exception e) { if (e.getClass().toString() .equalsIgnoreCase("class java.nio.channels.UnresolvedAddressException")) { throw new HaoqeeChatException("UnresolvedAddress", e, R.string.unknown_addr); } else if (e.getClass().toString().equalsIgnoreCase("class java.net.UnknownHostException")) { throw new HaoqeeChatException("UnknownHost", e, R.string.error_host); } else if (e.getClass().toString() .equalsIgnoreCase("class org.apache.http.conn.ConnectTimeoutException")) { throw new HaoqeeChatException("ConnectionTimeout", e, R.string.timeout); } else if (e.getClass().toString().equalsIgnoreCase("class java.net.SocketTimeoutException")) { throw new HaoqeeChatException("SocketTimeout", e, R.string.timeout); } e.printStackTrace(); } } else { rlt = openUrl(url, method, params, fileList, listener); } return rlt; }
From source file:com.amalto.core.objects.DroppedItemPOJO.java
/** * recover dropped item/*from www . ja v a2 s. c o m*/ */ public static ItemPOJOPK recover(DroppedItemPOJOPK droppedItemPOJOPK) throws XtentisException { // validate input if (droppedItemPOJOPK == null) { return null; } String partPath = droppedItemPOJOPK.getPartPath(); if (partPath == null || partPath.length() == 0) { return null; } if (!"/".equals(partPath)) { //$NON-NLS-1$ throw new IllegalArgumentException("Path '" + partPath + "' is not valid."); } ItemPOJOPK refItemPOJOPK = droppedItemPOJOPK.getRefItemPOJOPK(); String actionName = "recover"; //$NON-NLS-1$ // for recover 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 the universe and revision ID XmlServer server = Util.getXmlServerCtrlLocal(); try { // load dropped content String doc = server.getDocumentAsString(MDM_ITEMS_TRASH, droppedItemPOJOPK.getUniquePK(), null); if (doc == null) { return null; } // recover source item DroppedItemPOJO droppedItemPOJO = MarshallingFactory.getInstance() .getUnmarshaller(DroppedItemPOJO.class).unmarshal(new StringReader(doc)); String clusterName = refItemPOJOPK.getDataClusterPOJOPK().getUniqueId(); server.start(clusterName); try { server.putDocumentFromString(droppedItemPOJO.getProjection(), refItemPOJOPK.getUniqueID(), clusterName); server.commit(clusterName); } catch (Exception e) { server.rollback(clusterName); throw e; } //delete dropped item try { server.deleteDocument(MDM_ITEMS_TRASH, droppedItemPOJOPK.getUniquePK()); } catch (Exception e) { server.rollback(MDM_ITEMS_TRASH); throw e; } return refItemPOJOPK; } 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.amalto.webapp.core.util.Util.java
public static Document parse(String xmlString, String schema) throws Exception { // parse//from w w w.j a va 2 s .c o m Document d; SAXErrorHandler seh = new SAXErrorHandler(); try { // initialize the sax parser which uses Xerces DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); // Schema validation based on schemaURL factory.setNamespaceAware(true); factory.setValidating((schema != null)); factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", //$NON-NLS-1$ "http://www.w3.org/2001/XMLSchema"); //$NON-NLS-1$ if (schema != null) { factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", //$NON-NLS-1$ new InputSource(new StringReader(schema))); } DocumentBuilder builder; builder = factory.newDocumentBuilder(); builder.setErrorHandler(seh); d = builder.parse(new InputSource(new StringReader(xmlString))); } catch (Exception e) { String err = "Unable to parse the document" + ": " + e.getClass().getName() + ": " //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + e.getLocalizedMessage() + "\n " //$NON-NLS-1$ + xmlString; throw new Exception(err); } // check if document parsed correctly against the schema if (schema != null) { String errors = seh.getErrors(); if (!errors.equals("")) { //$NON-NLS-1$ String err = "Document did not parse against schema: \n" + errors + "\n" + xmlString; //$NON-NLS-1$//$NON-NLS-2$ throw new Exception(err); } } return d; }
From source file:com.amalto.webapp.core.util.Util.java
public static String[] getTextNodes(Node contextNode, String xPath) throws XtentisWebappException { // test for hard-coded values if (xPath.startsWith("\"") && xPath.endsWith("\"")) { //$NON-NLS-1$ //$NON-NLS-2$ return new String[] { xPath.substring(1, xPath.length() - 1) }; }/*from ww w. j a v a 2 s. c o m*/ // test for incomplete path (elements missing /text()) if (!xPath.matches(".*@[^/\\]]+")) { //$NON-NLS-1$ if (!xPath.endsWith(")")) { //$NON-NLS-1$ xPath += "/text()"; //$NON-NLS-1$ } } try { NodeList nodeList = com.amalto.core.util.Util.getNodeList(contextNode, xPath); String[] results = new String[nodeList.getLength()]; for (int i = 0; i < nodeList.getLength(); i++) { results[i] = nodeList.item(i).getNodeValue(); } return results; } catch (Exception e) { String err = "Unable to get the text node(s) of " + xPath + ": " + e.getClass().getName() + ": " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + e.getLocalizedMessage(); throw new XtentisWebappException(err, e); } }
From source file:com.facebook.internal.Utility.java
public static void logd(String tag, Exception e) { if (Settings.isDebugEnabled() && tag != null && e != null) { Log.d(tag, e.getClass().getSimpleName() + ": " + e.getMessage()); }//from w w w .j a v a 2 s. com }