01: /*
02: * (C) Copyright 2006 Nabh Information Systems, Inc.
03: *
04: * All copyright notices regarding Nabh's products MUST remain
05: * intact in the scripts and in the outputted HTML.
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public License
08: * as published by the Free Software Foundation; either version 2.1
09: * of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19: *
20: */
21: package com.nabhinc.portlet.mvcportlet.beanutil;
22:
23: import java.lang.reflect.Method;
24: import java.util.Collection;
25: import java.util.Iterator;
26:
27: import javax.portlet.ActionRequest;
28: import javax.portlet.ActionResponse;
29: import javax.portlet.PortletException;
30: import javax.portlet.PortletRequest;
31:
32: import org.w3c.dom.Element;
33:
34: import com.nabhinc.portlet.mvcportlet.core.ControllerPortletConfig;
35: import com.nabhinc.portlet.mvcportlet.core.ParameterSetter;
36:
37: /**
38: *
39: *
40: * @author Padmanabh Dabke
41: * (c) 2006 Nabh Information Systems, Inc. All Rights Reserved.
42: * @since 1.1
43: */
44: public class CollectionParameterSetter extends BaseParameterSetter {
45: private ParameterSetter afElementFormatter = null;
46:
47: public CollectionParameterSetter(ParameterSetter elemFormatter,
48: Method m) {
49: super (m);
50: afElementFormatter = elemFormatter;
51: }
52:
53: public void setParameters(ActionRequest request,
54: ActionResponse response, String paramName, Object target,
55: String propertyName) throws PortletException {
56: Collection value;
57: try {
58: value = (Collection) bpsGetMethod.invoke(target, bpsArgs);
59: } catch (Exception e) {
60: throw new PortletException("Failed to retrieve property: "
61: + propertyName, e);
62: }
63: if (value == null)
64: return;
65: int size = value.size();
66: String[] stringArray = new String[size];
67: Iterator iter = value.iterator();
68: int i = 0;
69: while (iter.hasNext()) {
70: stringArray[i] = afElementFormatter.formatParameterValue(
71: request, iter.next());
72: i++;
73: }
74: response.setRenderParameter(paramName, stringArray);
75:
76: }
77:
78: public String formatParameterValue(PortletRequest request,
79: Object value) {
80: return null;
81: }
82:
83: public void init(Element xmlConfig, ControllerPortletConfig config)
84: throws PortletException {
85: // No initialization needed
86:
87: }
88:
89: }
|