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.calendar;
13:
14: import com.sun.portal.app.calendarcommon.common.SharedServicesException;
15: import javax.faces.context.FacesContext;
16: import javax.portlet.PortletContext;
17:
18: /**
19: * Retrieves the SharedCalendarUtils from the provided portlet (servlet) context.
20: * The utils should bave already been created and placed on the context by SharedCalendarContextListener,
21: * during servlet inititialization.
22: *
23: * @author Nigel Jacobs
24: * @created June 6, 2005
25: *
26: */
27: public class SharedCalendarUtilsFactory {
28:
29: public static SharedCalendarUtils getSharedCalendarUtils(
30: PortletContext portletContext)
31: throws SharedServicesException {
32:
33: Object o = portletContext
34: .getAttribute(SharedCalendarUtils.SHARED_CAL_UTILS_CONTEXT_ATTR);
35: if ((o == null) || !(o instanceof SharedCalendarUtils)) {
36: throw new SharedServicesException(
37: "SharedCalendarUtils on servlet context is null or of wrong type: "
38: + o);
39: }
40: return (SharedCalendarUtils) o;
41:
42: }
43:
44: public static SharedCalendarUtils getSharedCalendarUtils(
45: FacesContext facesContext) throws SharedServicesException {
46: Object externalContext = facesContext.getExternalContext()
47: .getContext();
48: if (externalContext instanceof PortletContext) {
49: return getSharedCalendarUtils((PortletContext) externalContext);
50: } else {
51: throw new SharedServicesException(
52: "Can't getSharedCalendarUtils: only supporting Portlet environment.");
53: }
54: }
55:
56: }
|