KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > manentia > kasai > services > AuthServiceFactory


1 package org.manentia.kasai.services;
2
3 import org.apache.commons.lang.exception.ExceptionUtils;
4 import org.manentia.kasai.util.Constants;
5 import org.manentia.kasai.exceptions.ServiceNotAvailableException;
6
7 import com.koala.commons.log.Log;
8
9 /**
10  *
11  * @author rzuasti
12  */

13 public class AuthServiceFactory {
14     
15     public static AuthService getAuthService(String JavaDoc serviceClass) throws ServiceNotAvailableException {
16         AuthService service = null;
17         
18         try {
19             service = (AuthService) Class.forName(serviceClass).newInstance();
20         }
21         catch (ClassNotFoundException JavaDoc e){
22                 Log.getInstance(Constants.PROPERTY_FILE).write(AuthServiceFactory.class.getName(), "getAuthService",
23                     "Class not found (" +
24                     ExceptionUtils.getStackTrace(e) + ")",
25                     java.util.logging.Level.SEVERE);
26                  
27                 throw new ServiceNotAvailableException(AuthServiceFactory.class.getName() + ".classNotFound", e);
28         }
29         catch (InstantiationException JavaDoc e){
30                 Log.getInstance(Constants.PROPERTY_FILE).write(AuthServiceFactory.class.getName(), "getAuthService",
31                     "Error initializing service, it doesn't have a correct constructor (" +
32                     ExceptionUtils.getStackTrace(e) + ")",
33                     java.util.logging.Level.SEVERE);
34                  
35                 throw new ServiceNotAvailableException(AuthServiceFactory.class.getName() + ".instantiationError", e);
36         }
37         catch (IllegalAccessException JavaDoc e){
38                 Log.getInstance(Constants.PROPERTY_FILE).write(AuthServiceFactory.class.getName(), "getAuthService",
39                     "Error initializing service, it doesn't have a public constructor (" +
40                     ExceptionUtils.getStackTrace(e) + ")",
41                     java.util.logging.Level.SEVERE);
42                  
43                 throw new ServiceNotAvailableException(AuthServiceFactory.class.getName() + ".instantiationError", e);
44         }
45      
46         return service;
47     }
48     
49 }
50
Popular Tags