1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.juddi.keygen;
19
20 import org.apache.commons.configuration.ConfigurationException;
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.apache.juddi.ClassUtil;
24 import org.apache.juddi.config.AppConfig;
25 import org.apache.juddi.config.Property;
26
27
28
29
30
31
32
33
34
35 public abstract class KeyGeneratorFactory {
36 private static Log log = LogFactory.getLog(KeyGeneratorFactory.class);
37
38
39 public static final String DEFAULT_IMPL = "org.apache.juddi.keygen.DefaultKeyGenerator";
40
41
42 private static KeyGenerator keyGenerator = null;
43
44
45
46
47
48
49 public static synchronized KeyGenerator getKeyGenerator() {
50 if (keyGenerator == null)
51 keyGenerator = createKeyGenerator();
52 return keyGenerator;
53 }
54
55 public static synchronized KeyGenerator forceNewKeyGenerator() {
56 keyGenerator = null;
57 keyGenerator = createKeyGenerator();
58 return keyGenerator;
59 }
60
61
62
63
64
65
66 private static synchronized KeyGenerator createKeyGenerator() {
67 if (keyGenerator != null)
68 return keyGenerator;
69
70
71 String className = System.getProperty(Property.JUDDI_KEYGENERATOR);
72 if (className==null){
73 try {
74
75 className = AppConfig.getConfiguration().getString(Property.JUDDI_KEYGENERATOR, DEFAULT_IMPL);
76 }
77 catch(ConfigurationException ce) {
78 log.error("Configuration exception occurred retrieving: " + Property.JUDDI_KEYGENERATOR);
79 }
80 }
81 try {
82
83 log.debug("Configuration Key Generator Implementation = " + AppConfig.getConfiguration().getString(Property.JUDDI_KEYGENERATOR));
84 } catch (ConfigurationException ex) {
85 }
86 log.debug("SysProp Key Generator Implementation = " + System.getProperty(Property.JUDDI_KEYGENERATOR));
87 log.debug("Using Key Generator Implementation = " + className);
88
89 Class<?> keygenClass = null;
90 try {
91
92 keygenClass = ClassUtil.forName(className,KeyGeneratorFactory.class);
93
94 keyGenerator = (KeyGenerator)keygenClass.newInstance();
95 } catch(ClassNotFoundException cnfe) {
96 throw new RuntimeException("The specified Key Generator class '" + className + "' was not found on classpath.",cnfe);
97 } catch(InstantiationException ie) {
98 throw new RuntimeException("The specified Key Generator class '" + className + "' cannot be instantiated.",ie);
99 } catch(IllegalAccessException iae) {
100 throw new RuntimeException("The specified Key Generator class '" + className + "' cannot be instantiated due to illegal access.",iae);
101 } catch(Exception e) {
102 throw new RuntimeException("Exception while attempting to instantiate the implementation of Key Generator: " + className + "\n" + e.getMessage());
103 }
104
105 return keyGenerator;
106 }
107 }