本文整理汇总了Java中org.springframework.util.ReflectionUtils.declaresException方法的典型用法代码示例。如果您正苦于以下问题:Java ReflectionUtils.declaresException方法的具体用法?Java ReflectionUtils.declaresException怎么用?Java ReflectionUtils.declaresException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.util.ReflectionUtils
的用法示例。
在下文中一共展示了ReflectionUtils.declaresException方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertRmiAccessException
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
/**
* Convert the given RemoteException that happened during remote access
* to Spring's RemoteAccessException if the method signature does not
* support RemoteException. Else, return the original RemoteException.
* @param method the invoked method
* @param ex the RemoteException that happened
* @param isConnectFailure whether the given exception should be considered
* a connect failure
* @param serviceName the name of the service (for debugging purposes)
* @return the exception to be thrown to the caller
*/
public static Exception convertRmiAccessException(
Method method, RemoteException ex, boolean isConnectFailure, String serviceName) {
if (logger.isDebugEnabled()) {
logger.debug("Remote service [" + serviceName + "] threw exception", ex);
}
if (ReflectionUtils.declaresException(method, ex.getClass())) {
return ex;
}
else {
if (isConnectFailure) {
return new RemoteConnectFailureException("Could not connect to remote service [" + serviceName + "]", ex);
}
else {
return new RemoteAccessException("Could not access remote service [" + serviceName + "]", ex);
}
}
}
示例2: invoke
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
try {
return mi.proceed();
}
catch (RuntimeException ex) {
// Let it throw raw if the type of the exception is on the throws clause of the method.
if (!this.alwaysTranslate && ReflectionUtils.declaresException(mi.getMethod(), ex.getClass())) {
throw ex;
}
else {
if (this.persistenceExceptionTranslator == null) {
this.persistenceExceptionTranslator = detectPersistenceExceptionTranslators(this.beanFactory);
}
throw DataAccessUtils.translateIfNecessary(ex, this.persistenceExceptionTranslator);
}
}
}
示例3: convertCorbaAccessException
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
/**
* Convert the given CORBA SystemException that happened during remote access
* to Spring's RemoteAccessException if the method signature does not declare
* RemoteException. Else, return the SystemException wrapped in a RemoteException.
* @param method the invoked method
* @param ex the RemoteException that happened
* @return the exception to be thrown to the caller
*/
private Exception convertCorbaAccessException(SystemException ex, Method method) {
if (ReflectionUtils.declaresException(method, RemoteException.class)) {
// A traditional RMI service: wrap CORBA exceptions in standard RemoteExceptions.
return new RemoteException("Failed to access CORBA service [" + getJndiName() + "]", ex);
}
else {
if (isConnectFailure(ex)) {
return new RemoteConnectFailureException("Could not connect to CORBA service [" + getJndiName() + "]", ex);
}
else {
return new RemoteAccessException("Could not access CORBA service [" + getJndiName() + "]", ex);
}
}
}