01: /*
02: * ServiceRegistryFactory.java
03: *
04: * Created on January 11, 2005, 1:28 PM
05: */
06:
07: package com.sun.portal.service.serviceregistry;
08:
09: import javax.servlet.http.HttpServletRequest;
10:
11: import com.sun.portal.service.common.ServiceConfig;
12:
13: /**
14: *
15: * @author mjain
16: */
17: public class ServiceRegistryFactory {
18:
19: public static ServiceRegistryFactory _instance;
20:
21: ServiceRegistryFactory() {
22: }
23:
24: public static void init() {
25: _instance = new ServiceRegistryFactory();
26: }
27:
28: public static ServiceRegistryFactory getInstance() {
29: return _instance;
30: }
31:
32: /**
33: * Get an instance of ServiceRegistry from a servlet.
34: *
35: * @param request a <code>HttpServletRequest</code> to be used for establishing user context.
36: * @return a <code>ServiceRegistry</code> value
37: * @exception ServiceException if an error occurs
38: */
39: public ServiceRegistry getServiceRegistry(HttpServletRequest request)
40: throws ServiceRegistryException {
41:
42: ServiceConfig config = ServiceConfig.getInstance();
43:
44: String srClassname = config.getServiceRegistryClassname();
45: ServiceRegistry sr = loadServiceRegistryClass(srClassname);
46: sr.init(request);
47:
48: return sr;
49: }
50:
51: /**
52: * Get an instance of ServiceRegistry using credentials supplied
53: * in a form of username and password.
54: *
55: * @param consumerId a <code>String</code> value identifying the consumer entity
56: * @param username user id for establishing user context
57: * @param password user password for establishing user context
58: * @return a <code>ServiceRegistry</code> value
59: * @exception ServiceException if an error occurs
60: */
61: public ServiceRegistry getServiceRegistry(String username,
62: String password) throws ServiceRegistryException {
63:
64: ServiceConfig config = ServiceConfig.getInstance();
65:
66: String srClassname = config.getServiceRegistryClassname();
67: ServiceRegistry sr = loadServiceRegistryClass(srClassname);
68: sr.init(username, password);
69:
70: return sr;
71: }
72:
73: protected ServiceRegistry loadServiceRegistryClass(String classname)
74: throws ServiceRegistryException {
75:
76: ServiceRegistry sr = null;
77: try {
78: sr = (ServiceRegistry) (Class.forName(classname)
79: .newInstance());
80: } catch (Exception ex) {
81: throw new ServiceRegistryException(
82: "ServiceRegistryFactory.loadServiceRegistryClass(): failed to load sr class.",
83: ex);
84: }
85:
86: return sr;
87: }
88:
89: }
|