Author: hadrian
Date: Fri May 23 07:51:37 2008
New Revision: 659559

URL: http://svn.apache.org/viewvc?rev=659559&view=rev
Log:
CAMEL-272. Simplify code to use ObjectHelper.

Modified:
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java

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=659559&r1=659558&r2=659559&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
 Fri May 23 07:51:37 2008
@@ -42,6 +42,9 @@
  */
 public class FileEndpoint extends ScheduledPollEndpoint<FileExchange> {
     private static final transient Log LOG = 
LogFactory.getLog(FileEndpoint.class);
+    private static final String DEFAULT_STRATEGYFACTORY_CLASS = 
+       "org.apache.camel.component.file.strategy.FileProcessStrategyFactory";
+    
     private File file;
     private FileProcessStrategy fileProcessStrategy;
     private boolean autoCreate = true;
@@ -273,37 +276,30 @@
      * A strategy method to lazily create the file strategy
      */
     protected FileProcessStrategy createFileStrategy() {
-        Class factory = null;
-        try {
+       Class factory = null;
+       try {
             FactoryFinder finder = new 
FactoryFinder("META-INF/services/org/apache/camel/component/");
-            factory = finder.findClass("file", "strategy.factory.");
-        } catch (ClassNotFoundException e) {
+           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);
-        }
+            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);
+            factory = ObjectHelper.loadClass(DEFAULT_STRATEGYFACTORY_CLASS);
+            if (factory == null) {
+                throw new TypeNotPresentException("FileProcessStrategyFactory 
class not found", null);
             }
         }
 
         try {
             Method factoryMethod = 
factory.getMethod("createFileProcessStrategy", Properties.class);
-            return 
(FileProcessStrategy)ObjectHelper.invokeMethod(factoryMethod, null,
-                                                                  
getParamsAsProperties());
+            return (FileProcessStrategy) 
ObjectHelper.invokeMethod(factoryMethod, null, getParamsAsProperties());
         } catch (NoSuchMethodException e) {
-            throw new TypeNotPresentException(
-                                              factory.getSimpleName()
-                                                  + 
".createFileProcessStrategy(Properties params) moethod not found",
-                                              e);
+            throw new TypeNotPresentException(factory.getSimpleName() 
+                + ".createFileProcessStrategy(Properties params) moethod not 
found", e);
         }
     }
 


Reply via email to