Author: hadrian
Date: Thu May 22 12:11:33 2008
New Revision: 659210

URL: http://svn.apache.org/viewvc?rev=659210&view=rev
Log:
CAMEL-272

Modified:
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategyFactory.java
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/FactoryFinder.java
    
activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/file

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java?rev=659210&r1=659209&r2=659210&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
 Thu May 22 12:11:33 2008
@@ -17,6 +17,9 @@
 package org.apache.camel.component.file;
 
 import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.util.Properties;
 
 import org.apache.camel.Consumer;
 import org.apache.camel.ExchangePattern;
@@ -25,8 +28,8 @@
 import org.apache.camel.Producer;
 import org.apache.camel.component.file.strategy.FileProcessStrategyFactory;
 import org.apache.camel.component.file.strategy.FileProcessStrategySupport;
-import org.apache.camel.component.file.strategy.NoOpFileProcessStrategy;
 import org.apache.camel.impl.ScheduledPollEndpoint;
+import org.apache.camel.util.FactoryFinder;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -270,9 +273,58 @@
      * A strategy method to lazily create the file strategy
      */
     protected FileProcessStrategy createFileStrategy() {
-        return FileProcessStrategyFactory.createFileProcessStrategy(isNoop(), 
isDelete(), isLock(), moveNamePrefix, moveNamePostfix);
+       Class factory = null;
+       try {
+               FactoryFinder finder = new 
FactoryFinder("META-INF/services/org/apache/camel/component/");
+                       factory = finder.findClass("file", "strategy.factory.");
+       } catch (ClassNotFoundException e) {
+               LOG.debug("'strategy.factory.class' not found", e);
+               } catch (IOException e) {
+               LOG.debug("No strategy factory defined in 
'META-INF/services/org/apache/camel/component/file'", e);
+       }
+               
+               if (factory == null) {
+                       // use default
+                       ClassLoader cl = 
Thread.currentThread().getContextClassLoader();
+                       try {
+                               factory = 
cl.loadClass("org.apache.camel.component.file.strategy.FileProcessStrategyFactory");
+                       } catch (ClassNotFoundException e) {
+                               throw new 
TypeNotPresentException("FileProcessStrategyFactory class not found", e);
+                       }
+               }
+               
+               try {
+                       Method factoryMethod = 
factory.getMethod("createFileProcessStrategy", Properties.class);
+                       return (FileProcessStrategy) 
ObjectHelper.invokeMethod(factoryMethod, null, getParamsAsProperties());
+               } catch (NoSuchMethodException e) {
+                       throw new 
TypeNotPresentException(factory.getSimpleName() 
+                + ".createFileProcessStrategy(Properties params) moethod not 
found", e);
+               }
+    }
+
+    protected Properties getParamsAsProperties() {
+               Properties params = new Properties();
+               if (isNoop()) {
+                       params.setProperty("noop", 
Boolean.toString(Boolean.TRUE));
+               }
+               if (isDelete()) {
+                       params.setProperty("delete", 
Boolean.toString(Boolean.TRUE));
+               }
+               if (isAppend()) {
+                       params.setProperty("append", 
Boolean.toString(Boolean.TRUE));
+               }
+               if (isLock()) {
+                       params.setProperty("lock", 
Boolean.toString(Boolean.TRUE));
+               }
+               if (moveNamePrefix != null) {
+                       params.setProperty("moveNamePrefix", moveNamePrefix);
+               }
+               if (moveNamePostfix != null) {
+                       params.setProperty("moveNamePostfix", moveNamePostfix);
+               }
+               return params;
     }
-
+    
     @Override
     protected String createEndpointUri() {
         return "file://" + getFile().getAbsolutePath();

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategyFactory.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategyFactory.java?rev=659210&r1=659209&r2=659210&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategyFactory.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategyFactory.java
 Thu May 22 12:11:33 2008
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.file.strategy;
 
+import java.util.Properties;
+
 import org.apache.camel.component.file.FileProcessStrategy;
 
 /**
@@ -30,12 +32,20 @@
     /**
      * A strategy method to lazily create the file strategy to use.
      */
-    public static FileProcessStrategy createFileProcessStrategy(boolean 
isNoop, boolean isDelete, boolean isLock, String moveNamePrefix, String 
moveNamePostfix) {
-        if (isNoop) {
+    public static FileProcessStrategy createFileProcessStrategy(Properties 
params) {
+
+       // We assume a value is present only if its value not null for String 
and 'true' for boolean            
+       boolean isDelete = params.getProperty("delete") != null;
+       boolean isLock = params.getProperty("lock") != null;
+       String moveNamePrefix = params.getProperty("moveNamePrefix");
+       String moveNamePostfix = params.getProperty("moveNamePostfix");
+       
+        if (params.getProperty("noop") != null) {
             return new NoOpFileProcessStrategy();
         } else if (moveNamePostfix != null || moveNamePrefix != null) {
             if (isDelete) {
-                throw new IllegalArgumentException("You cannot set the 
deleteFiles property and a moveFilenamePostfix or moveFilenamePrefix");
+                throw new IllegalArgumentException("You cannot set the 
deleteFiles property " 
+                    + "and a moveFilenamePostfix or moveFilenamePrefix");
             }
             return new RenameFileProcessStrategy(isLock, moveNamePrefix, 
moveNamePostfix);
         } else if (isDelete) {

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/FactoryFinder.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/FactoryFinder.java?rev=659210&r1=659209&r2=659210&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/FactoryFinder.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/FactoryFinder.java
 Thu May 22 12:11:33 2008
@@ -102,7 +102,7 @@
 
         Class clazz = (Class)classMap.get(propertyPrefix + key);
         if (clazz == null) {
-            clazz = newInstance(doFindFactoryProperies(key), propertyPrefix);
+            clazz = newInstance(doFindFactoryProperties(key), propertyPrefix);
             classMap.put(propertyPrefix + key, clazz);
         }
         return clazz;
@@ -145,7 +145,7 @@
         return clazz;
     }
 
-    private Properties doFindFactoryProperies(String key) throws IOException {
+    private Properties doFindFactoryProperties(String key) throws IOException {
         String uri = path + key;
 
         // lets try the thread context class loader first

Modified: 
activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/file
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/file?rev=659210&r1=659209&r2=659210&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/file
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/file
 Thu May 22 12:11:33 2008
@@ -16,3 +16,4 @@
 #
 
 class=org.apache.camel.component.file.FileComponent
+strategy.factory.class=org.apache.camel.component.file.strategy.FileProcessStrategyFactory
\ No newline at end of file


Reply via email to