01: package org.manentia.kasai.services;
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 AuthServiceFactory {
12:
13: public static AuthService getAuthService(String serviceClass)
14: throws ServiceNotAvailableException {
15: AuthService service = null;
16:
17: try {
18: service = (AuthService) Class.forName(serviceClass)
19: .newInstance();
20: } catch (ClassNotFoundException e) {
21: Log.write("Class not found", e, Log.ERROR,
22: "getAuthService", AuthServiceFactory.class);
23:
24: throw new ServiceNotAvailableException(
25: AuthServiceFactory.class.getName()
26: + ".classNotFound", e);
27: } catch (InstantiationException e) {
28: Log
29: .write(
30: "Error initializing service, it doesn't have a correct constructor",
31: e, Log.ERROR, "getAuthService",
32: AuthServiceFactory.class);
33:
34: throw new ServiceNotAvailableException(
35: AuthServiceFactory.class.getName()
36: + ".instantiationError", e);
37: } catch (IllegalAccessException e) {
38: Log
39: .write(
40: "Error initializing service, it doesn't have a public constructor",
41: e, Log.ERROR, "getAuthService",
42: AuthServiceFactory.class);
43:
44: throw new ServiceNotAvailableException(
45: AuthServiceFactory.class.getName()
46: + ".instantiationError", e);
47: }
48:
49: return service;
50: }
51:
52: }
|