001: /**
002: * $Id: GenericPortletProvisionListener.java,v 1.5 2007/02/06 22:10:19 pm95875 Exp $
003: * Copyright 2005 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.portlet.service.provision;
014:
015: import javax.servlet.ServletContext;
016: import javax.portlet.PortletContext;
017:
018: /**
019: * A convienence class implementing PortletProvisionListener.
020: * Listeners are configured for a portlet in sun-portlet.xml file. Methods on
021: * these listeners are invoked everytime the community including the portlet changes its state.
022: * Framework initializes the instance with the right PortletContext in the init() method.
023: */
024: public class GenericPortletProvisionListener implements
025: PortletProvisionListener {
026: private PortletContext _portletContext;
027: private ServletContext _servletContext;
028: private PortletProvisionPreferences _portletProvisionPreferences;
029:
030: /**
031: * Called by container when an instance is created. When overwritten, super.init(context) must
032: * be called to initialize it correctly.
033: * @param pc portlet context
034: * @exception com.sun.portal.portlet.service.provision.PortletProvisionException
035: */
036: public void init(PortletContext pc)
037: throws PortletProvisionException {
038: _portletContext = pc;
039: _servletContext = null;
040: }
041:
042: /**
043: * Called by container when an instance is created. When overwritten, super.init(context) must
044: * be called to initialize it correctly.
045: * @param pc portlet context
046: * @param sc servlet context
047: * @exception com.sun.portal.portlet.service.provision.PortletProvisionException
048: */
049: public void init(PortletContext pc, javax.servlet.ServletContext sc)
050: throws PortletProvisionException {
051: _portletContext = pc;
052: _servletContext = sc;
053: }
054:
055: /**
056: * Returns the Portlet Context
057: * @return PortletContext
058: */
059: public PortletContext getPortletContext() {
060: return _portletContext;
061: }
062:
063: /**
064: * Getter for property _servletContext.
065: * @return Value of property _servletContext.
066: */
067: public ServletContext getServletContext() {
068: return this ._servletContext;
069: }
070:
071: /**
072: * Method called when an instance of the portlet, for which this listener is configured, is added to the community.
073: * For backward compatibility, handleEvent calls this method when the event type is EVENT_TYPE_CREATED.
074: * We recommend not to use this method and instead overwrite the default implementation of handleEvent
075: * to handle all community event types.
076: * @deprecated Use handleEvent instead
077: * @param event provisioning event
078: * @exception com.sun.portal.portlet.service.provision.PortletProvisionException
079: */
080: public void provision(PortletProvisionEvent event)
081: throws PortletProvisionException {
082: // no-op
083: }
084:
085: /**
086: * Method called when an instance of the portlet, for which this listener is configured, is removed from the community.
087: * For backward compatibility, handleEvent calls this method when the event type is EVENT_TYPE_PURGED.
088: * We recommend not to use this method and instead overwrite the default implementation of handleEvent
089: * to handle all community event types.
090: * @deprecated Use handleEvent instead
091: * @param event provisioning event
092: * @exception com.sun.portal.portlet.service.provision.PortletProvisionException thrown when there is an application error.
093: */
094: public void unprovision(PortletProvisionEvent event)
095: throws PortletProvisionException {
096: //no-op
097: }
098:
099: /**
100: * Method called when a provisioning event happens.
101: * @param event provisioning event
102: * @exception com.sun.portal.portlet.service.provision.PortletProvisionException thrown when there is an application error.
103: */
104: public void handleProvisionEvent(PortletProvisionEvent event)
105: throws PortletProvisionException {
106: if (event.getType().equals(
107: PortletProvisionEvent.EVENT_TYPE_CREATED)) {
108: provision(event);
109: } else if (event.getType().equals(
110: PortletProvisionEvent.EVENT_TYPE_DESTROYED)) {
111: unprovision(event);
112: } else {
113: // nothing
114: }
115: }
116:
117: }
|