1/*2 * Copyright 2001-2008 The Apache Software Foundation.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 at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 *16 */17package org.apache.juddi.cryptor;
1819import org.apache.commons.configuration.ConfigurationException;
20import org.apache.commons.logging.Log;
21import org.apache.commons.logging.LogFactory;
22import org.apache.juddi.ClassUtil;
23import org.apache.juddi.config.AppConfig;
24import org.apache.juddi.config.Property;
25import org.apache.juddi.v3.client.cryptor.Cryptor;
2627/**28 * Used to create the org.apache.juddi.cryptor.Cryptor implementation as29 * specified by the 'juddi.cryptor' property. Defaults to30 * org.apache.juddi.cryptor.DefaultCryptor if an implementation is not31 * specified.<Br>32 * <br>33 * This class is a special instance that loads from the juddi server side config file.<br>34 *35 * Use org.apache.juddi.v3.client.cryptor.CryptorFactor for all client side actions36 * @see org.apache.juddi.v3.client.cryptor.CryptorFactory37 * @author Steve Viens (sviens@apache.org)38 * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>39 */4041publicabstractclassCryptorFactory {
4243privatestaticfinal Log log = LogFactory.getLog(CryptorFactory.class);
44// the shared Cryptor instance45privatestaticCryptor cryptor = null;
4647/*48 * Returns a new instance of a CryptorFactory.49 * 50 * @return Cryptor51 */52publicstaticsynchronizedCryptor getCryptor() {
53if (cryptor == null) {
54 cryptor = createCryptor();
55 }
56return cryptor;
57 }
5859publicstaticsynchronizedCryptor getCryptor(String className) throws Exception {
60return org.apache.juddi.v3.client.cryptor.CryptorFactory.getCryptor(className);
6162 }
6364/*65 * Returns a new instance of a Cryptor.66 * 67 * @return Cryptor68 */69privatestaticsynchronizedCryptor createCryptor() {
70if (cryptor != null) {
71return cryptor;
72 }
7374// grab class name of the Cryptor implementation to create75 String className = Property.DEFAULT_CRYPTOR;
76try {
77// grab class name of the Authenticator implementation to create78 className = AppConfig.getConfiguration().getString(Property.JUDDI_CRYPTOR, Property.DEFAULT_CRYPTOR);
79 } catch (ConfigurationException ce) {
80 log.error("Configuration exception occurred retrieving: " + Property.JUDDI_CRYPTOR, ce);
81 }
8283// write the Cryptor implementation name to the log84 log.debug("Cryptor Implementation = " + className);
8586 Class<?> cryptorClass = null;
87try {
88// Use Loader to locate & load the Cryptor implementation89 cryptorClass = ClassUtil.forName(className, CryptorFactory.class);
90 } catch (ClassNotFoundException e) {
91 log.error("The specified Cryptor class '" + className + "' was not found in classpath.");
92 log.error(e);
93 }
9495if (cryptorClass != null) {
96try {
97// try to instantiate the Cryptor implementation98 cryptor = (Cryptor) cryptorClass.newInstance();
99 } catch (Exception e) {
100 log.error("Exception while attempting to instantiate the implementation of Cryptor: " + cryptorClass.getName() + "\n" + e.getMessage());
101 log.error(e);
102 }
103 }
104105return cryptor;
106 }
107 }