Repository: camel
Updated Branches:
  refs/heads/master e53b636e3 -> f824fb0bf


Optimise - IntrospectionSupport to have simpler way of checking if its 
getter/setter without using regexp matcher which creates new matcher object per 
call


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/410537f9
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/410537f9
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/410537f9

Branch: refs/heads/master
Commit: 410537f9833f636c76d827c14d87943fbc9dd7fd
Parents: e53b636
Author: Claus Ibsen <[email protected]>
Authored: Thu Jun 1 20:31:35 2017 +0200
Committer: Claus Ibsen <[email protected]>
Committed: Thu Jun 1 20:31:35 2017 +0200

----------------------------------------------------------------------
 .../camel/processor/CamelInternalProcessor.java   | 11 ++++++++---
 .../apache/camel/util/IntrospectionSupport.java   | 18 +++++++++---------
 2 files changed, 17 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/410537f9/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
 
b/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
index 1ba6c0c..2514d37 100644
--- 
a/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
+++ 
b/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
@@ -633,18 +633,23 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor {
     public static class UnitOfWorkProcessorAdvice implements 
CamelInternalProcessorAdvice<UnitOfWork> {
 
         private final RouteContext routeContext;
-        private final String routeId;
+        private String routeId;
 
         public UnitOfWorkProcessorAdvice(RouteContext routeContext) {
             this.routeContext = routeContext;
-            this.routeId = 
routeContext.getRoute().idOrCreate(routeContext.getCamelContext().getNodeIdFactory());
+            if (routeContext != null) {
+                this.routeId = 
routeContext.getRoute().idOrCreate(routeContext.getCamelContext().getNodeIdFactory());
+            }
         }
 
         @Override
         public UnitOfWork before(Exchange exchange) throws Exception {
             // if the exchange doesn't have from route id set, then set it if 
it originated
             // from this unit of work
-            if (routeContext != null && exchange.getFromRouteId() == null && 
routeId != null) {
+            if (routeContext != null && exchange.getFromRouteId() == null) {
+                if (routeId == null) {
+                    routeId = 
routeContext.getRoute().idOrCreate(routeContext.getCamelContext().getNodeIdFactory());
+                }
                 exchange.setFromRouteId(routeId);
             }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/410537f9/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java 
b/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
index 21384cc..1683d26 100644
--- a/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
+++ b/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
@@ -63,8 +63,6 @@ import static 
org.apache.camel.util.ObjectHelper.isAssignableFrom;
 public final class IntrospectionSupport {
 
     private static final Logger LOG = 
LoggerFactory.getLogger(IntrospectionSupport.class);
-    private static final Pattern GETTER_PATTERN = 
Pattern.compile("(get|is)[A-Z].*");
-    private static final Pattern SETTER_PATTERN = 
Pattern.compile("set[A-Z].*");
     private static final List<Method> EXCLUDED_METHODS = new 
ArrayList<Method>();
     // use a cache to speedup introspecting for known classes during startup
     // use a weak cache as we dont want the cache to keep around as it 
reference classes
@@ -146,16 +144,17 @@ public final class IntrospectionSupport {
         Class<?> type = method.getReturnType();
         Class<?> params[] = method.getParameterTypes();
 
-        if (!GETTER_PATTERN.matcher(name).matches()) {
-            return false;
+        // is it a getXXX method
+        if (name.startsWith("get") && name.length() >= 4 && 
Character.isUpperCase(name.charAt(3))) {
+            return params.length == 0 && !type.equals(Void.TYPE);
         }
 
         // special for isXXX boolean
-        if (name.startsWith("is")) {
+        if (name.startsWith("is") && name.length() >= 3 && 
Character.isUpperCase(name.charAt(2))) {
             return params.length == 0 && 
type.getSimpleName().equalsIgnoreCase("boolean");
         }
 
-        return params.length == 0 && !type.equals(Void.TYPE);
+        return false;
     }
 
     public static String getGetterShorthandName(Method method) {
@@ -194,11 +193,12 @@ public final class IntrospectionSupport {
         Class<?> type = method.getReturnType();
         Class<?> params[] = method.getParameterTypes();
 
-        if (!SETTER_PATTERN.matcher(name).matches()) {
-            return false;
+        // is it a getXXX method
+        if (name.startsWith("set") && name.length() >= 4 && 
Character.isUpperCase(name.charAt(3))) {
+            return params.length == 1 && (type.equals(Void.TYPE) || 
(allowBuilderPattern && method.getDeclaringClass().isAssignableFrom(type)));
         }
 
-        return params.length == 1 && (type.equals(Void.TYPE) || 
(allowBuilderPattern && method.getDeclaringClass().isAssignableFrom(type)));
+        return false;
     }
     
     public static boolean isSetter(Method method) {

Reply via email to