Source Code Cross Referenced for ResultObjectBasedEventFactory.java in  » Workflow-Engines » spring-webflow-1.0.4 » org » springframework » webflow » action » 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 » Workflow Engines » spring webflow 1.0.4 » org.springframework.webflow.action 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004-2007 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.springframework.webflow.action;
017:
018:        import org.springframework.core.JdkVersion;
019:        import org.springframework.core.enums.LabeledEnum;
020:        import org.springframework.webflow.execution.Event;
021:        import org.springframework.webflow.execution.RequestContext;
022:        import org.springframework.webflow.execution.support.EventFactorySupport;
023:
024:        /**
025:         * Result object-to-event adapter interface that tries to do a 
026:         * sensible conversion of the result object into a web flow event.
027:         * It uses the following conversion table:
028:         * <table border="1">
029:         * <tr>
030:         * <th>Result object type</th>
031:         * <th>Event id</th>
032:         * <th>Remarks</th>
033:         * </tr>
034:         * <tr>
035:         * <td>null</td>
036:         * <td>{@link org.springframework.webflow.execution.support.EventFactorySupport#getNullEventId()}</td>
037:         * <td>&nbsp;</td>
038:         * </tr>
039:         * <tr>
040:         * <td>{@link java.lang.Boolean} or boolean</td>
041:         * <td>{@link org.springframework.webflow.execution.support.EventFactorySupport#getYesEventId()}/
042:         * {@link org.springframework.webflow.execution.support.EventFactorySupport#getNoEventId()}</td>
043:         * <td>&nbsp;</td>
044:         * </tr>
045:         * <tr>
046:         * <td>{@link org.springframework.core.enums.LabeledEnum}</td>
047:         * <td>{@link org.springframework.core.enums.LabeledEnum#getLabel()}</td>
048:         * <td>The result object will included in the event as an attribute
049:         * named "result".</td>
050:         * </tr>
051:         * <tr>
052:         * <td>{@link java.lang.Enum}</td>
053:         * <td>{@link java.lang.Enum#name()}</td>
054:         * <td>The result object will included in the event as an attribute
055:         * named "result".</td>
056:         * </tr>
057:         * <tr>
058:         * <td>{@link java.lang.String}</td>
059:         * <td>The string.</td>
060:         * <td>&nbsp;</td>
061:         * </tr>
062:         * <tr>
063:         * <td>{@link org.springframework.webflow.execution.Event}</td>
064:         * <td>The resulting event object.</td>
065:         * <td>&nbsp;</td>
066:         * </tr>
067:         * </table>
068:         * 
069:         * @author Keith Donald
070:         * @author Erwin Vervaet
071:         */
072:        public class ResultObjectBasedEventFactory extends EventFactorySupport
073:                implements  ResultEventFactory {
074:
075:            public Event createResultEvent(Object source, Object resultObject,
076:                    RequestContext context) {
077:                if (resultObject == null) {
078:                    // this handles the case where the declared result return type is mapped
079:                    // by this class but the value is null
080:                    return event(source, getNullEventId());
081:                } else if (isBoolean(resultObject.getClass())) {
082:                    return event(source, ((Boolean) resultObject)
083:                            .booleanValue());
084:                } else if (isLabeledEnum(resultObject.getClass())) {
085:                    String resultId = ((LabeledEnum) resultObject).getLabel();
086:                    return event(source, resultId, getResultAttributeName(),
087:                            resultObject);
088:                } else if (isJdk5Enum(resultObject.getClass())) {
089:                    String eventId = EnumNameResolver.getEnumName(resultObject);
090:                    return event(source, eventId, getResultAttributeName(),
091:                            resultObject);
092:                } else if (isString(resultObject.getClass())) {
093:                    return event(source, (String) resultObject);
094:                } else if (isEvent(resultObject.getClass())) {
095:                    return (Event) resultObject;
096:                } else {
097:                    throw new IllegalArgumentException(
098:                            "Cannot deal with result object '" + resultObject
099:                                    + "' of type '" + resultObject.getClass()
100:                                    + "'");
101:                }
102:            }
103:
104:            /**
105:             * Check whether or not given type is mapped to a corresponding
106:             * event using special mapping rules.
107:             */
108:            public boolean isMappedValueType(Class type) {
109:                return isBoolean(type) || isLabeledEnum(type)
110:                        || isJdk5Enum(type) || isString(type) || isEvent(type);
111:            }
112:
113:            // internal helpers to determine the 'type' of a class
114:
115:            private boolean isBoolean(Class type) {
116:                return Boolean.class.equals(type) || boolean.class.equals(type);
117:            }
118:
119:            private boolean isLabeledEnum(Class type) {
120:                return LabeledEnum.class.isAssignableFrom(type);
121:            }
122:
123:            private boolean isJdk5Enum(Class type) {
124:                if (JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_15) {
125:                    return type.isEnum();
126:                } else {
127:                    return false;
128:                }
129:            }
130:
131:            private boolean isString(Class type) {
132:                return String.class.equals(type);
133:            }
134:
135:            private boolean isEvent(Class type) {
136:                return Event.class.isAssignableFrom(type);
137:            }
138:
139:            /**
140:             * Simple helper class with Java 5 specific code factored out to keep
141:             * the containing class JDK 1.3 compatible.
142:             */
143:            private static class EnumNameResolver {
144:                public static String getEnumName(Object enumValue) {
145:                    return ((java.lang.Enum) enumValue).name();
146:                }
147:            }
148:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.