KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > schlichtherle > key > passwd > swing > WeakKeyException


1 /*
2  * Copyright 2006 Schlichtherle IT Services
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package de.schlichtherle.key.passwd.swing;
18
19 import java.security.GeneralSecurityException JavaDoc;
20 import java.text.MessageFormat JavaDoc;
21 import java.util.ResourceBundle JavaDoc;
22
23 /**
24  * Thrown to indicate that a password or key file is considered weak.
25  *
26  * @author Christian Schlichtherle
27  * @since TrueZIP 6.1 (refactored from <code>WeakPasswdException</code>)
28  * @version @version@
29  */

30 public class WeakKeyException extends GeneralSecurityException JavaDoc {
31
32     private final ResourceBundle JavaDoc resources;
33     private final Object JavaDoc param;
34
35     /**
36      * @param key The resource bundle key for the localized message.
37      *
38      * @see #getLocalizedMessage()
39      */

40     public WeakKeyException(ResourceBundle JavaDoc resources, String JavaDoc key) {
41         super(key);
42         
43         this.resources = resources;
44         this.param = null;
45     }
46
47     /**
48      * @param key The resource bundle key for the localized message.
49      *
50      * @see #getLocalizedMessage()
51      */

52     public WeakKeyException(ResourceBundle JavaDoc resources, String JavaDoc key, Object JavaDoc param) {
53         super(key);
54         
55         this.resources = resources;
56         this.param = param;
57     }
58     
59     /**
60      * Returns the localized message of the key in the resource bundle.
61      */

62     public String JavaDoc getLocalizedMessage() {
63         if (param != null) {
64             return MessageFormat.format(
65                     resources.getString(getMessage()),
66                     new Object JavaDoc[] { param });
67         } else {
68             return resources.getString(getMessage());
69         }
70     }
71 }
72
Popular Tags