diff options
Diffstat (limited to 'moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/invoke/IaikExceptionMapper.java')
-rw-r--r-- | moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/invoke/IaikExceptionMapper.java | 246 |
1 files changed, 135 insertions, 111 deletions
diff --git a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/invoke/IaikExceptionMapper.java b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/invoke/IaikExceptionMapper.java index 6e8448b..8817937 100644 --- a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/invoke/IaikExceptionMapper.java +++ b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/invoke/IaikExceptionMapper.java @@ -21,12 +21,8 @@ * that you distribute must include a readable copy of the "NOTICE" text file. */ - package at.gv.egovernment.moa.spss.server.invoke; -import iaik.server.modules.IAIKException; -import iaik.server.modules.IAIKRuntimeException; - import java.lang.reflect.Constructor; import java.util.HashMap; import java.util.Map; @@ -34,12 +30,13 @@ import java.util.Map; import at.gv.egovernment.moa.spss.MOAApplicationException; import at.gv.egovernment.moa.spss.MOAException; import at.gv.egovernment.moa.spss.MOASystemException; - +import iaik.server.modules.IAIKException; +import iaik.server.modules.IAIKRuntimeException; /** * Map an exception from the <code>iaik</code> namespace to a * <code>MOAException</code>. - * + * * @author Patrick Peck * @version $Id$ */ @@ -47,57 +44,80 @@ public class IaikExceptionMapper { /** The argument classes for <code>MOAException</code>s. */ private static final Class[] CONSTRUCTOR_ARGS = - new Class[] { String.class, Object[].class, Throwable.class }; + new Class[] { String.class, Object[].class, Throwable.class }; /** The exception mapping, as an array. */ private static final Object[][] MESSAGES = - { - { iaik.server.modules.IAIKException.class, "9900", MOASystemException.class }, - { iaik.server.modules.IAIKRuntimeException.class, "9901", MOASystemException.class }, - { iaik.server.modules.xmlsign.XMLSignatureCreationException.class, "2220", MOAApplicationException.class }, - { iaik.server.modules.xmlsign.XMLSignatureCreationRuntimeException.class, "2220", MOAApplicationException.class }, - { iaik.server.modules.xmlsign.InvalidKeyException.class, "2221", MOAApplicationException.class }, - { iaik.server.modules.xmlsign.ManifestException.class, "2222", MOAApplicationException.class }, - { iaik.server.modules.xmlsign.ReferenceException.class, "2223", MOAApplicationException.class }, - { iaik.server.modules.xmlsign.HashUnavailableException.class, "2224", MOAApplicationException.class }, - { iaik.server.modules.xmlsign.SignatureAlgorithmException.class, "2225", MOAApplicationException.class }, - { iaik.server.modules.xmlsign.SignatureEmbeddingException.class, "2226", MOAApplicationException.class }, - { iaik.server.modules.xmlsign.SignatureValueException.class, "2227", MOAApplicationException.class }, - { iaik.server.modules.xmlsign.SignedPropertyException.class, "2228", MOAApplicationException.class }, - { iaik.server.modules.xmlsign.SignerCertificateUnavailableException.class, "2229", MOAApplicationException.class }, - { iaik.server.modules.xmlsign.SupplementException.class, "2230", MOAApplicationException.class }, - { iaik.server.modules.xmlsign.TransformationException.class, "2233", MOAApplicationException.class }, - { iaik.server.modules.cmsverify.CMSSignatureVerificationException.class, "2240", MOAApplicationException.class }, - { iaik.server.modules.cmsverify.CMSSignatureVerificationRuntimeException.class, "2240", MOAApplicationException.class }, - { iaik.server.modules.cmsverify.AlgorithmNotSupportedException.class, "2241", MOAApplicationException.class }, - { iaik.server.modules.cmsverify.CMSSignatureParsingException.class, "2242", MOAApplicationException.class }, - { iaik.server.modules.cmsverify.SignerCertificateUnavailableException.class, "2243", MOAApplicationException.class }, - { iaik.server.modules.cmsverify.CMSSignatureVerificationRuntimeException.class, "2247", MOAApplicationException.class }, - { iaik.server.modules.cmsverify.InitException.class, "2248", MOAApplicationException.class }, - { iaik.server.modules.xmlverify.XMLSignatureVerificationException.class, "2240", MOAApplicationException.class }, - { iaik.server.modules.xmlverify.XMLSignatureVerificationRuntimeException.class, "2240", MOAApplicationException.class }, - { iaik.server.modules.xmlverify.AlgorithmNotSupportedException.class, "2241", MOAApplicationException.class }, - { iaik.server.modules.xmlverify.ManifestException.class, "2262", MOAApplicationException.class }, - { iaik.server.modules.xmlverify.PropertiesException.class, "2263", MOAApplicationException.class }, - { iaik.server.modules.xmlverify.ReferenceException.class, "2264", MOAApplicationException.class }, - { iaik.server.modules.xmlverify.HashUnavailableException.class, "2224", MOAApplicationException.class }, - { iaik.server.modules.xmlverify.SignerCertificateUnavailableException.class, "2243", MOAApplicationException.class }, - { iaik.server.modules.xmlverify.SupplementException.class, "2230", MOAApplicationException.class }, - { iaik.server.modules.xmlverify.TransformationException.class, "2265", MOAApplicationException.class }, - { iaik.server.modules.xmlverify.TransformationParsingException.class, "2269", MOAApplicationException.class }, - { at.gv.egovernment.moa.sig.tsl.exception.TslException.class, "2290", MOAApplicationException.class }, - { iaik.server.modules.cmssign.CMSSignatureCreationException.class, "2300", MOAApplicationException.class } , - - - }; - + { + { iaik.server.modules.IAIKException.class, "9900", MOASystemException.class }, + { iaik.server.modules.IAIKRuntimeException.class, "9901", MOASystemException.class }, + { iaik.server.modules.xmlsign.XMLSignatureCreationException.class, "2220", + MOAApplicationException.class }, + { iaik.server.modules.xmlsign.XMLSignatureCreationRuntimeException.class, "2220", + MOAApplicationException.class }, + { iaik.server.modules.xmlsign.InvalidKeyException.class, "2221", MOAApplicationException.class }, + { iaik.server.modules.xmlsign.ManifestException.class, "2222", MOAApplicationException.class }, + { iaik.server.modules.xmlsign.ReferenceException.class, "2223", MOAApplicationException.class }, + { iaik.server.modules.xmlsign.HashUnavailableException.class, "2224", + MOAApplicationException.class }, + { iaik.server.modules.xmlsign.SignatureAlgorithmException.class, "2225", + MOAApplicationException.class }, + { iaik.server.modules.xmlsign.SignatureEmbeddingException.class, "2226", + MOAApplicationException.class }, + { iaik.server.modules.xmlsign.SignatureValueException.class, "2227", + MOAApplicationException.class }, + { iaik.server.modules.xmlsign.SignedPropertyException.class, "2228", + MOAApplicationException.class }, + { iaik.server.modules.xmlsign.SignerCertificateUnavailableException.class, "2229", + MOAApplicationException.class }, + { iaik.server.modules.xmlsign.SupplementException.class, "2230", MOAApplicationException.class }, + { iaik.server.modules.xmlsign.TransformationException.class, "2233", + MOAApplicationException.class }, + { iaik.server.modules.cmsverify.CMSSignatureVerificationException.class, "2240", + MOAApplicationException.class }, + { iaik.server.modules.cmsverify.CMSSignatureVerificationRuntimeException.class, "2240", + MOAApplicationException.class }, + { iaik.server.modules.cmsverify.AlgorithmNotSupportedException.class, "2241", + MOAApplicationException.class }, + { iaik.server.modules.cmsverify.CMSSignatureParsingException.class, "2242", + MOAApplicationException.class }, + { iaik.server.modules.cmsverify.SignerCertificateUnavailableException.class, "2243", + MOAApplicationException.class }, + { iaik.server.modules.cmsverify.CMSSignatureVerificationRuntimeException.class, "2247", + MOAApplicationException.class }, + { iaik.server.modules.cmsverify.InitException.class, "2248", MOAApplicationException.class }, + { iaik.server.modules.xmlverify.XMLSignatureVerificationException.class, "2240", + MOAApplicationException.class }, + { iaik.server.modules.xmlverify.XMLSignatureVerificationRuntimeException.class, "2240", + MOAApplicationException.class }, + { iaik.server.modules.xmlverify.AlgorithmNotSupportedException.class, "2241", + MOAApplicationException.class }, + { iaik.server.modules.xmlverify.ManifestException.class, "2262", MOAApplicationException.class }, + { iaik.server.modules.xmlverify.PropertiesException.class, "2263", MOAApplicationException.class }, + { iaik.server.modules.xmlverify.ReferenceException.class, "2264", MOAApplicationException.class }, + { iaik.server.modules.xmlverify.HashUnavailableException.class, "2224", + MOAApplicationException.class }, + { iaik.server.modules.xmlverify.SignerCertificateUnavailableException.class, "2243", + MOAApplicationException.class }, + { iaik.server.modules.xmlverify.SupplementException.class, "2230", MOAApplicationException.class }, + { iaik.server.modules.xmlverify.TransformationException.class, "2265", + MOAApplicationException.class }, + { iaik.server.modules.xmlverify.TransformationParsingException.class, "2269", + MOAApplicationException.class }, + { at.gv.egovernment.moa.sig.tsl.exception.TslException.class, "2290", + MOAApplicationException.class }, + { iaik.server.modules.cmssign.CMSSignatureCreationException.class, "2300", + MOAApplicationException.class }, + + }; + /** The single instance of this class. */ private static IaikExceptionMapper instance; /** The exception mapping, as a <code>Map</code> for fast lookup. */ - private Map messages = new HashMap(); + private final Map messages = new HashMap(); /** * Get the single instance of this class. - * + * * @return The single instance of this class. */ public static synchronized IaikExceptionMapper getInstance() { @@ -109,7 +129,7 @@ public class IaikExceptionMapper { /** * Create a new <code>IaikExceptionMapper</code>. - * + * * Protected to disallow multple instances. */ protected IaikExceptionMapper() { @@ -124,59 +144,63 @@ public class IaikExceptionMapper { for (i = 0; i < MESSAGES.length; i++) { registerMessage( - (Class) MESSAGES[i][0], - (String) MESSAGES[i][1], - (Class) MESSAGES[i][2]); + (Class) MESSAGES[i][0], + (String) MESSAGES[i][1], + (Class) MESSAGES[i][2]); } } /** * Register a single <code>IAIKException</code> to message mapping. - * - * @param iaikExceptionClass An exception from the <code>iaik</code> package. - * @param messageId The corresponding error message id. - * @param moaExceptionClass The type of <code>MOAException</code> that the - * <code>IAIKException</code> is mapped to (usually - * <code>MOAApplicationException</code> or <code>MOASystemException</code>). + * + * @param iaikExceptionClass An exception from the <code>iaik</code> package. + * @param messageId The corresponding error message id. + * @param moaExceptionClass The type of <code>MOAException</code> that the + * <code>IAIKException</code> is mapped to (usually + * <code>MOAApplicationException</code> or + * <code>MOASystemException</code>). */ protected void registerMessage( - Class iaikExceptionClass, - String messageId, - Class moaExceptionClass) { + Class iaikExceptionClass, + String messageId, + Class moaExceptionClass) { messages.put( - iaikExceptionClass, - new ExceptionMappingInfo(messageId, moaExceptionClass)); + iaikExceptionClass, + new ExceptionMappingInfo(messageId, moaExceptionClass)); } /** - * Map an <code>iaik.xml.crypto.tsl.ex.TSLSearchException</code> to a <code>MOAException</code>. - * - * @param tslSearchException The <code>iaik.xml.crypto.tsl.ex.TSLSearchException</code> to map. - * @return A <code>MOAException</code> containing the message for the - * given <code>IAIKException</code>. + * Map an <code>iaik.xml.crypto.tsl.ex.TSLSearchException</code> to a + * <code>MOAException</code>. + * + * @param tslSearchException The + * <code>iaik.xml.crypto.tsl.ex.TSLSearchException</code> + * to map. + * @return A <code>MOAException</code> containing the message for the given + * <code>IAIKException</code>. */ public MOAException map(at.gv.egovernment.moa.sig.tsl.exception.TslException tslSearchException) { return mapImpl(tslSearchException); } - + /** * Map an <code>IAIKException</code> to a <code>MOAException</code>. - * - * @param iaikException The <code>IAIKException</code> to map. - * @return A <code>MOAException</code> containing the message for the - * given <code>IAIKException</code>. + * + * @param iaikException The <code>IAIKException</code> to map. + * @return A <code>MOAException</code> containing the message for the given + * <code>IAIKException</code>. */ public MOAException map(IAIKException iaikException) { return mapImpl(iaikException); } - + /** * Map an <code>IAIKRuntimeException</code> to a <code>MOAException</code>. - * - * @param iaikException The <code>IAIKException</code> to map. - * @return A <code>MOAException</code> containing the message for the - * given <code>IAIKRuntimeException</code>. + * + * @param iaikException The <code>IAIKException</code> to map. + * @return A <code>MOAException</code> containing the message for the given + * <code>IAIKRuntimeException</code>. */ public MOAException map(IAIKRuntimeException iaikException) { return mapImpl(iaikException); @@ -185,14 +209,14 @@ public class IaikExceptionMapper { /** * Map an <code>IAIKException</code> or <code>IAIKRuntimeException</code> to a * <code>MOAException</code>. - * + * * @param iaikException The <code>IAIKException</code> or - * <code>IAIKRuntimeException</code> to map. - * @return A <code>MOAException</code> containing the message for the - * given <code>IAIKRuntimeException</code>. + * <code>IAIKRuntimeException</code> to map. + * @return A <code>MOAException</code> containing the message for the given + * <code>IAIKRuntimeException</code>. */ private MOAException mapImpl(Exception iaikException) { - MOAException moaException = createMoaException(iaikException); + final MOAException moaException = createMoaException(iaikException); if (moaException == null) { return new MOASystemException("9999", null, iaikException); @@ -201,16 +225,16 @@ public class IaikExceptionMapper { } /** - * Create a <code>MOAException</code> from a given <code>IAIKException</code> - * by looking it up in the mapping. - * + * Create a <code>MOAException</code> from a given <code>IAIKException</code> by + * looking it up in the mapping. + * * @param iaikException The <code>IAIKException</code> to map. - * @return A <code>MOAException</code> with an error code corresponding to - * the given <code>IAIKException</code>. Returns <code>null</code>, if no - * mapping could be found. + * @return A <code>MOAException</code> with an error code corresponding to the + * given <code>IAIKException</code>. Returns <code>null</code>, if no + * mapping could be found. */ protected MOAException createMoaException(Exception iaikException) { - ExceptionMappingInfo info = lookupMessage(iaikException.getClass()); + final ExceptionMappingInfo info = lookupMessage(iaikException.getClass()); Constructor constructor; if (info == null) { @@ -220,13 +244,13 @@ public class IaikExceptionMapper { // instantiate the proper MOAException and return it try { constructor = - info.getMoaExceptionClass().getConstructor(CONSTRUCTOR_ARGS); + info.getMoaExceptionClass().getConstructor(CONSTRUCTOR_ARGS); return (MOAException) constructor.newInstance( - new Object[] { - info.getMessageId(), - new Object[] { iaikException.getMessage()}, - iaikException }); - } catch (Exception e) { + new Object[] { + info.getMessageId(), + new Object[] { iaikException.getMessage() }, + iaikException }); + } catch (final Exception e) { return null; } } @@ -234,19 +258,19 @@ public class IaikExceptionMapper { /** * Recursively look up the message associated with an * <code>IAIKException</code>. - * + * * This method walks up the exception inheritance hierarchy until it finds a * mapping. - * + * * @param iaikExceptionClass The <code>IAIKException</code> to look up. - * @return Information about the message id and - * <code>MOAException</code> class that the <code>iaikExceptionClass</code> - * maps to. If no mapping could be found, <code>null</code> is returned. + * @return Information about the message id and <code>MOAException</code> class + * that the <code>iaikExceptionClass</code> maps to. If no mapping could + * be found, <code>null</code> is returned. */ protected ExceptionMappingInfo lookupMessage(Class iaikExceptionClass) { ExceptionMappingInfo info; - // break if + // break if if (iaikExceptionClass.equals(Exception.class)) { return null; } @@ -264,21 +288,21 @@ public class IaikExceptionMapper { /** * A class containing a mapping from an error message ID to a * <code>MOAException</code> class. - * + * * @author Patrick Peck * @version $Id$ */ class ExceptionMappingInfo { /** The message ID. */ - private String messageId; + private final String messageId; /** The <code>MOAException</code> class. */ - private Class moaExceptionClass; + private final Class moaExceptionClass; /** * Create a new <code>ExceptionMappingInfo</code>. - * - * @param messageId The message ID. - * @param moaExceptionClass The <code>MOAException</code> class. + * + * @param messageId The message ID. + * @param moaExceptionClass The <code>MOAException</code> class. */ public ExceptionMappingInfo(String messageId, Class moaExceptionClass) { this.messageId = messageId; @@ -287,7 +311,7 @@ class ExceptionMappingInfo { /** * Return the message ID. - * + * * @return The message ID. */ public String getMessageId() { @@ -296,7 +320,7 @@ class ExceptionMappingInfo { /** * Returns the <code>MOAException</code> class that the message ID maps to. - * + * * @return The <code>MOAException</code> class. */ public Class getMoaExceptionClass() { |