KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > security > pki > SshPrivateKeyFormatFactory


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.security.pki;
21
22 import java.util.HashMap JavaDoc;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26
27
28 /**
29  *
30  *
31  * @author $author$
32  */

33 public class SshPrivateKeyFormatFactory {
34     private static String JavaDoc defaultFormat;
35     private static HashMap JavaDoc formatTypes;
36     private static Log log = LogFactory.getLog(SshPrivateKeyFormatFactory.class);
37
38     static {
39         if (log.isInfoEnabled())
40             log.info("Loading private key formats");
41
42         formatTypes = new HashMap JavaDoc();
43         defaultFormat = "SSHTools-PrivateKey-Base64Encoded";
44         formatTypes.put(defaultFormat, SshtoolsPrivateKeyFormat.class);
45
46     }
47
48     public static void initialize() {
49     }
50
51     /**
52      *
53      *
54      * @param type
55      *
56      * @return SshPrivateKeyFormat
57      *
58      * @throws InvalidKeyException
59      */

60     public static SshPrivateKeyFormat newInstance(String JavaDoc type)
61         throws InvalidKeyException {
62         try {
63             if (formatTypes.containsKey(type)) {
64                 return (SshPrivateKeyFormat) ((Class JavaDoc) formatTypes.get(type)).newInstance();
65             } else {
66                 throw new InvalidKeyException("The format type " + type +
67                     " is not supported");
68             }
69         } catch (IllegalAccessException JavaDoc iae) {
70             throw new InvalidKeyException(
71                 "Illegal access to class implementation of " + type);
72         } catch (InstantiationException JavaDoc ie) {
73             throw new InvalidKeyException(
74                 "Failed to create instance of format type " + type);
75         }
76     }
77
78     /**
79      *
80      *
81      * @return String
82      */

83     public static String JavaDoc getDefaultFormatType() {
84         return defaultFormat;
85     }
86 }
87
Popular Tags