activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r523731 [2/2] - in /activemq/camel/trunk: camel-core/ camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/builder/xpath/ camel-core/src/main/java/org/apache/camel/converter/ camel-core/src/main/java/org/apac...
Date Thu, 29 Mar 2007 14:58:22 GMT
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?view=diff&rev=523731&r1=523730&r2=523731
==============================================================================
--- 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
Thu Mar 29 07:58:08 2007
@@ -16,15 +16,19 @@
  */
 package org.apache.camel.util;
 
-import java.util.Arrays;
+import org.apache.camel.converter.ObjectConverter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Iterator;
 
 /**
  * @version $Revision$
  */
 public class ObjectHelper {
+    private static final transient Log log = LogFactory.getLog(ObjectHelper.class);
+
     /**
      * A helper method for comparing objects for equality while handling nulls
      */
@@ -86,26 +90,6 @@
 	}
 
     /**
-     * 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
-     */
-    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()) {
-            return Arrays.asList(value).iterator();
-        }
-        else {
-            return Collections.singletonList(value).iterator();
-        }
-    }
-
-    /**
      * Returns true if the collection contains the specified value
      */
     public static boolean contains(Object collectionOrArray, Object value) {
@@ -114,7 +98,7 @@
             return collection.contains(value);
         }
         else {
-            Iterator iter = iterator(value);
+            Iterator iter = ObjectConverter.iterator(value);
             while (iter.hasNext()) {
                 if (equals(value, iter.next())) {
                     return true;
@@ -124,22 +108,26 @@
         }
     }
 
+    public static boolean isNotNullOrBlank(String text) {
+        return text != null && text.trim().length() > 0;
+    }
+
     /**
-     * Converts the given value to a boolean, handling strings or Boolean objects; otherwise
returning true if non-null
+     * A helper method to access a system property, catching any security exceptions
+     *
+     * @param name the name of the system property required
+     * @param defaultValue the default value to use if the property is not available or a
security exception prevents access
+     * @return the system property value or the default value if the property is not available
or security does not allow its access
      */
-    public static boolean toBoolean(Object value) {
-        if (value instanceof Boolean) {
-            return (Boolean) value;
-        }
-        if (value instanceof String) {
-            return "true".equalsIgnoreCase(value.toString());
+    public static String getSystemProperty(String name, String defaultValue) {
+        try {
+            return System.getProperty(name, defaultValue);
+        }
+        catch (Exception e) {
+            if (log.isDebugEnabled()) {
+                log.debug("Caught security exception accessing system property: " + name
+ ". Reason: " + e, e);
+            }
+            return defaultValue;
         }
-        return value != null;
-    }
-
-
-
-    public static boolean isNotNullOrBlank(String text) {
-        return text != null && text.trim().length() > 0;
     }
 }

Added: activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/TypeConverter?view=auto&rev=523731
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
(added)
+++ activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
Thu Mar 29 07:58:08 2007
@@ -0,0 +1 @@
+org.apache.camel.converter
\ No newline at end of file

Modified: activemq/camel/trunk/camel-core/src/test/ide-resources/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/ide-resources/log4j.properties?view=diff&rev=523731&r1=523730&r2=523731
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/ide-resources/log4j.properties (original)
+++ activemq/camel/trunk/camel-core/src/test/ide-resources/log4j.properties Thu Mar 29 07:58:08
2007
@@ -18,7 +18,7 @@
 #
 # The logging properties used for eclipse testing, We want to see debug output on the console.
 #
-log4j.rootLogger=INFO, out
+log4j.rootLogger=DEBUG, out
 
 #log4j.logger.org.apache.activemq=DEBUG
 log4j.logger.org.apache.camel=DEBUG

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java?view=auto&rev=523731
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java
(added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java
Thu Mar 29 07:58:08 2007
@@ -0,0 +1,45 @@
+/**
+ *
+ * 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.converter;
+
+import junit.framework.TestCase;
+import org.apache.camel.TypeConverter;
+import org.apache.camel.impl.converter.DefaultTypeConverter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @version $Revision$
+ */
+public class ConverterTest extends TestCase {
+    private static final transient Log log = LogFactory.getLog(ConverterTest.class);
+
+    protected TypeConverter converter = new DefaultTypeConverter();
+    
+    public void testConvert() throws Exception {
+        byte[] array = converter.convertTo(byte[].class, "foo");
+        assertNotNull(array);
+
+        log.debug("Found array of size: " + array.length);
+
+        // lets now convert back again
+
+        String text = converter.convertTo(String.class, array);
+        assertEquals("Converted to String", "foo", text);
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/JaxpTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/JaxpTest.java?view=auto&rev=523731
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/JaxpTest.java
(added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/JaxpTest.java
Thu Mar 29 07:58:08 2007
@@ -0,0 +1,46 @@
+/**
+ *
+ * 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.converter;
+
+import junit.framework.TestCase;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.camel.TypeConverter;
+import org.apache.camel.impl.converter.DefaultTypeConverter;
+import org.w3c.dom.Document;
+
+/**
+ * @version $Revision$
+ */
+public class JaxpTest extends TestCase {
+    private static final transient Log log = LogFactory.getLog(JaxpTest.class);
+
+    protected TypeConverter converter = new DefaultTypeConverter();
+
+    public void testConvert() throws Exception {
+        Document document = converter.convertTo(Document.class, "<?xml version=\"1.0\"
encoding=\"UTF-8\"?><hello>world!</hello>");
+        assertNotNull(document);
+
+        log.debug("Found document: " + document);
+
+        // lets now convert back again
+
+        String text = converter.convertTo(String.class, document);
+        assertEquals("Converted to String", "<?xml version=\"1.0\" encoding=\"UTF-8\"?><hello>world!</hello>",
text);
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/JaxpTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/JaxpTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/JaxpTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: activemq/camel/trunk/camel-core/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/resources/log4j.properties?view=diff&rev=523731&r1=523730&r2=523731
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/resources/log4j.properties (original)
+++ activemq/camel/trunk/camel-core/src/test/resources/log4j.properties Thu Mar 29 07:58:08
2007
@@ -18,10 +18,10 @@
 #
 # The logging properties used for eclipse testing, We want to see debug output on the console.
 #
-log4j.rootLogger=INFO, out
+log4j.rootLogger=DEBUG, out
 
 #log4j.logger.org.apache.activemq=DEBUG
-#log4j.logger.org.apache.camel=DEBUG
+log4j.logger.org.apache.camel=DEBUG
 
 # CONSOLE appender not used by default
 log4j.appender.out=org.apache.log4j.ConsoleAppender

Modified: activemq/camel/trunk/camel-script/src/main/java/org/apache/camel/builder/script/ScriptBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-script/src/main/java/org/apache/camel/builder/script/ScriptBuilder.java?view=diff&rev=523731&r1=523730&r2=523731
==============================================================================
--- activemq/camel/trunk/camel-script/src/main/java/org/apache/camel/builder/script/ScriptBuilder.java
(original)
+++ activemq/camel/trunk/camel-script/src/main/java/org/apache/camel/builder/script/ScriptBuilder.java
Thu Mar 29 07:58:08 2007
@@ -21,7 +21,7 @@
 import org.apache.camel.Expression;
 import org.apache.camel.Predicate;
 import org.apache.camel.Processor;
-import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.converter.ObjectConverter;
 import org.springframework.core.io.FileSystemResource;
 import org.springframework.core.io.Resource;
 import org.springframework.core.io.UrlResource;
@@ -36,8 +36,6 @@
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
 
 /**
  * A builder class for creating {@link Processor}, {@link Expression} and {@link Predicate}
objects using
@@ -72,7 +70,7 @@
     }
 
     public boolean matches(E exchange) {
-        return ObjectHelper.toBoolean(evaluateScript(exchange));
+        return ObjectConverter.toBoolean(evaluateScript(exchange));
     }
 
     public void onExchange(E exchange) {



Mime
View raw message