Source Code Cross Referenced for NewAction.java in  » Development » ivatamasks » com » ivata » mask » web » struts » 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 » Development » ivatamasks » com.ivata.mask.web.struts 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2001 - 2005 ivata limited.
003:         * All rights reserved.
004:         * -----------------------------------------------------------------------------
005:         * ivata masks may be redistributed under the GNU General Public
006:         * License as published by the Free Software Foundation;
007:         * version 2 of the License.
008:         *
009:         * These programs are free software; you can redistribute them and/or
010:         * modify them under the terms of the GNU General Public License
011:         * as published by the Free Software Foundation; version 2 of the License.
012:         *
013:         * These programs are distributed in the hope that they will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016:         *
017:         * See the GNU General Public License in the file LICENSE.txt for more
018:         * details.
019:         *
020:         * If you would like a copy of the GNU General Public License write to
021:         *
022:         * Free Software Foundation, Inc.
023:         * 59 Temple Place - Suite 330
024:         * Boston, MA 02111-1307, USA.
025:         *
026:         *
027:         * To arrange commercial support and licensing, contact ivata at
028:         *                  http://www.ivata.com/contact.jsp
029:         * -----------------------------------------------------------------------------
030:         * $Log: NewAction.java,v $
031:         * Revision 1.11  2005/10/11 18:54:06  colinmacleod
032:         * Fixed some checkstyle and javadoc issues.
033:         *
034:         * Revision 1.10  2005/10/09 09:55:17  colinmacleod
035:         * Merged changes from ivata masks v0.6.2 into main trunk.
036:         *
037:         * Revision 1.9  2005/10/03 10:17:25  colinmacleod
038:         * Fixed some style and javadoc issues.
039:         *
040:         * Revision 1.8  2005/10/02 14:06:34  colinmacleod
041:         * Added/improved log4j logging.
042:         *
043:         * Revision 1.7.2.1  2005/10/08 10:54:23  colinmacleod
044:         * Added temporary workarounds for bugs in ivata groupware v0.11.x
045:         *
046:         * Revision 1.7  2005/04/11 14:53:28  colinmacleod
047:         * Added defaulting of class name to base class
048:         * name.
049:         *
050:         * Revision 1.6  2005/04/09 18:04:19  colinmacleod
051:         * Changed copyright text to GPL v2 explicitly.
052:         *
053:         * Revision 1.5  2005/01/19 13:14:02  colinmacleod
054:         * Renamed CausedByException to SystemException.
055:         *
056:         * Revision 1.4  2005/01/07 08:08:25  colinmacleod
057:         * Moved up a version number.
058:         * Changed copyright notices to 2005.
059:         * Updated the documentation:
060:         *   - started working on multiproject:site docu.
061:         *   - changed the logo.
062:         * Added checkstyle and fixed LOADS of style issues.
063:         * Added separate thirdparty subproject.
064:         * Added struts (in web), util and webgui (in webtheme) from ivata op.
065:         *
066:         * Revision 1.3  2004/12/29 15:32:20  colinmacleod
067:         * List/input mask actions are no longer hard-coded.
068:         * Overrides added via request parameters - defaults via new methods on the
069:         factory.
070:         *
071:         * Revision 1.2  2004/05/19 20:34:17  colinmacleod
072:         * Added methods to add, amend and remove value objects.
073:         *
074:         * Revision 1.1.1.1  2004/05/16 20:40:32  colinmacleod
075:         * Ready for 0.1 release
076:         * -----------------------------------------------------------------------------
077:         */
078:        package com.ivata.mask.web.struts;
079:
080:        import org.apache.log4j.Logger;
081:
082:        import javax.servlet.http.HttpServletRequest;
083:        import javax.servlet.http.HttpServletResponse;
084:        import javax.servlet.http.HttpSession;
085:        import org.apache.struts.action.ActionForm;
086:        import org.apache.struts.action.ActionMapping;
087:        import org.sourceforge.clientsession.ClientSession;
088:
089:        import com.ivata.mask.Mask;
090:        import com.ivata.mask.MaskFactory;
091:        import com.ivata.mask.util.SystemException;
092:        import com.ivata.mask.valueobject.ValueObject;
093:
094:        /**
095:         * <p>
096:         * Create a new value object and create a form for it in the request scope.
097:         * </p>
098:         *
099:         * @since ivata masks 0.1 (2004-05-10)
100:         * @author Colin MacLeod
101:         * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
102:         * @version $Revision: 1.11 $
103:         */
104:        public class NewAction extends MaskAction {
105:            /**
106:             * Logger for this class.
107:             */
108:            private static final Logger logger = Logger
109:                    .getLogger(NewAction.class);
110:
111:            /**
112:             * <p>
113:             * This factory is needed to access the masks and groups of masks.
114:             * </p>
115:             */
116:            private MaskFactory maskFactory;
117:
118:            /**
119:             * <p>
120:             * Construct an action to create new value objects.
121:             * </p>
122:             *
123:             * @param maskFactoryParam {@inheritDoc}
124:             * @param authenticatorParam {@inheritDoc}
125:             */
126:            public NewAction(final MaskFactory maskFactoryParam,
127:                    final MaskAuthenticator authenticatorParam) {
128:                super (maskFactoryParam, authenticatorParam);
129:                this .maskFactory = maskFactoryParam;
130:            }
131:
132:            /**
133:             * <p>
134:             * Override this method to create a different class of input mask form.
135:             * </p>
136:             *
137:             * @param requestParam
138:             * <copyDoc>Refer to {@link InputMaskForm#InputMaskForm}.</copyDoc>
139:             * @param valueObjectParam
140:             * <copyDoc>Refer to {@link InputMaskForm#InputMaskForm}.</copyDoc>
141:             * @param maskParam
142:             * <copyDoc>Refer to {@link InputMaskForm#InputMaskForm}.</copyDoc>
143:             * @param baseClassParam
144:             * <copyDoc>Refer to {@link InputMaskForm#InputMaskForm}.</copyDoc>
145:             * @return new input mask form instance.
146:             */
147:            protected InputMaskForm createInputMaskForm(
148:                    final HttpServletRequest requestParam,
149:                    final ValueObject valueObjectParam, final Mask maskParam,
150:                    final Class baseClassParam) {
151:                if (logger.isDebugEnabled()) {
152:                    logger
153:                            .debug("createInputMaskForm(HttpServletRequest requestParam = "
154:                                    + requestParam
155:                                    + ", ValueObject valueObjectParam = "
156:                                    + valueObjectParam
157:                                    + ", Mask maskParam = "
158:                                    + maskParam
159:                                    + ", Class baseClassParam = "
160:                                    + baseClassParam + ") - start");
161:                }
162:
163:                InputMaskForm returnInputMaskForm = new InputMaskForm(
164:                        valueObjectParam, maskParam, baseClassParam);
165:                if (logger.isDebugEnabled()) {
166:                    logger.debug("createInputMaskForm - end - return value = "
167:                            + returnInputMaskForm);
168:                }
169:                return returnInputMaskForm;
170:            }
171:
172:            /**
173:             * <p>
174:             * Generic method called by the <strong>Struts </strong> interface. Creates
175:             * the value object and a form. Always returns success.
176:             * </p>
177:             *
178:             * @param mapping {@inheritDoc}
179:             * @param form {@inheritDoc}
180:             * @param request {@inheritDoc}
181:             * @param response {@inheritDoc}
182:             * @param session {@inheritDoc}
183:             * @param clientSession {@inheritDoc}
184:             * @throws SystemException If a new value object cannot be created.
185:             * @return &quot;success&quot; if successful, otherwise <code>null</code>.
186:             */
187:            public String execute(final ActionMapping mapping,
188:                    final ActionForm form, final HttpServletRequest request,
189:                    final HttpServletResponse response,
190:                    final HttpSession session, final ClientSession clientSession)
191:                    throws SystemException {
192:                if (logger.isDebugEnabled()) {
193:                    logger.debug("execute(ActionMapping mapping = " + mapping
194:                            + ", ActionForm form = " + form
195:                            + ", HttpServletRequest request = " + request
196:                            + ", HttpServletResponse response = " + response
197:                            + ", HttpSession session = " + session
198:                            + ", ClientSession clientSession = "
199:                            + clientSession + ") - start");
200:                }
201:
202:                String className = request.getParameter("className");
203:                String baseClassName = request.getParameter("baseClass");
204:                if (className == null) {
205:                    className = baseClassName;
206:                }
207:                if (className == null) {
208:                    throw new NullPointerException(
209:                            "ERROR in NewAction: you must "
210:                                    + "specify a request parameter called 'className'.");
211:                }
212:                Class valueObjectClass;
213:                try {
214:                    valueObjectClass = Class.forName(className);
215:                } catch (ClassNotFoundException e) {
216:                    logger.error("execute - could not find class '" + className
217:                            + "'", e);
218:                    throw new ValueObjectException(e);
219:                }
220:                ValueObject valueObject;
221:                try {
222:                    valueObject = (ValueObject) valueObjectClass.newInstance();
223:                } catch (InstantiationException e) {
224:                    logger.error("execute - could not instantiate "
225:                            + valueObjectClass, e);
226:                    throw new ValueObjectException(e, valueObjectClass);
227:                } catch (IllegalAccessException e) {
228:                    logger.error("execute - could not instantiate "
229:                            + valueObjectClass, e);
230:                    throw new ValueObjectException(e, valueObjectClass);
231:                }
232:                // default the base class name to the class name: if you want, they
233:                // can be different, but the class must be a subclass of the base
234:                // class
235:                if (baseClassName == null) {
236:                    baseClassName = className;
237:                }
238:                Class baseClass;
239:                try {
240:                    baseClass = Class.forName(baseClassName);
241:                } catch (ClassNotFoundException e) {
242:                    logger.error("execute - could not create class '"
243:                            + baseClassName + "'", e);
244:                    throw new ValueObjectException(e);
245:                }
246:                Mask mask = maskFactory.getMask(baseClass, getInputMask(
247:                        request, form));
248:                InputMaskForm inputMaskForm;
249:                if (form instanceof  InputMaskForm) {
250:                    inputMaskForm = (InputMaskForm) form;
251:                } else {
252:                    inputMaskForm = createInputMaskForm(request, valueObject,
253:                            mask, baseClass);
254:                }
255:                request.setAttribute(InputMaskForm.REQUEST_ATTRIBUTE,
256:                        inputMaskForm);
257:
258:                if (logger.isDebugEnabled()) {
259:                    logger.debug("execute - end - return value = success");
260:                }
261:                return "success";
262:            }
263:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.