camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r739191 - in /camel/trunk/camel-core/src/main/java/org/apache/camel: component/file/ impl/converter/
Date Fri, 30 Jan 2009 06:26:07 GMT
Author: davsclaus
Date: Fri Jan 30 06:26:07 2009
New Revision: 739191

URL: http://svn.apache.org/viewvc?rev=739191&view=rev
Log:
CAMEL-1241: Fixed generic file component to use File.separator instead of / to work on all
platforms.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileComponent.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConfiguration.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileDefaultBinding.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExchange.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileMessage.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileConsumer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java?rev=739191&r1=739190&r2=739191&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
Fri Jan 30 06:26:07 2009
@@ -73,26 +73,26 @@
      * @param newName the new name
      */
     public void changeFileName(String newName) {
-        setAbsoluteFileName(getParent() + "/" + newName);
+        setAbsoluteFileName(getParent() + File.separator + newName);
 
         // relative name is a bit more complex to set as newName itself can contain
         // folders we need to consider as well
         String baseNewName = null;
-        if (newName.indexOf("/") != -1) {
-            baseNewName = newName.substring(0, newName.lastIndexOf("/"));
-            newName = newName.substring(newName.lastIndexOf("/") + 1);
+        if (newName.indexOf(File.separator) != -1) {
+            baseNewName = newName.substring(0, newName.lastIndexOf(File.separator));
+            newName = newName.substring(newName.lastIndexOf(File.separator) + 1);
         }
 
-        if (relativeFileName.indexOf("/") != -1) {
-            String relative = relativeFileName.substring(0, relativeFileName.lastIndexOf("/"));
+        if (relativeFileName.indexOf(File.separator) != -1) {
+            String relative = relativeFileName.substring(0, relativeFileName.lastIndexOf(File.separator));
             if (baseNewName != null) {
-                setRelativeFileName(relative + "/" + baseNewName + "/" + newName);
+                setRelativeFileName(relative + File.separator + baseNewName + File.separator
+ newName);
             } else {
-                setRelativeFileName(relative + "/" + newName);
+                setRelativeFileName(relative + File.separator + newName);
             }
         } else {
             if (baseNewName != null) {
-                setRelativeFileName(baseNewName + "/" + newName);
+                setRelativeFileName(baseNewName + File.separator + newName);
             } else {
                 setRelativeFileName(newName);
             }
@@ -150,8 +150,8 @@
     }
 
     public String getParent() {
-        if (getAbsoluteFileName().lastIndexOf("/") > 0) {
-            return getAbsoluteFileName().substring(0, getAbsoluteFileName().lastIndexOf("/"));
+        if (getAbsoluteFileName().lastIndexOf(File.separator) > 0) {
+            return getAbsoluteFileName().substring(0, getAbsoluteFileName().lastIndexOf(File.separator));
         } else {
             return "";
         }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileComponent.java?rev=739191&r1=739190&r2=739191&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileComponent.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileComponent.java
Fri Jan 30 06:26:07 2009
@@ -63,14 +63,23 @@
     }
 
     /**
-     * File Components implements this method
+     * A factory method for derived file components to create the endpoint
+     *
+     * @param uri the full URI of the endpoint
+     * @param remaining the remaining part of the URI without the query
+     *                parameters or component prefix
+     * @param parameters the optional parameters passed in
+     * @return a newly created endpoint or null if the endpoint cannot be
+     *         created based on the inputs
+     * @throws Exception can be thrown
      */
     protected abstract GenericFileEndpoint<T> buildFileEndpoint(String uri, String
remaining, Map parameters) throws Exception;
 
     /**
-     * File Components implements this method
+     * A factory method for derived file components to perform validation of properties
      *
-     * @param endpoint the newly created endpoint to do some custom post configuration
+     * @param endpoint the endpoint
+     * @throws Exception can be thrown in case of validation errors
      */
     protected abstract void afterPropertiesSet(GenericFileEndpoint<T> endpoint) throws
Exception;
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConfiguration.java?rev=739191&r1=739190&r2=739191&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConfiguration.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConfiguration.java
Fri Jan 30 06:26:07 2009
@@ -22,10 +22,6 @@
 
     private String file;
 
-    public GenericFileConfiguration() {
-        super();
-    }
-
     public void configure(URI uri) {
         setFile(uri.getPath());
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java?rev=739191&r1=739190&r2=739191&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
Fri Jan 30 06:26:07 2009
@@ -50,7 +50,9 @@
 
         // before we poll is there anything we need to check ? Such as are we
         // connected to the FTP Server Still ?
-        prePollCheck();
+        if (!prePollCheck()) {
+            log.debug("Skipping pool as pre poll check returned false");
+        }
 
         // gather list of files to process
         List<GenericFile<T>> files = new ArrayList<GenericFile<T>>();
@@ -133,7 +135,7 @@
         }
 
         try {
-            final GenericFileProcessStrategy processStrategy = endpoint.getGenericFileProcessStrategy();
+            final GenericFileProcessStrategy<T> processStrategy = endpoint.getGenericFileProcessStrategy();
 
             if (processStrategy.begin(operations, endpoint, exchange, exchange.getGenericFile()))
{
 
@@ -206,8 +208,8 @@
      *                        <tt>true</tt> if an exception occured during processing
but it
      *                        was handled by the failure processor (usually the DeadLetterChannel).
      */
-    protected void processStrategyCommit(GenericFileProcessStrategy processStrategy,
-                                         GenericFileExchange exchange, GenericFile<T>
file, boolean failureHandled) {
+    protected void processStrategyCommit(GenericFileProcessStrategy<T> processStrategy,
+                                         GenericFileExchange<T> exchange, GenericFile<T>
file, boolean failureHandled) {
         if (endpoint.isIdempotent()) {
             // only add to idempotent repository if we could process the file
             // only use the filename as the key as the file could be moved into a done folder
@@ -234,8 +236,8 @@
      * @param exchange        the exchange
      * @param file            the file processed
      */
-    protected void processStrategyRollback(GenericFileProcessStrategy processStrategy,
-                                           GenericFileExchange exchange, GenericFile<T>
file) {
+    protected void processStrategyRollback(GenericFileProcessStrategy<T> processStrategy,
+                                           GenericFileExchange<T> exchange, GenericFile<T>
file) {
         if (log.isDebugEnabled()) {
             log.debug("Rolling back remote file strategy: " + processStrategy + " for file:
" + file);
         }
@@ -332,11 +334,4 @@
         return true;
     }
 
-    /**
-     * Override if required
-     */
-    protected void doStop() throws Exception {
-        super.doStop();
-    }
-
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileDefaultBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileDefaultBinding.java?rev=739191&r1=739190&r2=739191&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileDefaultBinding.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileDefaultBinding.java
Fri Jan 30 06:26:07 2009
@@ -23,11 +23,11 @@
 
     private Object body;
 
-    public Object getBody(GenericFile genericFile) {
+    public Object getBody(GenericFile file) {
         return body;
     }
 
-    public void setBody(GenericFile genericFile, Object body) {
+    public void setBody(GenericFile file, Object body) {
         this.body = body;
     }
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java?rev=739191&r1=739190&r2=739191&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
Fri Jan 30 06:26:07 2009
@@ -37,7 +37,7 @@
 import org.apache.commons.logging.LogFactory;
 
 /**
- * Generic Endpoint
+ * Generic FileEndpoint
  */
 public abstract class GenericFileEndpoint<T> extends ScheduledPollEndpoint {
 
@@ -46,7 +46,7 @@
 
     protected final transient Log log = LogFactory.getLog(getClass());
 
-    protected GenericFileProcessStrategy processStrategy;
+    protected GenericFileProcessStrategy<T> processStrategy;
     protected GenericFileOperations<T> operations;
     protected GenericFileConfiguration configuration;
 
@@ -109,7 +109,7 @@
         return UuidGenerator.generateSanitizedId(message.getMessageId());
     }
 
-    public GenericFileProcessStrategy getGenericFileProcessStrategy() {
+    public GenericFileProcessStrategy<T> getGenericFileProcessStrategy() {
         if (processStrategy == null) {
             processStrategy = createGenericFileStrategy();
             if (log.isDebugEnabled()) {
@@ -122,7 +122,8 @@
     /**
      * A strategy method to lazily create the file strategy
      */
-    protected GenericFileProcessStrategy createGenericFileStrategy() {
+    @SuppressWarnings("unchecked")
+    protected GenericFileProcessStrategy<T> createGenericFileStrategy() {
         Class<?> factory = null;
         try {
             FactoryFinder finder = getCamelContext().createFactoryFinder("META-INF/services/org/apache/camel/component/");
@@ -143,13 +144,13 @@
 
         try {
             Method factoryMethod = factory.getMethod("createGenericFileProcessStrategy",
Map.class);
-            return (GenericFileProcessStrategy) ObjectHelper.invokeMethod(factoryMethod,
null, getParamsAsMap());
+            return (GenericFileProcessStrategy<T>) ObjectHelper.invokeMethod(factoryMethod,
null, getParamsAsMap());
         } catch (NoSuchMethodException e) {
             throw new TypeNotPresentException(factory.getSimpleName() + ".createGenericFileProcessStrategy(GenericFileEndpoint
endpoint) method not found", e);
         }
     }
 
-    public void setGenericFileProcessStrategy(GenericFileProcessStrategy genericFileProcessStrategy)
{
+    public void setGenericFileProcessStrategy(GenericFileProcessStrategy<T> genericFileProcessStrategy)
{
         this.processStrategy = genericFileProcessStrategy;
     }
 
@@ -408,11 +409,11 @@
         this.operations = operations;
     }
 
-    public GenericFileProcessStrategy getProcessStrategy() {
+    public GenericFileProcessStrategy<T> getProcessStrategy() {
         return processStrategy;
     }
 
-    public void setProcessStrategy(GenericFileProcessStrategy processStrategy) {
+    public void setProcessStrategy(GenericFileProcessStrategy<T> processStrategy) {
         this.processStrategy = processStrategy;
     }
 
@@ -479,7 +480,7 @@
             params.put("readLock", readLock);
         }
         if (readLockTimeout > 0) {
-            params.put("readLockTimeout", Long.valueOf(readLockTimeout));
+            params.put("readLockTimeout", readLockTimeout);
         }
         return params;
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExchange.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExchange.java?rev=739191&r1=739190&r2=739191&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExchange.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExchange.java
Fri Jan 30 06:26:07 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.file;
 
+import java.io.File;
 import java.util.Date;
 
 import org.apache.camel.CamelContext;
@@ -26,7 +27,7 @@
 
 public class GenericFileExchange<T> extends DefaultExchange {
 
-    private GenericFile<T> genericFile;
+    private GenericFile<T> file;
 
     public GenericFileExchange(CamelContext context) {
         super(context);
@@ -44,53 +45,53 @@
         super(fromEndpoint);
     }
 
-    public GenericFileExchange(GenericFileEndpoint endpoint, ExchangePattern pattern, GenericFile<T>
genericFile) {
+    public GenericFileExchange(GenericFileEndpoint endpoint, ExchangePattern pattern, GenericFile<T>
file) {
         super(endpoint, pattern);
-        setGenericFile(genericFile);
+        setGenericFile(file);
     }
 
-    public GenericFileExchange(DefaultExchange parent, GenericFile<T> genericFile)
{
+    public GenericFileExchange(DefaultExchange parent, GenericFile<T> file) {
         super(parent);
-        setGenericFile(genericFile);
+        setGenericFile(file);
     }
 
     public GenericFileExchange(Endpoint fromEndpoint, ExchangePattern pattern) {
         super(fromEndpoint, pattern);
     }
 
-    protected void populateHeaders(GenericFile<T> genericFile) {
-        if (genericFile != null) {
-            getIn().setHeader("CamelFileName", genericFile.getFileName());
-            getIn().setHeader("CamelFileAbsolutePath", genericFile.getAbsoluteFileName());
+    protected void populateHeaders(GenericFile<T> file) {
+        if (file != null) {
+            getIn().setHeader("CamelFileName", file.getFileName());
+            getIn().setHeader("CamelFileAbsolutePath", file.getAbsoluteFileName());
             // set the parent if there is a parent folder
-            if (genericFile.getRelativeFileName().lastIndexOf("/") != -1) {
-                String parent = genericFile.getRelativeFileName().substring(0, genericFile.getRelativeFileName().lastIndexOf("/"));
+            if (file.getRelativeFileName().lastIndexOf(File.separator) != -1) {
+                String parent = file.getRelativeFileName().substring(0, file.getRelativeFileName().lastIndexOf(File.separator));
                 getIn().setHeader("CamelFileParent", parent);
             }
-            getIn().setHeader("CamelFilePath", genericFile.getRelativeFileName());
-            getIn().setHeader("CamelFileCanonicalPath", genericFile.getCanonicalFileName());
+            getIn().setHeader("CamelFilePath", file.getRelativeFileName());
+            getIn().setHeader("CamelFileCanonicalPath", file.getCanonicalFileName());
 
-            if (genericFile.getFileLength() > 0) {
-                getIn().setHeader("CamelFileLength", genericFile.getFileLength());
+            if (file.getFileLength() > 0) {
+                getIn().setHeader("CamelFileLength", file.getFileLength());
             }
-            if (genericFile.getLastModified() > 0) {
-                getIn().setHeader("CamelFileLastModified", new Date(genericFile.getLastModified()));
+            if (file.getLastModified() > 0) {
+                getIn().setHeader("CamelFileLastModified", new Date(file.getLastModified()));
             }
         }
     }
 
     public GenericFile<T> getGenericFile() {
-        return genericFile;
+        return file;
     }
 
-    public void setGenericFile(GenericFile<T> genericFile) {
-        setIn(new GenericFileMessage(genericFile));
-        this.genericFile = genericFile;
-        populateHeaders(genericFile);
+    public void setGenericFile(GenericFile<T> file) {
+        setIn(new GenericFileMessage<T>(file));
+        this.file = file;
+        populateHeaders(file);
     }
 
     public Exchange newInstance() {
-        return new GenericFileExchange<T>(this, genericFile);
+        return new GenericFileExchange<T>(this, file);
     }
 
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileMessage.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileMessage.java?rev=739191&r1=739190&r2=739191&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileMessage.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileMessage.java
Fri Jan 30 06:26:07 2009
@@ -19,34 +19,35 @@
 import org.apache.camel.impl.DefaultMessage;
 
 /**
- * Remote file message
+ * Generic file message
  */
 public class GenericFileMessage<T> extends DefaultMessage {
-    private GenericFile<T> genericFile;
+    private GenericFile<T> file;
 
     public GenericFileMessage() {
     }
 
-    public GenericFileMessage(GenericFile<T> genericFile) {
-        this.genericFile = genericFile;
+    public GenericFileMessage(GenericFile<T> file) {
+        this.file = file;
     }
 
     @Override
-    public GenericFileExchange getExchange() {
-        return (GenericFileExchange) super.getExchange();
+    @SuppressWarnings("unchecked")
+    public GenericFileExchange<T> getExchange() {
+        return (GenericFileExchange<T>) super.getExchange();
     }
 
     @Override
     protected Object createBody() {
-        return genericFile.getBody();
+        return file.getBody();
     }
 
     public GenericFile<T> getGenericFile() {
-        return genericFile;
+        return file;
     }
 
-    public void setRemoteFile(GenericFile<T> genericFile) {
-        this.genericFile = genericFile;
+    public void setGenericFile(GenericFile<T> file) {
+        this.file = file;
     }
 
     @Override
@@ -56,6 +57,6 @@
 
     @Override
     public String toString() {
-        return "GenericFileMessage: " + genericFile;
+        return "GenericFileMessage: " + file;
     }
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java?rev=739191&r1=739190&r2=739191&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
Fri Jan 30 06:26:07 2009
@@ -105,8 +105,7 @@
     }
 
     /**
-     * Perform any actions that need to occur before we write Such as connecting
-     * to an FTP server etc.
+     * Perform any actions that need to occur before we write such as connecting to an FTP
server etc.
      */
     protected void preWriteCheck() throws Exception {
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileConsumer.java?rev=739191&r1=739190&r2=739191&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileConsumer.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileConsumer.java
Fri Jan 30 06:26:07 2009
@@ -82,7 +82,6 @@
             // matched file so add
             fileList.add(gf);
         }
-
     }
 
     /**
@@ -106,7 +105,7 @@
         }
         answer.setLastModified(file.lastModified());
         if (file.getParent() != null) {
-            answer.setRelativeFileName(file.getParent() + "/" + file.getName());
+            answer.setRelativeFileName(file.getParent() + File.separator + file.getName());
         } else {
             answer.setRelativeFileName(file.getName());
         }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java?rev=739191&r1=739190&r2=739191&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
Fri Jan 30 06:26:07 2009
@@ -159,7 +159,7 @@
                 loadConverterMethods(registry, superclass);
             }
         } catch (NoClassDefFoundError e) {
-            LOG.warn("Ignoring converter type: " + type.getName() + " as a dependent class
could not be found: " + e, e);
+            LOG.warn("Ignoring converter type: " + type.getCanonicalName() + " as a dependent
class could not be found: " + e, e);
         }
     }
 



Mime
View raw message