camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r681576 - in /activemq/camel/trunk/camel-core/src/main/java/org/apache/camel: impl/DefaultHeaderFilterStrategy.java spi/HeaderFilterStrategy.java
Date Fri, 01 Aug 2008 01:15:40 GMT
Author: ningjiang
Date: Thu Jul 31 18:15:40 2008
New Revision: 681576

URL: http://svn.apache.org/viewvc?rev=681576&view=rev
Log:
CAMEL-766 patch applied with thanks to William

Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultHeaderFilterStrategy.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/HeaderFilterStrategy.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultHeaderFilterStrategy.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultHeaderFilterStrategy.java?rev=681576&r1=681575&r2=681576&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultHeaderFilterStrategy.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultHeaderFilterStrategy.java
Thu Jul 31 18:15:40 2008
@@ -28,8 +28,12 @@
  * add extended filter logic in 
  * {@link #extendedFilter(org.apache.camel.impl.DefaultHeaderFilterStrategy.Direction, String,
Object)}
  * 
- * Filters are associated with directions (in or out).  "In" direction is referred
- * to propagating headers "to" Camel message.
+ * Filters are associated with directions (in or out).  "In" direction is 
+ * referred to propagating headers "to" Camel message.  The "out" direction
+ * is opposite which is referred to propagating headers from Camel message
+ * to a native message like JMS and CXF message.  You can see example of
+ * DefaultHeaderFilterStrategy are being extended and invoked in camel-jms 
+ * and camel-cxf components.
  *
  * @version $Revision$
  */
@@ -45,55 +49,43 @@
 
     private boolean isLowercase;
     private boolean allowNullValues;
-
-    private boolean doFiltering(Direction direction, String headerName, Object headerValue)
{
-        
-        if (headerName == null) {
-            return true;
-        }
-        
-        if (headerValue == null && !allowNullValues) {
-            return true;
-        }
-        
-        Pattern pattern = null;
-        Set<String> filter = null;
-        
-        if (Direction.OUT == direction) {
-            pattern = outFilterPattern;
-            filter = outFilter;                
-        } else if (Direction.IN == direction) {
-            pattern = inFilterPattern;
-            filter = inFilter;
-        }
-   
-        if (pattern != null && pattern.matcher(headerName).matches()) {
-            return true;
-        }
-            
-        if (filter != null) {
-            if (isLowercase) {
-                if (filter.contains(headerName.toLowerCase())) {
-                    return true;
-                }
-            } else {
-                if (filter.contains(headerName)) {
-                    return true;
-                }
-            }
-        }
-            
-        if (extendedFilter(direction, headerName, headerValue)) {
-            return true;
-        }
-            
-        return false;
-    }
     
-    protected boolean extendedFilter(Direction direction, String key, Object value) {
-        return false;
+    /**
+     * Applies filtering logic to Camel Message header that is
+     * going to be copied to target message.
+     * 
+     * It returns true if the filtering logics return a match.  Otherwise,
+     * it returns false.  A match means the header should be excluded.
+     * 
+     * @param headerName 
+     * @param headerValue
+     * @return true if this header should be filtered out.
+     */
+    public boolean applyFilterToCamelHeaders(String headerName, Object headerValue) {
+        return doFiltering(Direction.OUT, headerName, headerValue);
+    }
+
+    /**
+     * Applies filtering logic to an external message header message that 
+     * is going to be copied to Camel message header.
+     * 
+     * It returns true if the filtering logics return a match.  Otherwise,
+     * it returns false.  A match means the header should be excluded.
+     *  
+     * @param headerName 
+     * @param headerValue
+     * @return true if this header should be excluded.
+     */
+    public boolean applyFilterToExternalHeaders(String headerName, Object headerValue) {
+        return doFiltering(Direction.IN, headerName, headerValue);
     }
 
+    /**
+     * Gets the "out" direction filter set.  The "out" direction is referred to 
+     * copying headers from a Camel message to an external message.
+     * 
+     * @return a set that contains header names that should be excluded.
+     */
     public Set<String> getOutFilter() {
         if (outFilter == null) {
             outFilter = new HashSet<String>();
@@ -102,14 +94,37 @@
         return outFilter;
     }
 
+    /**
+     * Sets the "out" direction filter set.  The "out" direction is referred to 
+     * copying headers from a Camel message to an external message.
+     * 
+     * @return a set that contains headers names that should be excluded.
+     */
     public void setOutFilter(Set<String> value) {
         outFilter = value;
     }
 
+    /**
+     * Gets the "out" direction filter regular expression {@link Pattern}.  The
+     * "out" direction is referred to copying headers from Camel message to
+     * an external message.  If the pattern matches a header, the header will 
+     * be filtered out. 
+     * 
+     * @return regular expression filter pattern
+     */
     public String getOutFilterPattern() {
         return outFilterPattern == null ? null : outFilterPattern.pattern();
     }
     
+
+    /**
+     * Sets the "out" direction filter regular expression {@link Pattern}.  The
+     * "out" direction is referred to copying headers from Camel message to
+     * an external message.  If the pattern matches a header, the header will 
+     * be filtered out. 
+     * 
+     * @param value regular expression filter pattern
+     */
     public void setOutFilterPattern(String value) {
         if (value == null) {
             outFilterPattern = null;
@@ -118,6 +133,12 @@
         }
     }
     
+    /**
+     * Gets the "in" direction filter set.  The "in" direction is referred to 
+     * copying headers from an external message to a Camel message.
+     * 
+     * @return a set that contains header names that should be excluded.
+     */
     public Set<String> getInFilter() {
         if (inFilter == null) {
             inFilter = new HashSet<String>();
@@ -125,14 +146,36 @@
         return inFilter;
     }
 
+    /**
+     * Sets the "in" direction filter set.  The "in" direction is referred to 
+     * copying headers from an external message to a Camel message.
+     * 
+     * @return a set that contains headers names that should be excluded.
+     */
     public void setInFilter(Set<String> value) {
         inFilter = value;
     }
 
+    /**
+     * Gets the "in" direction filter regular expression {@link Pattern}.  The
+     * "in" direction is referred to copying headers from an external message
+     * to a Camel message.  If the pattern matches a header, the header will 
+     * be filtered out. 
+     * 
+     * @return regular expression filter pattern
+     */
     public String getInFilterPattern() {
         return inFilterPattern == null ? null : inFilterPattern.pattern();
     }
     
+    /**
+     * Sets the "in" direction filter regular expression {@link Pattern}.  The
+     * "in" direction is referred to copying headers from an external message
+     * to a Camel message.  If the pattern matches a header, the header will 
+     * be filtered out. 
+     * 
+     * @param value regular expression filter pattern
+     */
     public void setInFilterPattern(String value) {
         if (value == null) {
             inFilterPattern = null;
@@ -141,10 +184,22 @@
         }
     }
 
+    /**
+     * Gets the isLowercase property which is a boolean to determinte
+     * whether header names should be converted to lowercase before
+     * checking it the filter Set.  It does not affect filtering using
+     * regular expression pattern.
+     */
     public boolean getIsLowercase() {
         return isLowercase;
     }
     
+    /**
+     * Sets the isLowercase property which is a boolean to determinte
+     * whether header names should be converted to lowercase before
+     * checking it the filter Set.  It does not affect filtering using
+     * regular expression pattern.
+     */
     public void setIsLowercase(boolean value) {
         isLowercase = value;
     }
@@ -155,14 +210,53 @@
     
     public void setAllowNullValues(boolean value) {
         allowNullValues = value;
-    }
+    }   
 
-    public boolean applyFilterToCamelHeaders(String headerName, Object headerValue) {
-        return doFiltering(Direction.OUT, headerName, headerValue);
+    protected boolean extendedFilter(Direction direction, String key, Object value) {
+        return false;
     }
 
-    public boolean applyFilterToExternalHeaders(String headerName, Object headerValue) {
-        return doFiltering(Direction.IN, headerName, headerValue);
-    }
+    private boolean doFiltering(Direction direction, String headerName, Object headerValue)
{
+        
+        if (headerName == null) {
+            return true;
+        }
+        
+        if (headerValue == null && !allowNullValues) {
+            return true;
+        }
+        
+        Pattern pattern = null;
+        Set<String> filter = null;
+        
+        if (Direction.OUT == direction) {
+            pattern = outFilterPattern;
+            filter = outFilter;                
+        } else if (Direction.IN == direction) {
+            pattern = inFilterPattern;
+            filter = inFilter;
+        }
    
+        if (pattern != null && pattern.matcher(headerName).matches()) {
+            return true;
+        }
+            
+        if (filter != null) {
+            if (isLowercase) {
+                if (filter.contains(headerName.toLowerCase())) {
+                    return true;
+                }
+            } else {
+                if (filter.contains(headerName)) {
+                    return true;
+                }
+            }
+        }
+            
+        if (extendedFilter(direction, headerName, headerValue)) {
+            return true;
+        }
+            
+        return false;
+    }
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/HeaderFilterStrategy.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/HeaderFilterStrategy.java?rev=681576&r1=681575&r2=681576&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/HeaderFilterStrategy.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/HeaderFilterStrategy.java
Thu Jul 31 18:15:40 2008
@@ -28,6 +28,8 @@
     /**
      * Applies filtering logic to Camel Message header that is
      * going to be copied to target message such as CXF and JMS message.
+     * It returns true if the filtering logics return a match.  Otherwise,
+     * it returns false.  A match means the header should be excluded.
      * 
      * @param headerName 
      * @param headerValue
@@ -40,6 +42,8 @@
      * Applies filtering logic to an external message header such 
      * as CXF and JMS message that is going to be copied to Camel
      * message header.
+     * It returns true if the filtering logics return a match.  Otherwise,
+     * it returns false.  A match means the header should be excluded.
      *  
      * @param headerName 
      * @param headerValue



Mime
View raw message