001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package javax.microedition.pki;
028:
029: /**
030: * This class is used to identify error conditions in
031: * the management of the user certificate store.
032: * Thrown by the <code>CMSMessageSignatureService</code> and
033: * <code>UserCredentialManager</code> classes.
034: */
035: final public class UserCredentialManagerException extends Exception {
036: /**
037: * Code returned if a credential can not be added.
038: * For example, it is returned if there is insufficient
039: * memory to add additional credentials
040: */
041: public static final byte CREDENTIAL_NOT_SAVED = 0x00;
042:
043: /**
044: * Code returned if a security element does not
045: * support key generation.
046: */
047: public static final byte SE_NO_KEYGEN = 0x01;
048:
049: /**
050: * Code returned if a security element does not
051: * have keys available for certificate requests.
052: */
053: public static final byte SE_NO_KEYS = 0x02;
054:
055: /**
056: * Code returned if a security element does not
057: * have any keys available that are not already
058: * associated with a certificate, and if the
059: * platform does not allow reuse of keys that
060: * are associated with an existing certificate.
061: */
062: public static final byte SE_NO_UNASSOCIATED_KEYS = 0x03;
063:
064: /**
065: * Code returned if an appropriate security element
066: * can not be found.
067: */
068: public static final byte SE_NOT_FOUND = 0x04;
069:
070: /**
071: * Code returned if an appropriate certificate
072: * can not be found.
073: */
074: public static final byte CREDENTIAL_NOT_FOUND = 0x05;
075:
076: /**
077: * The reason code for exception.
078: */
079: private byte reasonCode;
080:
081: /**
082: * Construct an exception with specific reason code.
083: * @param code the code for the error condition
084: */
085: public UserCredentialManagerException(byte code) {
086: super (getMessageForReason(code));
087: reasonCode = code;
088: }
089:
090: /**
091: * Gets the reason code.
092: * @return the code for the error condition
093: */
094: public byte getReason() {
095: return reasonCode;
096: }
097:
098: /**
099: * Gets the exception message for a reason.
100: *
101: * @param reason reason code
102: *
103: * @return exception message
104: */
105: static String getMessageForReason(int reason) {
106: switch (reason) {
107: case CREDENTIAL_NOT_SAVED:
108: return "Could not save credential";
109: case SE_NO_KEYGEN:
110: return "Security element does not support key generation";
111: case SE_NO_KEYS:
112: return "Security Element has no keys";
113: case SE_NO_UNASSOCIATED_KEYS:
114: return "Security Element has no unassociated keys";
115: case SE_NOT_FOUND:
116: return "Security Element was not found";
117: case CREDENTIAL_NOT_FOUND:
118: return "Credential was not found";
119: }
120:
121: return "Unknown reason (" + reason + ")";
122: }
123:
124: }
|