01: package org.manentia.kasai.user.passwordvalidators;
02:
03: import org.manentia.kasai.exceptions.ServiceNotAvailableException;
04:
05: import com.manentia.commons.log.Log;
06:
07: /**
08: *
09: * @author rzuasti
10: */
11: public class PasswordValidatorFactory {
12:
13: public static PasswordValidator getPasswordValidator(
14: String validatorClass) throws ServiceNotAvailableException {
15: PasswordValidator validator = null;
16:
17: try {
18: validator = (PasswordValidator) Class.forName(
19: validatorClass).newInstance();
20: } catch (ClassNotFoundException e) {
21: Log.write("Class not found", e, Log.ERROR,
22: "getPasswordValidator",
23: PasswordValidatorFactory.class);
24:
25: throw new ServiceNotAvailableException(
26: PasswordValidatorFactory.class.getName()
27: + ".classNotFound", e);
28: } catch (InstantiationException e) {
29: Log
30: .write(
31: "Error initializing validator, it doesn't have a correct constructor",
32: e, Log.ERROR, "getPasswordValidator",
33: PasswordValidatorFactory.class);
34:
35: throw new ServiceNotAvailableException(
36: PasswordValidatorFactory.class.getName()
37: + ".instantiationError", e);
38: } catch (IllegalAccessException e) {
39: Log
40: .write(
41: "Error initializing validator, it doesn't have a public constructor",
42: e, Log.ERROR, "getPasswordValidator",
43: PasswordValidatorFactory.class);
44:
45: throw new ServiceNotAvailableException(
46: PasswordValidatorFactory.class.getName()
47: + ".instantiationError", e);
48: }
49:
50: return validator;
51: }
52:
53: }
|