camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r730768 - in /activemq/camel/trunk: components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/AntPathMatcherRemoteFileFilter.java tests/camel-itest/pom.xml
Date Fri, 02 Jan 2009 16:20:22 GMT
Author: davsclaus
Date: Fri Jan  2 08:20:22 2009
New Revision: 730768

URL: http://svn.apache.org/viewvc?rev=730768&view=rev
Log:
CAMEL-1198: added init() to avoid load and lookup methods more than once

Modified:
    activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/AntPathMatcherRemoteFileFilter.java
    activemq/camel/trunk/tests/camel-itest/pom.xml

Modified: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/AntPathMatcherRemoteFileFilter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/AntPathMatcherRemoteFileFilter.java?rev=730768&r1=730767&r2=730768&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/AntPathMatcherRemoteFileFilter.java
(original)
+++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/AntPathMatcherRemoteFileFilter.java
Fri Jan  2 08:20:22 2009
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.file.remote;
 
+import java.lang.reflect.Method;
+
 import org.apache.camel.util.ObjectHelper;
 import static org.apache.camel.util.CollectionHelper.collectionAsCommaDelimitedString;
 
@@ -29,24 +31,28 @@
     private String[] excludes;
     private String[] includes;
 
-    public boolean accept(RemoteFile file) {
-        // we must use reflection to invoke the AntPathMatcherFileFilter that reside in camel-spring.jar
-        // and we don't want camel-ftp to have runtime dependency on camel-spring.jar
-        Class clazz = ObjectHelper.loadClass(ANTPATHMATCHER_CLASSNAME);
-        ObjectHelper.notNull(clazz, ANTPATHMATCHER_CLASSNAME + " not found in classpath.
camel-spring.jar is required in the classpath.");
+    private Object filter;
+    private Method includesMethod;
+    private Method excludesMethod;
+    private Method acceptsMethod;
 
+    public boolean accept(RemoteFile file) {
         try {
-            Object filter = ObjectHelper.newInstance(clazz);
+            synchronized (this) {
+                if (filter == null) {
+                    init();
+                }
+            }
 
             // invoke setIncludes(String), must using string type as invoking with string[]
does not work
-            ObjectHelper.invokeMethod(filter.getClass().getMethod("setIncludes", String.class),
filter, collectionAsCommaDelimitedString(includes));
+            ObjectHelper.invokeMethod(includesMethod, filter, collectionAsCommaDelimitedString(includes));
 
             // invoke setExcludes(String), must using string type as invoking with string[]
does not work
-            ObjectHelper.invokeMethod(filter.getClass().getMethod("setExcludes", String.class),
filter, collectionAsCommaDelimitedString(excludes));
+            ObjectHelper.invokeMethod(excludesMethod, filter, collectionAsCommaDelimitedString(excludes));
 
             // invoke acceptPathName(String)
             String path = file.getRelativeFileName();
-            Boolean result = (Boolean) ObjectHelper.invokeMethod(filter.getClass().getMethod("acceptPathName",
String.class), filter, path);
+            Boolean result = (Boolean) ObjectHelper.invokeMethod(acceptsMethod, filter, path);
             return result;
 
         } catch (NoSuchMethodException e) {
@@ -54,6 +60,19 @@
         }
     }
 
+    private void init() throws NoSuchMethodException {
+        // we must use reflection to invoke the AntPathMatcherFileFilter that reside in camel-spring.jar
+        // and we don't want camel-ftp to have runtime dependency on camel-spring.jar
+        Class clazz = ObjectHelper.loadClass(ANTPATHMATCHER_CLASSNAME);
+        ObjectHelper.notNull(clazz, ANTPATHMATCHER_CLASSNAME + " not found in classpath.
camel-spring.jar is required in the classpath.");
+
+        filter = ObjectHelper.newInstance(clazz);
+
+        includesMethod = filter.getClass().getMethod("setIncludes", String.class);
+        excludesMethod = filter.getClass().getMethod("setExcludes", String.class);
+        acceptsMethod = filter.getClass().getMethod("acceptPathName", String.class);
+    }
+
     public String[] getExcludes() {
         return excludes;
     }

Modified: activemq/camel/trunk/tests/camel-itest/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/tests/camel-itest/pom.xml?rev=730768&r1=730767&r2=730768&view=diff
==============================================================================
--- activemq/camel/trunk/tests/camel-itest/pom.xml (original)
+++ activemq/camel/trunk/tests/camel-itest/pom.xml Fri Jan  2 08:20:22 2009
@@ -183,7 +183,19 @@
                     </execution>
                 </executions>
             </plugin>
-        </plugins>
+
+            <plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-clean-plugin</artifactId>
+				<configuration>
+					<filesets>
+						<fileset>
+							<directory>${basedir}/res</directory>
+						</fileset>
+					</filesets>
+				</configuration>
+			</plugin>
+		</plugins>
     </build>
 
 </project>



Mime
View raw message