Source Code Cross Referenced for ParameterSetter.java in  » Portal » stringbeans-3.5 » com » nabhinc » portlet » mvcportlet » actionprocessor » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » stringbeans 3.5 » com.nabhinc.portlet.mvcportlet.actionprocessor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * (C) Copyright 2004 Nabh Information Systems, Inc.
003:         *
004:         * All copyright notices regarding Nabh's products MUST remain
005:         * intact in the scripts and in the outputted HTML.
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public License
008:         * as published by the Free Software Foundation; either version 2.1 
009:         * of the License, or (at your option) any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014:         * GNU Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
019:         *
020:         */
021:        package com.nabhinc.portlet.mvcportlet.actionprocessor;
022:
023:        import java.io.IOException;
024:        import java.lang.reflect.InvocationTargetException;
025:        import java.util.Collection;
026:        import java.util.Enumeration;
027:        import java.util.Iterator;
028:        import java.util.List;
029:        import java.util.Vector;
030:
031:        import javax.portlet.ActionRequest;
032:        import javax.portlet.ActionResponse;
033:        import javax.portlet.PortletException;
034:
035:        import org.w3c.dom.Element;
036:
037:        import com.nabhinc.portlet.mvcportlet.common.AttributeBeanCreator;
038:        import com.nabhinc.portlet.mvcportlet.common.BeanCreator;
039:        import com.nabhinc.portlet.mvcportlet.core.ActionConfig;
040:        import com.nabhinc.portlet.mvcportlet.core.ActionProcessor;
041:        import com.nabhinc.portlet.mvcportlet.core.BaseRequestProcessor;
042:        import com.nabhinc.portlet.mvcportlet.core.ControllerPortletConfig;
043:        import com.nabhinc.portlet.mvcportlet.core.Form;
044:        import com.nabhinc.portlet.mvcportlet.core.FormField;
045:        import com.nabhinc.util.ArrayIterator;
046:        import com.nabhinc.util.EnumerationIterator;
047:        import com.nabhinc.util.ReflectionUtil;
048:        import com.nabhinc.util.StringUtil;
049:        import com.nabhinc.util.XMLUtil;
050:
051:        /**
052:         * Sets render parameters derived from bean properties.
053:         * 
054:         * @author Padmanabh Dabke 
055:         * (c) 2006 Nabh Information Systems, Inc. All Rights Reserved.
056:         */
057:        public class ParameterSetter extends BaseRequestProcessor implements 
058:                ActionProcessor {
059:
060:            private BeanCreator psBeanCreator = new AttributeBeanCreator();
061:
062:            private Form[] psForms = null;
063:
064:            private class ParamInfo {
065:                // public PropertyFormatter formatter = FormatterFactory.getBaseFormatter();
066:
067:                public String propertyName = null;
068:
069:                public String parameterName = null;
070:
071:                public String idPropertyName = null;
072:            }
073:
074:            /**
075:             * Initialization.
076:             * 
077:             * @param config
078:             *            XML configuration element
079:             * @throws PortletException
080:             *             Thrown if sql parameter is not specified, "params" parameter
081:             *             is specified but corresponding "param-types" are not
082:             *             specified.
083:             */
084:            public void init(Element config, ControllerPortletConfig cpConfig)
085:                    throws PortletException {
086:                super .init(config, cpConfig);
087:
088:                Element beanElem = XMLUtil
089:                        .getSubElement(config, "bean-creator");
090:                if (beanElem != null) {
091:                    try {
092:                        BeanCreator bCreator = (BeanCreator) Class.forName(
093:                                beanElem.getAttribute("class")).newInstance();
094:                        bCreator.init(beanElem);
095:                        psBeanCreator = bCreator;
096:                    } catch (Exception e) {
097:                        throw new PortletException(
098:                                "Failed to create bean creator instance.", e);
099:                    }
100:                }
101:                String formStr = config.getAttribute("forms");
102:                if (formStr != null && formStr.length() > 0) {
103:                    String[] formNames = StringUtil.split(formStr, ",");
104:                    psForms = new Form[formNames.length];
105:                    for (int i = 0; i < formNames.length; i++) {
106:                        psForms[i] = brpConfig.getForm(formNames[i]);
107:                        if (psForms[i] == null) {
108:                            throw new PortletException("Bad form name "
109:                                    + formNames[i] + ".");
110:                        }
111:                    }
112:                }
113:            }
114:
115:            /**
116:             */
117:            public String process(ActionRequest request,
118:                    ActionResponse response, ActionConfig config)
119:                    throws PortletException, IOException {
120:
121:                Object bean = psBeanCreator.getBean(request);
122:                if (bean != null) {
123:                    if (psForms != null) {
124:                        for (int i = 0; i < psForms.length; i++) {
125:                            setParameters(psForms[i], request, response, bean);
126:                        }
127:
128:                    } else {
129:                        Form form = config.getForm();
130:                        if (form == null)
131:                            throw new PortletException(
132:                                    "Failed to locate a form associated with this action.");
133:                        setParameters(form, request, response, bean);
134:                    }
135:                }
136:                return "success";
137:
138:            }
139:
140:            private void setParameters(Form form, ActionRequest request,
141:                    ActionResponse response, Object bean)
142:                    throws PortletException {
143:                List fieldList = form.getFieldList();
144:                int i = 0;
145:                try {
146:                    for (i = 0; i < fieldList.size(); i++) {
147:                        FormField field = (FormField) fieldList.get(i);
148:                        Object prop = ReflectionUtil.getProperty(bean, field
149:                                .getPropertyName());
150:                        if (prop == null)
151:                            continue;
152:
153:                        // Check for collection types. For these create an iterator
154:                        // and set multiple values.
155:                        Iterator iter = null;
156:                        if (prop.getClass().isArray()) {
157:                            iter = new ArrayIterator(prop);
158:                        } else if (prop instanceof  Collection) {
159:                            iter = (((Collection) prop).iterator());
160:                        } else if (prop instanceof  Iterator) {
161:                            iter = ((Iterator) prop);
162:                        } else if (prop instanceof  Enumeration) {
163:                            iter = new EnumerationIterator((Enumeration) prop);
164:                        }
165:
166:                        if (iter == null) {
167:                            // Single value property
168:                            if (field.getIdPropertyName() != null) {
169:                                prop = ReflectionUtil.getProperty(prop, field
170:                                        .getIdPropertyName());
171:                            }
172:                            String paramValue = field.getParameterSetter()
173:                                    .formatParameterValue(request, prop);
174:                            response.setRenderParameter(field.getName(),
175:                                    paramValue);
176:                        } else {
177:                            Vector valueVec = new Vector(5);
178:                            while (iter.hasNext()) {
179:                                Object paramValueObj = iter.next();
180:                                if (paramValueObj == null)
181:                                    continue;
182:                                if (field.getIdPropertyName() != null) {
183:                                    paramValueObj = ReflectionUtil.getProperty(
184:                                            paramValueObj, field
185:                                                    .getIdPropertyName());
186:                                }
187:                                String paramValue = field.getParameterSetter()
188:                                        .formatParameterValue(request,
189:                                                paramValueObj);
190:                                valueVec.addElement(paramValue);
191:                            }
192:                            if (valueVec.size() > 0) {
193:                                String[] paramValues = new String[valueVec
194:                                        .size()];
195:                                valueVec.copyInto(paramValues);
196:                                response.setRenderParameter(field.getName(),
197:                                        paramValues);
198:                            }
199:                        }
200:                    }
201:                } catch (IllegalAccessException e) {
202:                    throw new PortletException(
203:                            "Failed to access bean property "
204:                                    + ((FormField) fieldList.get(i))
205:                                            .getPropertyName(), e);
206:                } catch (InvocationTargetException e) {
207:                    throw new PortletException(
208:                            "Failed to access bean property "
209:                                    + ((FormField) fieldList.get(i))
210:                                            .getPropertyName(), e);
211:                } catch (IllegalArgumentException e) {
212:                    throw new PortletException(
213:                            "Failed to access bean property "
214:                                    + ((FormField) fieldList.get(i))
215:                                            .getPropertyName(), e);
216:                }
217:
218:            }
219:
220:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.