You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2011/08/18 13:33:12 UTC

svn commit: r1159174 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/converter/DateTimeConverter.java main/java/org/apache/camel/impl/converter/CorePackageScanClassResolver.java test/java/org/apache/camel/converter/DateTimeConverterTest.java

Author: davsclaus
Date: Thu Aug 18 11:33:12 2011
New Revision: 1159174

URL: http://svn.apache.org/viewvc?rev=1159174&view=rev
Log:
CAMEL-4348: Added String to TimeZone converter, needed by camel-quartz. Thanks to Bengt for reporting and providing a patch for inspiration.

Added:
    camel/trunk/camel-core/src/main/java/org/apache/camel/converter/DateTimeConverter.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/converter/DateTimeConverterTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/CorePackageScanClassResolver.java

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/converter/DateTimeConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/DateTimeConverter.java?rev=1159174&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/converter/DateTimeConverter.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/converter/DateTimeConverter.java Thu Aug 18 11:33:12 2011
@@ -0,0 +1,36 @@
+/**
+ * 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 java.util.TimeZone;
+
+import org.apache.camel.Converter;
+
+/**
+ * Date and time related converters.
+ */
+@Converter
+public final class DateTimeConverter {
+
+    private DateTimeConverter() {
+    }
+
+    @Converter
+    public static TimeZone toTimeZone(String s) {
+        return TimeZone.getTimeZone(s);
+    }
+}

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/CorePackageScanClassResolver.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/CorePackageScanClassResolver.java?rev=1159174&r1=1159173&r2=1159174&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/CorePackageScanClassResolver.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/CorePackageScanClassResolver.java Thu Aug 18 11:33:12 2011
@@ -25,6 +25,7 @@ import org.apache.camel.component.bean.B
 import org.apache.camel.component.file.GenericFileConverter;
 import org.apache.camel.converter.CamelConverter;
 import org.apache.camel.converter.CollectionConverter;
+import org.apache.camel.converter.DateTimeConverter;
 import org.apache.camel.converter.IOConverter;
 import org.apache.camel.converter.NIOConverter;
 import org.apache.camel.converter.ObjectConverter;
@@ -57,6 +58,7 @@ public class CorePackageScanClassResolve
     public CorePackageScanClassResolver() {
         converters.add(ObjectConverter.class);
         converters.add(CollectionConverter.class);
+        converters.add(DateTimeConverter.class);
         converters.add(IOConverter.class);
         converters.add(NIOConverter.class);
         converters.add(StaxConverter.class);

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/converter/DateTimeConverterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/DateTimeConverterTest.java?rev=1159174&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/converter/DateTimeConverterTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/converter/DateTimeConverterTest.java Thu Aug 18 11:33:12 2011
@@ -0,0 +1,35 @@
+/**
+ * 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 java.util.TimeZone;
+
+import org.apache.camel.ContextTestSupport;
+
+/**
+ *
+ */
+public class DateTimeConverterTest extends ContextTestSupport {
+
+    public void testToTimeZone() throws Exception {
+        String id = TimeZone.getDefault().getID();
+
+        TimeZone zone = context.getTypeConverter().convertTo(TimeZone.class, id);
+        assertNotNull(zone);
+        assertEquals(id, zone.getID());
+    }
+}