diff options
author | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2006-09-05 20:47:38 +0000 |
---|---|---|
committer | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2006-09-05 20:47:38 +0000 |
commit | 228fc33f661314b6723b691635085ee4ff6a69b2 (patch) | |
tree | 50e78696593f8df21fe9330258dff98537d39f65 /gnu/javax/security/auth/callback/AbstractCallbackHandler.java | |
parent | f090c35d5776db64813ccf19d8327cf0ae756ac7 (diff) | |
download | classpath-228fc33f661314b6723b691635085ee4ff6a69b2.tar.gz |
2006-09-05 Andrew John Hughes <gnu_andrew@member.fsf.org>
* Merge of HEAD-->generics from 2006/08/12 to 2006/09/03.
Diffstat (limited to 'gnu/javax/security/auth/callback/AbstractCallbackHandler.java')
-rw-r--r-- | gnu/javax/security/auth/callback/AbstractCallbackHandler.java | 97 |
1 files changed, 67 insertions, 30 deletions
diff --git a/gnu/javax/security/auth/callback/AbstractCallbackHandler.java b/gnu/javax/security/auth/callback/AbstractCallbackHandler.java index eeedf2605..5144f58ea 100644 --- a/gnu/javax/security/auth/callback/AbstractCallbackHandler.java +++ b/gnu/javax/security/auth/callback/AbstractCallbackHandler.java @@ -83,65 +83,102 @@ public abstract class AbstractCallbackHandler implements CallbackHandler this.name = name; } - // Class methods. - // ------------------------------------------------------------------------- - + /** + * Create an instance of <code>CallbackHandler</code> of the designated + * <code>type</code> from the first Security Provider which offers it. + * + * @param type the type of callback handler to create. + * @return a newly created instance of <code>ClassbackHandler</code>. + * @throws NoSuchAlgorithmException if no security provider is found to offer + * an implementation of <code>CallbackHandler</code> of the + * designated <code>type</code>. + */ public static CallbackHandler getInstance(String type) - throws NoSuchAlgorithmException + throws NoSuchAlgorithmException { Provider[] p = Security.getProviders(); + NoSuchAlgorithmException lastException = null; for (int i = 0; i < p.length; i++) - { - try - { - return getInstance(type, p[i]); - } - catch (NoSuchAlgorithmException ignored) - { - } - } + try + { + return getInstance(type, p[i]); + } + catch (NoSuchAlgorithmException x) + { + lastException = x; + } + if (lastException != null) + throw lastException; throw new NoSuchAlgorithmException(type); } + /** + * Create an instance of <code>CallbackHandler</code> of the designated + * <code>type</code> from the named security <code>provider</code>. + * + * @param type the type of callback handler to create. + * @param provider a named security provider to use. + * @return a newly created instance of <code>ClassbackHandler</code>. + * @throws NoSuchAlgorithmException if no security provider is found to offer + * an implementation of <code>CallbackHandler</code> of the + * designated <code>type</code>. + * @throws IllegalArgumentException if either <code>type</code> or + * <code>provider</code> is <code>null</code>, or if + * <code>type</code> is an empty string. + */ public static CallbackHandler getInstance(String type, String provider) - throws NoSuchAlgorithmException, NoSuchProviderException + throws NoSuchAlgorithmException, NoSuchProviderException { + if (provider == null) + throw new IllegalArgumentException("provider MUST NOT be null"); Provider p = Security.getProvider(provider); if (p == null) - { - throw new NoSuchProviderException(provider); - } + throw new NoSuchProviderException(provider); return getInstance(type, p); } + /** + * Create an instance of <code>CallbackHandler</code> of the designated + * <code>type</code> from the designated security <code>provider</code>. + * + * @param type the type of callback handler to create. + * @param provider a security provider to use. + * @return a newly created instance of <code>ClassbackHandler</code>. + * @throws NoSuchAlgorithmException if no security provider is found to offer + * an implementation of <code>CallbackHandler</code> of the + * designated <code>type</code>. + * @throws IllegalArgumentException if either <code>type</code> or + * <code>provider</code> is <code>null</code>, or if + * <code>type</code> is an empty string. + */ public static CallbackHandler getInstance(String type, Provider provider) throws NoSuchAlgorithmException { + StringBuilder sb = new StringBuilder("CallbackHandler of type [") + .append(type).append("] from provider[") + .append(provider).append("] could not be created"); + Throwable cause; try { return (CallbackHandler) Engine.getInstance(SERVICE, type, provider); } - catch (InvocationTargetException ite) + catch (InvocationTargetException x) { - Throwable cause = ite.getCause(); + cause = x.getCause(); if (cause instanceof NoSuchAlgorithmException) throw (NoSuchAlgorithmException) cause; - NoSuchAlgorithmException nsae = new NoSuchAlgorithmException(type); - if (cause != null) - nsae.initCause (cause); - throw nsae; + if (cause == null) + cause = x; } - catch (ClassCastException cce) + catch (ClassCastException x) { - NoSuchAlgorithmException nsae = new NoSuchAlgorithmException(type); - nsae.initCause (cce); - throw nsae; + cause = x; } + NoSuchAlgorithmException x = new NoSuchAlgorithmException(sb.toString()); + x.initCause(cause); + throw x; } - // Instance methods. - // ------------------------------------------------------------------------- - public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { |