Source Code Cross Referenced for MethodHeaderPropertyEntryPointResolver.java in  » ESB » mule » org » mule » model » resolvers » 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 » ESB » mule » org.mule.model.resolvers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: MethodHeaderPropertyEntryPointResolver.java 10489 2008-01-23 17:53:38Z dfeist $
003:         * --------------------------------------------------------------------------------------
004:         * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
005:         *
006:         * The software in this package is published under the terms of the CPAL v1.0
007:         * license, a copy of which has been included with this distribution in the
008:         * LICENSE.txt file.
009:         */
010:        package org.mule.model.resolvers;
011:
012:        import org.mule.api.MuleEventContext;
013:        import org.mule.api.config.MuleProperties;
014:        import org.mule.api.lifecycle.Callable;
015:        import org.mule.api.model.InvocationResult;
016:        import org.mule.config.i18n.CoreMessages;
017:        import org.mule.util.ClassUtils;
018:
019:        import java.lang.reflect.Method;
020:
021:        import org.apache.commons.lang.BooleanUtils;
022:
023:        /**
024:         * This resolver will look for a 'method' property on the incoming event to determine which method to invoke
025:         * Users can customise the name of the property used to look up the method name on the event
026:         */
027:        public class MethodHeaderPropertyEntryPointResolver extends
028:                AbstractEntryPointResolver {
029:
030:            private String methodProperty = MuleProperties.MULE_METHOD_PROPERTY;
031:
032:            public String getMethodProperty() {
033:                return methodProperty;
034:            }
035:
036:            public void setMethodProperty(String methodProperty) {
037:                this .methodProperty = methodProperty;
038:            }
039:
040:            public InvocationResult invoke(Object component,
041:                    MuleEventContext context) throws Exception {
042:                //TODO: RM* This is a hack that can be fixed by introducing property scoping on the message
043:                // Transports such as SOAP need to ignore the method property
044:                boolean ignoreMethod = BooleanUtils.toBoolean((Boolean) context
045:                        .getMessage().removeProperty(
046:                                MuleProperties.MULE_IGNORE_METHOD_PROPERTY));
047:
048:                if (ignoreMethod) {
049:                    //TODO: Removed once we have property scoping
050:                    InvocationResult result = new InvocationResult(
051:                            InvocationResult.STATE_INVOKE_NOT_SUPPORTED);
052:                    result.setErrorMessage("Property: "
053:                            + MuleProperties.MULE_IGNORE_METHOD_PROPERTY
054:                            + " was set so skipping this resolver: " + this );
055:                    return result;
056:                }
057:
058:                //TODO: with scoped properties we wouldn't need to remove the property here
059:                Object methodProp = context.getMessage().removeProperty(
060:                        getMethodProperty());
061:                if (methodProp == null) {
062:                    InvocationResult result = new InvocationResult(
063:                            InvocationResult.STATE_INVOKED_FAILED);
064:                    // no method for the explicit method header
065:                    result.setErrorMessage(CoreMessages
066:                            .propertyIsNotSetOnEvent(getMethodProperty())
067:                            .toString());
068:                    return result;
069:                }
070:
071:                Method method;
072:                String methodName;
073:                if (methodProp instanceof  Method) {
074:                    method = (Method) methodProp;
075:                    methodName = method.getName();
076:                } else {
077:                    methodName = methodProp.toString();
078:                    method = getMethodByName(methodName, context);
079:                }
080:
081:                if (method != null && method.getParameterTypes().length == 0) {
082:                    return invokeMethod(component, method,
083:                            ClassUtils.NO_ARGS_TYPE);
084:                }
085:
086:                Object[] payload = getPayloadFromMessage(context);
087:
088:                if (method == null) {
089:                    Class[] classTypes = ClassUtils.getClassTypes(payload);
090:                    try {
091:                        method = component.getClass().getMethod(methodName,
092:                                classTypes);
093:                    } catch (NoSuchMethodException e) {
094:                        InvocationResult result = new InvocationResult(
095:                                InvocationResult.STATE_INVOKED_FAILED);
096:                        result.setErrorNoMatchingMethods(component, classTypes,
097:                                this );
098:                        return result;
099:
100:                    }
101:                }
102:
103:                validateMethod(component, method);
104:                addMethodByName(method, context);
105:
106:                return invokeMethod(component, method, payload);
107:
108:            }
109:
110:            /**
111:             * This method can be used to validate that the method exists and is allowed to
112:             * be executed.
113:             */
114:            protected void validateMethod(Object component, Method method)
115:                    throws NoSuchMethodException {
116:                boolean fallback = component instanceof  Callable;
117:
118:                if (method != null) {
119:                    // This will throw NoSuchMethodException if it doesn't exist
120:                    try {
121:                        component.getClass().getMethod(method.getName(),
122:                                method.getParameterTypes());
123:                    } catch (NoSuchMethodException e) {
124:                        if (!fallback) {
125:                            throw e;
126:                        }
127:                    }
128:                } else {
129:                    if (!fallback) {
130:                        throw new NoSuchMethodException(CoreMessages
131:                                .methodWithParamsNotFoundOnObject("null",
132:                                        "unknown", component.getClass())
133:                                .toString());
134:                    }
135:                }
136:            }
137:
138:            public String toString() {
139:                final StringBuffer sb = new StringBuffer();
140:                sb.append("MethodHeaderPropertyEntryPointResolver");
141:                sb.append("{methodHeader=").append(methodProperty);
142:                sb.append("transformFirst=").append(isTransformFirst());
143:                sb.append(", acceptVoidMethods=").append(isAcceptVoidMethods());
144:                sb.append('}');
145:                return sb.toString();
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.