cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [1/2] git commit: CXF-5549: Introduce Tika Search Visitor. Added ParamConverterProvider and DefaultParamConverterProvider implementation
Date Fri, 04 Jul 2014 16:28:17 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 5a9bcf36e -> a03443ea9


CXF-5549: Introduce Tika Search Visitor. Added ParamConverterProvider and DefaultParamConverterProvider
implementation


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/b7516fdb
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/b7516fdb
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/b7516fdb

Branch: refs/heads/master
Commit: b7516fdbe543d21c4c90b47cbfb342ee1e59a0e3
Parents: c5752fd
Author: reta <drreta@gmail.com>
Authored: Fri Jul 4 12:27:48 2014 -0400
Committer: reta <drreta@gmail.com>
Committed: Fri Jul 4 12:27:48 2014 -0400

----------------------------------------------------------------------
 .../search/DefaultParamConverterProvider.java   | 136 +++++++++++++++++++
 1 file changed, 136 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/b7516fdb/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/DefaultParamConverterProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/DefaultParamConverterProvider.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/DefaultParamConverterProvider.java
new file mode 100644
index 0000000..db3cfaf
--- /dev/null
+++ b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/DefaultParamConverterProvider.java
@@ -0,0 +1,136 @@
+/**
+ * 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.cxf.jaxrs.ext.search;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.ext.ParamConverter;
+import javax.ws.rs.ext.ParamConverterProvider;
+
+import org.apache.lucene.document.DateTools;
+import org.apache.lucene.document.DateTools.Resolution;
+
+/**
+ * Default ParamConverterProvider with support of primitive Java type converters including
Date.
+ */
+public class DefaultParamConverterProvider implements ParamConverterProvider {
+    private final Map< Class< ? >, ParamConverter< ? > > converters = 
+            new HashMap< Class< ? >, ParamConverter< ? > >();
+    
+    /**
+     * Date type converter. 
+     */
+    private static class DateParamConverter implements ParamConverter< Date > {
+        @Override
+        public Date fromString(final String value) {
+            return SearchUtils.dateFromStringWithDefaultFormats(value);
+        }
+        
+        @Override
+        public String toString(final Date value) {
+            return DateTools.dateToString(value, Resolution.MILLISECOND);
+        }
+    }
+    
+    /**
+     * Long type converter. 
+     */
+    private static class LongParamConverter implements ParamConverter< Long > {
+        @Override
+        public Long fromString(final String value) {
+            return Long.valueOf(value);
+        }
+        
+        @Override
+        public String toString(final Long value) {
+            return Long.toString(value);
+        }
+    }
+    
+    /**
+     * Double type converter. 
+     */
+    private static class DoubleParamConverter implements ParamConverter< Double > {
+        @Override
+        public Double fromString(final String value) {
+            return Double.valueOf(value);
+        }
+        
+        @Override
+        public String toString(final Double value) {
+            return Double.toString(value);
+        }
+    }
+    
+    /**
+     * Float type converter. 
+     */
+    private static class FloatParamConverter implements ParamConverter< Float > {
+        @Override
+        public Float fromString(final String value) {
+            return Float.valueOf(value);
+        }
+        
+        @Override
+        public String toString(final Float value) {
+            return Float.toString(value);
+        }
+    }
+    
+    /**
+     * Integer type converter. 
+     */
+    private static class IntegerParamConverter implements ParamConverter< Integer >
{
+        @Override
+        public Integer fromString(final String value) {
+            return Integer.valueOf(value);
+        }
+        
+        @Override
+        public String toString(final Integer value) {
+            return Integer.toString(value);
+        }
+    }
+    
+    public DefaultParamConverterProvider() {
+        converters.put(Date.class, new DateParamConverter());
+        converters.put(Long.class, new LongParamConverter());
+        converters.put(Double.class, new DoubleParamConverter());
+        converters.put(Float.class, new FloatParamConverter());
+        converters.put(Integer.class, new IntegerParamConverter());
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Override
+    public <T> ParamConverter<T> getConverter(final Class<T> rawType, final
Type genericType, 
+            final Annotation[] annotations) {
+        
+        for (final Class< ? > type: converters.keySet()) {
+            if (type.isAssignableFrom(rawType)) {
+                return (ParamConverter<T>)converters.get(type);                   
    
+            }
+        }
+        
+        return null;
+    }
+}


Mime
View raw message