Skip to content
Snippets Groups Projects
Commit fa79e71e authored by ribeaudc's avatar ribeaudc
Browse files

minor: - Naming refactoring.

SVN: 4494
parent 6f002a86
No related branches found
No related tags found
No related merge requests found
......@@ -27,9 +27,9 @@ import ch.systemsx.cisd.common.exceptions.IndependentException;
public final class ExceptionUtils
{
/**
* The package names considered as client-safe.
* Accepted packages for dependencies.
*/
private static String[] CLIENT_SAFE_PACKAGE_NAMES =
private static String[] ACCEPTED_DEPENDENCIES_PACKAGE_NAMES =
{ "java.lang", "ch.systemsx.cisd" };
ExceptionUtils()
......@@ -38,13 +38,13 @@ public final class ExceptionUtils
}
/**
* Creates a new <code>ClientSafeException</code> from given <var>exception</var> only if it is needed ({@link #isClientSafe(Exception)}
* Creates a new {@link IndependentException} from given <var>exception</var> only if it is needed ({@link #isIndependent(Exception)}
* returns <code>false</code>). Otherwise returns given <var>exception</var>.
*/
private final static Exception createClientSafeException(final Exception exception)
private final static Exception createIndependentException(final Exception exception)
{
final Exception rootException = CheckedExceptionTunnel.unwrapIfNecessary(exception);
if (isClientSafe(rootException) == false)
if (isIndependent(rootException) == false)
{
return new IndependentException(rootException);
} else
......@@ -62,7 +62,7 @@ public final class ExceptionUtils
(Exception) org.apache.commons.lang.exception.ExceptionUtils.getCause(fromException);
if (fromCauseException != null && fromCauseException != fromException)
{
final Exception toCauseException = createClientSafeException(fromCauseException);
final Exception toCauseException = createIndependentException(fromCauseException);
if (toException.getCause() != toCauseException)
{
if (ClassUtils.setFieldValue(toException, "cause", toCauseException) == false)
......@@ -77,11 +77,11 @@ public final class ExceptionUtils
/**
* Whether given <var>exception</var> is client-safe or not.
*/
final static boolean isClientSafe(final Exception exception)
final static boolean isIndependent(final Exception exception)
{
assert exception != null : "Unspecified exception.";
final String className = exception.getClass().getName();
for (final String packageName : CLIENT_SAFE_PACKAGE_NAMES)
for (final String packageName : ACCEPTED_DEPENDENCIES_PACKAGE_NAMES)
{
if (className.startsWith(packageName))
{
......@@ -92,12 +92,13 @@ public final class ExceptionUtils
}
/**
* Analyzes given <var>exception</var> and makes it client-safe.
* Analyzes given <var>exception</var> and makes it independent to packages outside the ones specified in
* {@link #ACCEPTED_DEPENDENCIES_PACKAGE_NAMES}.
*/
public final static Exception createClientSafeExceptionIfNeeded(final Exception exception)
public final static Exception createIndependentExceptionIfNeeded(final Exception exception)
{
assert exception != null : "Unspecified SQL Exception.";
final Exception clientSafeException = createClientSafeException(exception);
final Exception clientSafeException = createIndependentException(exception);
copyCauseException(exception, clientSafeException);
return clientSafeException;
}
......
......@@ -65,7 +65,7 @@ public final class ExceptionUtilsTest
{
try
{
ExceptionUtils.createClientSafeExceptionIfNeeded(null);
ExceptionUtils.createIndependentExceptionIfNeeded(null);
fail("Null exception not allowed.");
} catch (final AssertionError ex)
{
......@@ -78,7 +78,7 @@ public final class ExceptionUtilsTest
{
final String message = "Oooops!";
final UserFailureException exception = new UserFailureException(message);
final Exception clientSafeException = ExceptionUtils.createClientSafeExceptionIfNeeded(exception);
final Exception clientSafeException = ExceptionUtils.createIndependentExceptionIfNeeded(exception);
checkReturnedClientSafeException(message, exception, clientSafeException, true);
}
......@@ -87,7 +87,7 @@ public final class ExceptionUtilsTest
{
final String message = "Oooops!";
final Exception exception = new SAXException(message);
final Exception clientSafeException = ExceptionUtils.createClientSafeExceptionIfNeeded(exception);
final Exception clientSafeException = ExceptionUtils.createIndependentExceptionIfNeeded(exception);
checkReturnedClientSafeException(message, exception, clientSafeException, false);
}
......@@ -102,7 +102,7 @@ public final class ExceptionUtilsTest
final UnsupportedOperationException unsupportedOperationException =
new UnsupportedOperationException(unsupportedOperationText, runtimeException);
final Exception clientSafeException =
ExceptionUtils.createClientSafeExceptionIfNeeded(unsupportedOperationException);
ExceptionUtils.createIndependentExceptionIfNeeded(unsupportedOperationException);
checkReturnedClientSafeException(unsupportedOperationText, unsupportedOperationException, clientSafeException,
true);
checkReturnedClientSafeException(runtimeText, runtimeException, (Exception) clientSafeException.getCause(),
......@@ -120,7 +120,7 @@ public final class ExceptionUtilsTest
final RuntimeException runtimeException = new RuntimeException(runtimeText, saxException);
final String digestExceptionText = "Wishiiiii!";
final DigestException digestException = new DigestException(digestExceptionText, runtimeException);
final Exception clientSafeException = ExceptionUtils.createClientSafeExceptionIfNeeded(digestException);
final Exception clientSafeException = ExceptionUtils.createIndependentExceptionIfNeeded(digestException);
checkReturnedClientSafeException(digestExceptionText, digestException, clientSafeException, false);
checkReturnedClientSafeException(runtimeText, runtimeException, (Exception) clientSafeException.getCause(),
true);
......@@ -134,7 +134,7 @@ public final class ExceptionUtilsTest
final String text = "Oooops!";
final IOException ioException = new IOException(text);
final RuntimeException checkedExceptionTunnel = CheckedExceptionTunnel.wrapIfNecessary(ioException);
final Exception clientSafeException = ExceptionUtils.createClientSafeExceptionIfNeeded(checkedExceptionTunnel);
final Exception clientSafeException = ExceptionUtils.createIndependentExceptionIfNeeded(checkedExceptionTunnel);
assertNotSame(clientSafeException, checkedExceptionTunnel);
assertNotSame(clientSafeException, ioException);
assertTrue(clientSafeException instanceof IndependentException);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment