cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1417884 - in /cxf/branches/2.6.x-fixes: ./ rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/ rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/
Date Thu, 06 Dec 2012 13:46:59 GMT
Author: sergeyb
Date: Thu Dec  6 13:46:58 2012
New Revision: 1417884

URL: http://svn.apache.org/viewvc?rev=1417884&view=rev
Log:
Merged revisions 1417880 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1417880 | sergeyb | 2012-12-06 13:43:44 +0000 (Thu, 06 Dec 2012) | 1 line
  
  Updating SearchContext to accept bean property mappings, and the parser to support Sets
........

Modified:
    cxf/branches/2.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContext.java
    cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
    cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
    svn:mergeinfo = /cxf/trunk:1417880

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContext.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContext.java?rev=1417884&r1=1417883&r2=1417884&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContext.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContext.java
Thu Dec  6 13:46:58 2012
@@ -18,6 +18,8 @@
  */
 package org.apache.cxf.jaxrs.ext.search;
 
+import java.util.Map;
+
 /**
  * Represents the current search expression.
  */
@@ -34,6 +36,18 @@ public interface SearchContext {
      */
     <T> SearchCondition<T> getCondition(Class<T> cls);
     
+    /**
+     * Returns the typed search condition representing 
+     * the search expression which is extracted from 
+     * the request URI
+     * 
+     * @param cls the type of the bean(s) the new search condition will 
+     *        attempt to match
+     * @param beanProperties mapping between search and bean properties       
+     * @return the search condition
+     */
+    <T> SearchCondition<T> getCondition(Class<T> cls, Map<String, String>
beanProperties);
+    
     
     /**
      * Returns the typed search condition representing 
@@ -46,6 +60,18 @@ public interface SearchContext {
      */
     <T> SearchCondition<T> getCondition(String expression, Class<T> cls);
     
+    /**
+     * Returns the typed search condition representing 
+     * the provided search expression
+     * 
+     * @param expression the search expression
+     * @param cls the type of the bean(s) the new search condition will 
+     *        attempt to match
+     * @param beanProperties mapping between search and bean properties       
+     * @return the search condition
+     */
+    <T> SearchCondition<T> getCondition(String expression, Class<T> cls,
Map<String, String> beanProperties);
+    
     
     /**
      * Returns the search expression

Modified: cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java?rev=1417884&r1=1417883&r2=1417884&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
Thu Dec  6 13:46:58 2012
@@ -47,15 +47,24 @@ public class SearchContextImpl implement
         return getCondition(null, cls);
     }
     
+    public <T> SearchCondition<T> getCondition(Class<T> cls, Map<String,
String> beanProperties) {
+        return getCondition(null, cls, beanProperties);
+    }
+    
     public <T> SearchCondition<T> getCondition(String expression, Class<T>
cls) {
-        
+        return getCondition(expression, cls, null);
+    }
+    
+    public <T> SearchCondition<T> getCondition(String expression, 
+                                               Class<T> cls, 
+                                               Map<String, String> beanProperties)
{    
         if (InjectionUtils.isPrimitive(cls)) {
             String errorMessage = "Primitive condition types are not supported"; 
             LOG.warning(errorMessage);
             throw new IllegalArgumentException(errorMessage);
         }
         
-        SearchConditionParser<T> parser = getParser(cls);
+        SearchConditionParser<T> parser = getParser(cls, beanProperties);
         
         String theExpression = expression == null 
             ? getSearchExpression() : expression;
@@ -88,7 +97,7 @@ public class SearchContextImpl implement
         }
     }
     
-    private <T> SearchConditionParser<T> getParser(Class<T> cls) {
+    private <T> SearchConditionParser<T> getParser(Class<T> cls, Map<String,
String> beanProperties) {
         // we can use this method as a parser factory, ex
         // we can get parsers capable of parsing XQuery and other languages
         // depending on the properties set by a user
@@ -100,8 +109,13 @@ public class SearchContextImpl implement
         props.put(SearchUtils.LAX_PROPERTY_MATCH, 
                   (String)message.getContextualProperty(SearchUtils.LAX_PROPERTY_MATCH));
         
-        Map<String, String> beanProps = 
-            CastUtils.cast((Map<?, ?>)message.getContextualProperty(SearchUtils.BEAN_PROPERTY_MAP));
+        Map<String, String> beanProps = null;
+            
+        if (beanProperties == null) {    
+            beanProps = CastUtils.cast((Map<?, ?>)message.getContextualProperty(SearchUtils.BEAN_PROPERTY_MAP));
+        } else {
+            beanProps = beanProperties;
+        }
         
         return new FiqlParser<T>(cls, props, beanProps); 
     }

Modified: cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java?rev=1417884&r1=1417883&r2=1417884&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
Thu Dec  6 13:46:58 2012
@@ -26,6 +26,7 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -298,7 +299,7 @@ public class FiqlParser<T> implements Se
                     try {
                         castedValue = InjectionUtils.convertStringToPrimitive(value, actualType);
                         if (isCollection) {
-                            castedValue = Collections.singletonList(castedValue);
+                            castedValue = getCollectionSingleton(valueType, castedValue);
                         }
                     } catch (Exception e) {
                         throw new SearchParseException("Cannot convert String value \"" +
value
@@ -309,7 +310,7 @@ public class FiqlParser<T> implements Se
                     try {
                         Method setterM = valueType.getMethod("set" + getMethodNameSuffix(setter),
                                                              new Class[]{classType});
-                        Object objectValue = !isCollection ? value : Collections.singletonList(value);
+                        Object objectValue = !isCollection ? value : getCollectionSingleton(valueType,
value);
                         setterM.invoke(ownerBean, new Object[]{objectValue});
                         castedValue = objectValue; 
                     } catch (Throwable ex) {
@@ -367,6 +368,14 @@ public class FiqlParser<T> implements Se
         }
     }
     
+    private Object getCollectionSingleton(Class<?> collectionCls, Object value) {
+        if (Set.class.isAssignableFrom(collectionCls)) {
+            return Collections.singleton(value);
+        } else {
+            return Collections.singletonList(value);
+        }
+    }
+    
     private Object convertToDate(String value) throws SearchParseException {
         try {
             DateFormat df = SearchUtils.getDateFormat(contextProperties);



Mime
View raw message