Source Code Cross Referenced for DispatchMethodInvoker.java in  » Workflow-Engines » spring-webflow-1.0.4 » org » springframework » webflow » util » 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.util 
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.util;
017:
018:        import java.lang.reflect.InvocationTargetException;
019:        import java.lang.reflect.Method;
020:        import java.util.Map;
021:
022:        import org.springframework.binding.method.InvalidMethodKeyException;
023:        import org.springframework.binding.method.MethodKey;
024:        import org.springframework.core.NestedRuntimeException;
025:        import org.springframework.util.Assert;
026:        import org.springframework.util.CachingMapDecorator;
027:
028:        /**
029:         * Invoker and cache for dispatch methods that all share the same target object.
030:         * The dispatch methods typically share the same form, but multiple exist per
031:         * target object, and they only differ in name.
032:         * 
033:         * @author Keith Donald
034:         * @author Ben Hale
035:         */
036:        public class DispatchMethodInvoker {
037:
038:            /**
039:             * The target object to dispatch to.
040:             */
041:            private Object target;
042:
043:            /**
044:             * The parameter types describing the dispatch method signature.
045:             */
046:            private Class[] parameterTypes;
047:
048:            /**
049:             * The resolved method cache.
050:             */
051:            private Map methodCache = new CachingMapDecorator() {
052:                public Object create(Object key) {
053:                    String methodName = (String) key;
054:                    try {
055:                        return new MethodKey(target.getClass(), methodName,
056:                                parameterTypes).getMethod();
057:                    } catch (InvalidMethodKeyException e) {
058:                        throw new MethodLookupException(
059:                                "Unable to resolve dispatch method "
060:                                        + e.getMethodKey()
061:                                        + "'; make sure the method name is correct and such a method is defined on targetClass "
062:                                        + target.getClass().getName(), e);
063:                    }
064:                }
065:            };
066:
067:            /**
068:             * Creates a dispatch method invoker.
069:             * @param target the target to dispatch to
070:             * @param parameterTypes the parameter types defining the argument signature
071:             * of the dispatch methods
072:             */
073:            public DispatchMethodInvoker(Object target, Class[] parameterTypes) {
074:                Assert
075:                        .notNull(target,
076:                                "The target of a dispatch method invocation is required");
077:                this .target = target;
078:                this .parameterTypes = parameterTypes;
079:            }
080:
081:            /**
082:             * Returns the target object method calls are dispatched to.
083:             */
084:            public Object getTarget() {
085:                return target;
086:            }
087:
088:            /**
089:             * Returns the parameter types defining the argument signature of the
090:             * dispatch methods.
091:             */
092:            public Class[] getParameterTypes() {
093:                return parameterTypes;
094:            }
095:
096:            /**
097:             * Dispatch a call with given arguments to named dispatcher method.
098:             * @param methodName the name of the method to invoke
099:             * @param arguments the arguments to pass to the method
100:             * @return the result of the method invokation
101:             * @throws MethodLookupException when the method cannot be resolved
102:             * @throws Exception when the invoked method throws an exception
103:             */
104:            public Object invoke(String methodName, Object[] arguments)
105:                    throws MethodLookupException, Exception {
106:                try {
107:                    Method dispatchMethod = getDispatchMethod(methodName);
108:                    return dispatchMethod.invoke(target, arguments);
109:                } catch (InvocationTargetException e) {
110:                    // the invoked method threw an exception; have it propagate to the caller
111:                    Throwable t = e.getTargetException();
112:                    if (t instanceof  Exception) {
113:                        throw (Exception) e.getTargetException();
114:                    } else {
115:                        throw (Error) e.getTargetException();
116:                    }
117:                }
118:            }
119:
120:            /**
121:             * Get a handle to the method of the specified name, with the signature
122:             * defined by the configured parameter types and return type.
123:             * @param methodName the method name
124:             * @return the method
125:             * @throws MethodLookupException when the method cannot be resolved
126:             */
127:            private Method getDispatchMethod(String methodName)
128:                    throws MethodLookupException {
129:                return (Method) methodCache.get(methodName);
130:            }
131:
132:            /**
133:             * Thrown when a dispatch method could not be resolved.
134:             */
135:            public static class MethodLookupException extends
136:                    NestedRuntimeException {
137:
138:                /**
139:                 * Create a new method lookup exception.
140:                 * @param msg a descriptive message
141:                 * @param ex the underlying cause of this exception
142:                 */
143:                public MethodLookupException(String msg, Throwable ex) {
144:                    super(msg, ex);
145:                }
146:            }
147:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.