01: /**
02: * Copyright 2002 Sun Microsystems, Inc. All
03: * rights reserved. Use of this product is subject
04: * to license terms. Federal Acquisitions:
05: * Commercial Software -- Government Users
06: * Subject to Standard License Terms and
07: * Conditions.
08: *
09: * Sun, Sun Microsystems, the Sun logo, and iPlanet
10: * are trademarks or registered trademarks of Sun Microsystems,
11: * Inc. in the United States and other countries.
12: */package com.sun.portal.app.calendarcommon.common;
13:
14: import javax.faces.context.FacesContext;
15: import javax.portlet.PortletContext;
16:
17: /**
18: * Retrieves the SharedServicesUtils from the provided portlet (servlet) context.
19: * The utils should bave already been created and placed on the context by SharedServicesContextListener,
20: * during servlet inititialization.
21: *
22: * @author Nigel Jacobs
23: * @created June 6, 2005
24: *
25: */
26: public class SharedServicesUtilsFactory {
27:
28: public static SharedServicesUtils getSharedServicesUtils(
29: PortletContext portletContext)
30: throws SharedServicesException {
31:
32: Object o = portletContext
33: .getAttribute(SharedServicesUtils.SHARED_SVCS_UTILS_CONTEXT_ATTR);
34: if ((o == null) || !(o instanceof SharedServicesUtils)) {
35: throw new SharedServicesException(
36: "SharedServicesUtils on servlet context is null or of wrong type: "
37: + o);
38: }
39: return (SharedServicesUtils) o;
40:
41: }
42:
43: public static SharedServicesUtils getSharedServicesUtils(
44: FacesContext facesContext) throws SharedServicesException {
45: Object externalContext = facesContext.getExternalContext()
46: .getContext();
47: if (externalContext instanceof PortletContext) {
48: return getSharedServicesUtils((PortletContext) externalContext);
49: } else {
50: throw new SharedServicesException(
51: "Can't getSharedServicesUtils: only supporting Portlet environment.");
52: }
53: }
54:
55: }
|