camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hadr...@apache.org
Subject svn commit: r662664 - in /activemq/camel/trunk/camel-core/src/main/java/org/apache/camel: ./ converter/ impl/ model/ model/dataformat/ processor/ spi/ util/
Date Tue, 03 Jun 2008 06:56:17 GMT
Author: hadrian
Date: Mon Jun  2 23:56:17 2008
New Revision: 662664

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

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Intercept.java
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Processor.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Interceptor.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Intercept.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Intercept.java?rev=662664&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Intercept.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Intercept.java Mon Jun
 2 23:56:17 2008
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel;
+
+/**
+ * An interface which provides the processing logic as a pluggable processor
+ *
+ * @version $Revision:  $
+ */
+public interface Intercept {
+    
+	Processor getInterceptorLogic();
+    
+    void setInterceptorLogic(Processor interceptorLogic);
+}

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Processor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Processor.java?rev=662664&r1=662663&r2=662664&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Processor.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Processor.java Mon Jun
 2 23:56:17 2008
@@ -18,11 +18,11 @@
 
 /**
  * A <a href="http://activemq.apache.org/camel/processor.html">processor</a>
is
- * used to implement the <a
- * href="http://activemq.apache.org/camel/event-driven-consumer.html">Event
- * Driven Consumer</a> and <a
- * href="http://activemq.apache.org/camel/message-translator.html">Message
- * Translater</a> patterns and to process message exchanges.
+ * used to implement the 
+ * <a href="http://activemq.apache.org/camel/event-driven-consumer.html">
+ * Event Driven Consumer</a> and 
+ * <a href="http://activemq.apache.org/camel/message-translator.html">
+ * Message Translator</a> patterns and to process message exchanges.
  * 
  * @version $Revision$
  */

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java?rev=662664&r1=662663&r2=662664&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java
Mon Jun  2 23:56:17 2008
@@ -16,15 +16,11 @@
  */
 package org.apache.camel.converter;
 
-import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Iterator;
-import java.util.List;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
 
 import org.apache.camel.Converter;
+import org.apache.camel.util.ObjectHelper;
 
 /**
  * Some core java.lang based <a
@@ -47,42 +43,12 @@
     }
 
     /**
-     * Creates an iterator over the value if the value is a collection, an
-     * Object[] or a primitive type array; otherwise to simplify the caller's
-     * code, we just create a singleton collection iterator over a single value
+     * Creates an iterator over the value
      */
-    @Converter
+    @SuppressWarnings("unchecked")
+	@Converter
     public static Iterator iterator(Object value) {
-        if (value == null) {
-            return Collections.EMPTY_LIST.iterator();
-        } else if (value instanceof Collection) {
-            Collection collection = (Collection)value;
-            return collection.iterator();
-        } else if (value.getClass().isArray()) {
-            // TODO we should handle primitive array types?
-            List<Object> list = Arrays.asList((Object[]) value);
-            return list.iterator();
-        } else if (value instanceof NodeList) {
-            // lets iterate through DOM results after performing XPaths
-            final NodeList nodeList = (NodeList) value;
-            return new Iterator<Node>() {
-                int idx = -1;
-
-                public boolean hasNext() {
-                    return ++idx < nodeList.getLength();
-                }
-
-                public Node next() {
-                    return nodeList.item(idx);
-                }
-
-                public void remove() {
-                    throw new UnsupportedOperationException();
-                }
-            };
-        } else {
-            return Collections.singletonList(value).iterator();
-        }
+    	return ObjectHelper.createIterator(value);
     }
 
     /**
@@ -106,13 +72,7 @@
      */
     @Converter
     public static Boolean toBoolean(Object value) {
-        if (value instanceof Boolean) {
-            return (Boolean)value;
-        }
-        if (value instanceof String) {
-            return "true".equalsIgnoreCase(value.toString()) ? Boolean.TRUE : Boolean.FALSE;
-        }
-        return null;
+    	return ObjectHelper.toBoolean(value);
     }
 
     /**

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java?rev=662664&r1=662663&r2=662664&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
Mon Jun  2 23:56:17 2008
@@ -24,6 +24,7 @@
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
+import org.apache.camel.Intercept;
 import org.apache.camel.NoSuchEndpointException;
 import org.apache.camel.Processor;
 import org.apache.camel.Route;
@@ -147,7 +148,7 @@
         eventDrivenProcessors.add(processor);
     }
 
-    public void intercept(Interceptor interceptor) {
+    public void intercept(Intercept interceptor) {
 /*
         InterceptorRef block = new InterceptorRef(interceptor);
         RouteType route = getRoute();
@@ -160,7 +161,7 @@
 */
 
         //getRoute().getInterceptors().add(new InterceptorRef(interceptor));
-        lastInterceptor = interceptor;
+        lastInterceptor = (Interceptor)interceptor;
     }
 
     public Processor createProceedProcessor() {

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java?rev=662664&r1=662663&r2=662664&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java
Mon Jun  2 23:56:17 2008
@@ -21,6 +21,7 @@
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlTransient;
 
+import org.apache.camel.Intercept;
 import org.apache.camel.Predicate;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.PredicateBuilder;
@@ -55,16 +56,6 @@
         return interceptor;
     }
 
-/*
-    public void addRoutes(RouteContext routeContext, Collection<Route> routes) throws
Exception {
-        Interceptor interceptor = new Interceptor();
-        routeContext.intercept(interceptor);
-
-        final Processor interceptRoute = routeContext.createProcessor(this);
-        interceptor.setInterceptorLogic(interceptRoute);
-    }
-*/
-
     /**
      * Applies this interceptor only if the given predicate is true
      */

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java?rev=662664&r1=662663&r2=662664&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java
Mon Jun  2 23:56:17 2008
@@ -21,8 +21,8 @@
 import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlRootElement;
 
-import org.apache.camel.converter.ObjectConverter;
 import org.apache.camel.spi.DataFormat;
+import org.apache.camel.util.ObjectHelper;
 
 /**
  * Represents the JAXB2 XML {@link DataFormat}
@@ -64,7 +64,8 @@
 
     @Override
     protected void configureDataFormat(DataFormat dataFormat) {
-        if (ObjectConverter.toBool(getPrettyPrint())) {
+    	Boolean answer = ObjectHelper.toBoolean(getPrettyPrint());
+        if (answer != null && answer.booleanValue()) {
             setProperty(dataFormat, "prettyPrint", Boolean.TRUE);
         }
         setProperty(dataFormat, "contextPath", contextPath);

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Interceptor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Interceptor.java?rev=662664&r1=662663&r2=662664&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Interceptor.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Interceptor.java
Mon Jun  2 23:56:17 2008
@@ -17,6 +17,7 @@
 package org.apache.camel.processor;
 
 import org.apache.camel.Exchange;
+import org.apache.camel.Intercept;
 import org.apache.camel.Processor;
 import org.apache.camel.util.ServiceHelper;
 
@@ -26,7 +27,7 @@
  *
  * @version $Revision$
  */
-public class Interceptor extends DelegateProcessor {
+public class Interceptor extends DelegateProcessor implements Intercept {
     private Processor interceptorLogic;
 
     public Interceptor() {

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java?rev=662664&r1=662663&r2=662664&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java Mon
Jun  2 23:56:17 2008
@@ -21,11 +21,11 @@
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
+import org.apache.camel.Intercept;
 import org.apache.camel.Processor;
 import org.apache.camel.model.FromType;
 import org.apache.camel.model.ProcessorType;
 import org.apache.camel.model.RouteType;
-import org.apache.camel.processor.Interceptor;
 
 /**
  * The context used to activate new routing rules
@@ -70,7 +70,7 @@
 
     void addEventDrivenProcessor(Processor processor);
 
-    void intercept(Interceptor interceptor);
+    void intercept(Intercept interceptor);
 
     Processor createProceedProcessor();
 

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java?rev=662664&r1=662663&r2=662664&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
Mon Jun  2 23:56:17 2008
@@ -24,14 +24,18 @@
 import java.lang.reflect.Method;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.camel.Converter;
 import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.converter.ObjectConverter;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 /**
  * A number of useful helper methods for working with Objects
@@ -131,6 +135,16 @@
         }
     }
 
+    public static Boolean toBoolean(Object value) {
+        if (value instanceof Boolean) {
+            return (Boolean)value;
+        }
+        if (value instanceof String) {
+            return "true".equalsIgnoreCase(value.toString()) ? Boolean.TRUE : Boolean.FALSE;
+        }
+        return null;
+    }
+    
     public static void notNull(Object value, String name) {
         if (value == null) {
             throw new IllegalArgumentException(name + " must be specified");
@@ -190,7 +204,8 @@
     /**
      * Returns true if the collection contains the specified value
      */
-    public static boolean contains(Object collectionOrArray, Object value) {
+    @SuppressWarnings("unchecked")
+	public static boolean contains(Object collectionOrArray, Object value) {
         if (collectionOrArray instanceof Collection) {
             Collection collection = (Collection)collectionOrArray;
             return collection.contains(value);
@@ -199,7 +214,7 @@
             String subStr = (String) value;
             return str.contains(subStr);
         } else {
-            Iterator iter = ObjectConverter.iterator(collectionOrArray);
+            Iterator iter = createIterator(collectionOrArray);
             while (iter.hasNext()) {
                 if (equal(value, iter.next())) {
                     return true;
@@ -210,6 +225,45 @@
     }
 
     /**
+     * Creates an iterator over the value if the value is a collection, an
+     * Object[] or a primitive type array; otherwise to simplify the caller's
+     * code, we just create a singleton collection iterator over a single value
+     */
+    @SuppressWarnings("unchecked")
+    public static Iterator createIterator(Object value) {
+        if (value == null) {
+            return Collections.EMPTY_LIST.iterator();
+        } else if (value instanceof Collection) {
+            Collection collection = (Collection)value;
+            return collection.iterator();
+        } else if (value.getClass().isArray()) {
+            // TODO we should handle primitive array types?
+            List<Object> list = Arrays.asList((Object[]) value);
+            return list.iterator();
+        } else if (value instanceof NodeList) {
+            // lets iterate through DOM results after performing XPaths
+            final NodeList nodeList = (NodeList) value;
+            return new Iterator<Node>() {
+                int idx = -1;
+
+                public boolean hasNext() {
+                    return ++idx < nodeList.getLength();
+                }
+
+                public Node next() {
+                    return nodeList.item(idx);
+                }
+
+                public void remove() {
+                    throw new UnsupportedOperationException();
+                }
+            };
+        } else {
+            return Collections.singletonList(value).iterator();
+        }
+    }
+
+    /**
      * Returns the predicate matching boolean on a {@link List} result set where
      * if the first element is a boolean its value is used otherwise this method
      * returns true if the collection is not empty



Mime
View raw message