001: /*
002: * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions
006: * are met:
007: *
008: * - Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: *
011: * - Redistribution in binary form must reproduce the above copyright
012: * notice, this list of conditions and the following disclaimer in
013: * the documentation and/or other materials provided with the
014: * distribution.
015: *
016: * Neither the name of Sun Microsystems, Inc. or the names of
017: * contributors may be used to endorse or promote products derived
018: * from this software without specific prior written permission.
019: *
020: * This software is provided "AS IS," without a warranty of any
021: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
022: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
023: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
024: * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
025: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
026: * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
027: * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
028: * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
029: * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
030: * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE,
031: * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
032: *
033: * You acknowledge that Software is not designed, licensed or intended
034: * for use in the design, construction, operation or maintenance of
035: * any nuclear facility.
036: */
037:
038: package com.sun.portal.portlet.ipc2;
039:
040: import com.sun.portal.portletappengine.ipc.EventRequest;
041: import com.sun.portal.portletappengine.ipc.EventResponse;
042: import com.sun.portal.portletappengine.ipc.PortletEvent;
043: import com.sun.portal.portletappengine.ipc.PortletEventBroker;
044: import com.sun.portal.portletappengine.ipc.PortletEventListener;
045:
046: import javax.portlet.ActionRequest;
047: import javax.portlet.ActionResponse;
048: import javax.portlet.GenericPortlet;
049: import javax.portlet.PortletConfig;
050: import javax.portlet.PortletContext;
051: import javax.portlet.PortletException;
052: import javax.portlet.PortletRequestDispatcher;
053: import javax.portlet.RenderRequest;
054: import javax.portlet.RenderResponse;
055: import java.io.IOException;
056:
057: /**
058: * The PricePortlet participates in the InterPortletCommunication.
059: * This generates the event that is consumed by two portlets
060: * (a)ConsiderationPortlet which is in a different web application
061: * (b)DecisionPortlet which is in the same web application
062: * This also consumes the event generated by the DecisionPortlet.
063: */
064: public class PricePortlet extends GenericPortlet implements
065: PortletEventListener {
066: private PortletContext pContext;
067:
068: public void init(PortletConfig config) throws PortletException {
069: super .init(config);
070: pContext = config.getPortletContext();
071: }
072:
073: public void doView(RenderRequest request, RenderResponse response)
074: throws PortletException, IOException {
075: String contentPage = "/priceportlet/content.jsp";
076: response.setContentType(request.getResponseContentType());
077: if (contentPage != null && contentPage.length() != 0) {
078: try {
079: PortletRequestDispatcher dispatcher = pContext
080: .getRequestDispatcher(contentPage);
081: dispatcher.include(request, response);
082: } catch (IOException e) {
083: throw new PortletException(
084: "PricePortlet.doView exception", e);
085: }
086: }
087: }
088:
089: public void processAction(ActionRequest request,
090: ActionResponse actionResponse) throws PortletException,
091: java.io.IOException {
092: PortletEventBroker peb = new PortletEventBroker(request);
093: try {
094: PortletEvent pe = peb.createEvent("priceChanged");
095: String price = null;
096: Object obj = request.getParameter("price");
097: if (obj != null) {
098: price = (String) obj;
099: } else {
100: price = "9999";
101: }
102: pe.setEventData(price);
103: pe.fire();
104:
105: PortletEvent pe2 = peb.createEvent("priceChanged2");
106: pe2.setEventData("700");
107: pe2.fire();
108:
109: PortletEvent pe3 = peb.createEvent("priceChanged3");
110: pe3.setEventData("800");
111: pe3.fire();
112:
113: } catch (Exception e) {
114: //Do nothing!
115: }
116: actionResponse.setRenderParameters(request.getParameterMap());
117: }
118:
119: public void handleEvent(EventRequest ereq, EventResponse eres) {
120: //Get the event name
121: String eventName = ereq.getEventName();
122: if (eventName.equalsIgnoreCase("highPriceEvent")) {
123: String data = (String) ereq.getEventData();
124: eres.setRenderParameter("data", data);
125: } else if (eventName.equalsIgnoreCase("lowPriceEvent")) {
126: String data = "lowPriceEvent";
127: eres.setRenderParameter("data", data);
128: } else if (eventName
129: .equalsIgnoreCase(PortletEvent.EVENT_HANDLING_FAILED)) {
130: String data = "eventHandlingFailed";
131: eres.setRenderParameter("data", data);
132: }
133: }
134: }
|