01: /* $Id: EventResponseImpl.java,v 1.3 2006/02/27 05:03:02 vs152012 Exp $
02: * Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
03: * Use is subject to license terms.
04: */
05: package com.sun.portal.portlet.impl;
06:
07: import com.sun.portal.portletappengine.ipc.EventResponse;
08: import com.sun.portal.portletcontainercommon.PortletContainerEventResponse;
09:
10: import java.util.Collections;
11: import java.util.HashMap;
12: import java.util.Map;
13: import java.util.Iterator;
14:
15: public class EventResponseImpl extends PortletResponseImpl implements
16: EventResponse {
17: private PortletContainerEventResponse pceResponse = null;
18:
19: void init(PortletContainerEventResponse pceResponse) {
20: this .pceResponse = pceResponse;
21: }
22:
23: public void setRenderParameters(Map parmMap) {
24: if (parmMap == null) {
25: throw new IllegalArgumentException(
26: "The passed in map should not be null");
27: }
28: //Check if all the params are Strings and corresponding values are String[]
29: Iterator keys = parmMap.keySet().iterator();
30: while (keys.hasNext()) {
31: Object key = keys.next();
32: if (!(key instanceof String))
33: throw new IllegalArgumentException(
34: "The keys in the map must be of type String");
35: Object value = parmMap.get(key);
36: if (!(value instanceof String[]))
37: throw new IllegalArgumentException(
38: "The values in the map must be of type String[]");
39: }
40: pceResponse.setRenderParameters(parmMap);
41: }
42:
43: public void setRenderParameter(String key, String value) {
44: if (key == null || value == null) {
45: throw new IllegalArgumentException(
46: "Key or value argument should not be null.");
47: }
48:
49: Map renderMap = pceResponse.getRenderParameters();
50: String[] values = new String[1];
51: values[0] = value;
52: if (renderMap == null || renderMap == Collections.EMPTY_MAP) {
53: renderMap = new HashMap();
54: renderMap.put(key, values);
55: pceResponse.setRenderParameters(renderMap);
56: } else {
57: renderMap.put(key, values);
58: pceResponse.setRenderParameters(renderMap);
59: }
60:
61: }
62:
63: public void setRenderParameter(String key, String[] values) {
64: if (key == null || values == null) {
65: throw new IllegalArgumentException(
66: "Key or values argument should not be null.");
67: }
68: Map renderMap = pceResponse.getRenderParameters();
69: if (renderMap == null || renderMap == Collections.EMPTY_MAP) {
70: renderMap = new HashMap();
71: renderMap.put(key, values);
72: pceResponse.setRenderParameters(renderMap);
73: } else {
74: renderMap.put(key, values);
75: pceResponse.setRenderParameters(renderMap);
76: }
77: }
78:
79: public void clear() {
80: super.clear();
81: pceResponse = null;
82: }
83: }
|