Source Code Cross Referenced for ReflectionEntryPointResolver.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: ReflectionEntryPointResolver.java 10529 2008-01-25 05:58:36Z 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.model.InvocationResult;
014:        import org.mule.routing.filters.WildcardFilter;
015:        import org.mule.util.ClassUtils;
016:        import org.mule.util.StringMessageUtils;
017:        import org.mule.util.StringUtils;
018:
019:        import java.lang.reflect.Method;
020:        import java.util.Arrays;
021:        import java.util.Collection;
022:        import java.util.Collections;
023:        import java.util.HashSet;
024:        import java.util.List;
025:        import java.util.Set;
026:
027:        /**
028:         * <code>ReflectEntryPointResolver</code> is used to determine the entry point on a service
029:         * after an event has been received for it. The entrypoint is  discovered using
030:         * the event payload type(s) as the argument using reflection. An entry point will try and match for
031:         * different argument types, so it's possible to have multiple entry points on a
032:         * single service.
033:         * <p/>
034:         * For multiple parameters the payload of context.getMessage().getPayload() should be an Array of objects.
035:         * If the message payload is of type {@link org.mule.transport.NullPayload} the resolver will look for a no-argument
036:         * method to call that doesn't match the set of ignoredMethods on the resolver.
037:         * <p/>
038:         * Also a set of 'ignored' methods are available (and the use can add others) to tell the resolver to not
039:         * resolve to these methods. The default ones are:
040:         * <ul>
041:         * <li>{@link #toString()}
042:         * <li>{@link #getClass()}
043:         * <li>{@link #notify}
044:         * <li>{@link #notifyAll}
045:         * <li>{@link #hashCode}
046:         * <li>{@link #wait}
047:         * <li>{@link java.lang.reflect.Proxy#getInvocationHandler}
048:         * <li>{@link Cloneable#clone()}
049:         * <li>'is*'
050:         * <li>'get*'.
051:         * <li>'set*'.
052:         * </ul>
053:         * <p/> Note that wildcard expressions can be used.
054:         */
055:        public class ReflectionEntryPointResolver extends
056:                AbstractEntryPointResolver {
057:
058:            // we don't want to match these methods when looking for a service method
059:            private Set ignoredMethods = new HashSet(Arrays
060:                    .asList(new String[] { "equals", "getInvocationHandler",
061:                            "set*", "toString", "getClass", "notify",
062:                            "notifyAll", "wait", "hashCode", "clone", "is*",
063:                            "get*" }));
064:
065:            protected WildcardFilter filter;
066:
067:            public ReflectionEntryPointResolver() {
068:                updateFilter();
069:            }
070:
071:            private void updateFilter() {
072:                filter = new WildcardFilter(StringUtils.join(ignoredMethods,
073:                        ','));
074:            }
075:
076:            /**
077:             * Returns an unmodifable Set of ignoredMethods on this resolver
078:             * To add method to the resolver use {@link #addIgnoredMethod(String)}
079:             *
080:             * @return unmodifiable set of method names set on this resolver
081:             */
082:            public Collection getIgnoredMethods() {
083:                return Collections.unmodifiableSet(ignoredMethods);
084:            }
085:
086:            public void setIgnoredMethods(Collection methods) {
087:                this .ignoredMethods = new HashSet(methods);
088:                updateFilter();
089:            }
090:
091:            public void addIgnoredMethod(String name) {
092:                this .ignoredMethods.add(name);
093:                updateFilter();
094:            }
095:
096:            public boolean removeIgnoredMethod(String name) {
097:                boolean result = this .ignoredMethods.remove(name);
098:                updateFilter();
099:                return result;
100:            }
101:
102:            /**
103:             * Will discover the entrypoint on the service using the payload type to figure out the method to call.
104:             * For multiple parameters the payload of context.getMessage().geTPayload() should be an Array of objects.
105:             * If the message payload is of type {@link org.mule.transport.NullPayload} the resolver will look for a no-argument
106:             * method to call that doesn't match the set of ignoredMethods on the resover.
107:             *
108:             * @param service
109:             * @param context
110:             * @return
111:             * @throws Exception
112:             */
113:            public InvocationResult invoke(Object component,
114:                    MuleEventContext context) throws Exception {
115:                Object[] payload = getPayloadFromMessage(context);
116:
117:                Method method;
118:                InvocationResult result;
119:
120:                method = this .getMethodByArguments(component, payload);
121:
122:                if (method != null) {
123:                    return invokeMethod(component, method, payload);
124:                }
125:
126:                Class[] types = ClassUtils.getClassTypes(payload);
127:
128:                // do any methods on the service accept a context?
129:                List methods = ClassUtils.getSatisfiableMethods(component
130:                        .getClass(), types, isAcceptVoidMethods(), false,
131:                        ignoredMethods, filter);
132:
133:                int numMethods = methods.size();
134:                if (numMethods > 1) {
135:                    result = new InvocationResult(
136:                            InvocationResult.STATE_INVOKED_FAILED);
137:                    // too many methods match the context argument
138:                    result.setErrorTooManyMatchingMethods(component, types,
139:                            StringMessageUtils.toString(methods), this );
140:                    return result;
141:
142:                } else if (numMethods == 1) {
143:                    // found exact match for method with context argument
144:                    method = this .addMethodByArguments(component,
145:                            (Method) methods.get(0), payload);
146:                } else {
147:                    methods = ClassUtils.getSatisfiableMethods(component
148:                            .getClass(), ClassUtils.getClassTypes(payload),
149:                            true, true, ignoredMethods);
150:
151:                    numMethods = methods.size();
152:
153:                    if (numMethods > 1) {
154:                        result = new InvocationResult(
155:                                InvocationResult.STATE_INVOKED_FAILED);
156:                        // too many methods match the context argument
157:                        result.setErrorTooManyMatchingMethods(component, types,
158:                                StringMessageUtils.toString(methods), this );
159:                        return result;
160:                    } else if (numMethods == 1) {
161:                        // found exact match for payload argument
162:                        method = this .addMethodByArguments(component,
163:                                (Method) methods.get(0), payload);
164:                    } else {
165:                        result = new InvocationResult(
166:                                InvocationResult.STATE_INVOKED_FAILED);
167:                        // no method for payload argument either - bail out
168:                        result.setErrorNoMatchingMethods(component, ClassUtils
169:                                .getClassTypes(payload), this );
170:                        return result;
171:                    }
172:                }
173:
174:                return invokeMethod(component, method, payload);
175:            }
176:
177:            public String toString() {
178:                final StringBuffer sb = new StringBuffer();
179:                sb.append("ReflectionEntryPointResolver");
180:                sb.append("{ignoredMethods=").append(
181:                        StringMessageUtils.toString(ignoredMethods));
182:                sb.append("{transformFirst=").append(isTransformFirst());
183:                sb.append(", acceptVoidMethods=").append(isAcceptVoidMethods());
184:                sb.append('}');
185:                return sb.toString();
186:            }
187:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.