Author: jstrachan
Date: Mon May 21 07:27:31 2007
New Revision: 540152
URL: http://svn.apache.org/viewvc?view=rev&rev=540152
Log:
added some utility helper methods
Added:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java
(with props)
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Message.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Message.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Message.java?view=diff&rev=540152&r1=540151&r2=540152
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Message.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Message.java
Mon May 21 07:27:31 2007
@@ -37,6 +37,13 @@
* @param messageId
*/
void setMessageId(String messageId);
+
+ /**
+ * Returns the exchange this message is related to
+ *
+ * @return
+ */
+ Exchange getExchange();
/**
* Accesses a specific header
@@ -109,5 +116,4 @@
*/
Message copy();
-
}
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?view=diff&rev=540152&r1=540151&r2=540152
==============================================================================
---
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 May 21 07:27:31 2007
@@ -19,20 +19,24 @@
import org.apache.camel.Converter;
-import java.util.Iterator;
-import java.util.Collections;
-import java.util.Collection;
import java.util.Arrays;
-import java.util.List;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
/**
- * Some core java.lang based
+ * Some core java.lang based
* <a href="http://activemq.apache.org/camel/type-converter.html">Type
Converters</a>
*
* @version $Revision$
*/
@Converter
public class ObjectConverter {
+ public static boolean isCollection(Object value) {
+ // TODO we should handle primitive array types?
+ return value instanceof Collection || (value != null &&
value.getClass().isArray());
+ }
+
/**
* 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
@@ -47,6 +51,7 @@
return collection.iterator();
}
else if (value.getClass().isArray()) {
+ // TODO we should handle primitive array types?
return Arrays.asList(value).iterator();
}
else {
@@ -67,5 +72,4 @@
}
return false;
}
-
}
Added:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java?view=auto&rev=540152
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java
(added)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java
Mon May 21 07:27:31 2007
@@ -0,0 +1,56 @@
+/**
+ *
+ * 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.util;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A number of helper methods for working with collections
+ *
+ * @version $Revision: 1.1 $
+ */
+public class CollectionHelper {
+ /**
+ * Sets the value of the entry in the map for the given key, though if the
map already contains a value for the
+ * given key then the value is appended to a list of values.
+ *
+ * @param map the map to add the entry to
+ * @param key the key in the map
+ * @param value the value to put in the map
+ */
+ public static void appendValue(Map map, Object key, Object value) {
+
+ Object oldValue = map.get(key);
+ if (oldValue != null) {
+ List list;
+ if (oldValue instanceof List) {
+ list = (List) oldValue;
+ }
+ else {
+ list = new ArrayList();
+ list.add(oldValue);
+ }
+ list.add(value);
+ }
+ else {
+ map.put(key, value);
+ }
+ }
+}
Propchange:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java
------------------------------------------------------------------------------
svn:eol-style = native