cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [1/3] cxf git commit: Minor changes to allow extending FiqlParser
Date Tue, 22 Nov 2016 10:44:08 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 569678ec8 -> 9d4fb9a8a
  refs/heads/3.1.x-fixes 7e57ca653 -> 5156dd256
  refs/heads/master e47a79f94 -> 301248b26


Minor changes to allow extending FiqlParser


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

Branch: refs/heads/master
Commit: 301248b264c6a7ddef5c367bd4fdf55fbeee24a9
Parents: e47a79f
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
Authored: Tue Nov 22 11:28:27 2016 +0100
Committer: Francesco Chicchiriccò <ilgrosso@apache.org>
Committed: Tue Nov 22 11:28:54 2016 +0100

----------------------------------------------------------------------
 .../jaxrs/ext/search/SimpleSearchCondition.java | 46 ++++++++-------
 .../cxf/jaxrs/ext/search/fiql/FiqlParser.java   | 60 +++++++++++---------
 2 files changed, 59 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/301248b2/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
index c2e79de..96bc33e 100644
--- a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
+++ b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
@@ -22,8 +22,8 @@ import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.EnumSet;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -41,16 +41,16 @@ import org.apache.cxf.jaxrs.ext.search.collections.CollectionCheckInfo;
  */
 public class SimpleSearchCondition<T> implements SearchCondition<T> {
 
-    private static Set<ConditionType> supportedTypes = new HashSet<ConditionType>();
+    protected static final Set<ConditionType> SUPPORTED_TYPES = EnumSet.noneOf(ConditionType.class);
     static {
-        supportedTypes.add(ConditionType.EQUALS);
-        supportedTypes.add(ConditionType.NOT_EQUALS);
-        supportedTypes.add(ConditionType.GREATER_THAN);
-        supportedTypes.add(ConditionType.GREATER_OR_EQUALS);
-        supportedTypes.add(ConditionType.LESS_THAN);
-        supportedTypes.add(ConditionType.LESS_OR_EQUALS);
+        SUPPORTED_TYPES.add(ConditionType.EQUALS);
+        SUPPORTED_TYPES.add(ConditionType.NOT_EQUALS);
+        SUPPORTED_TYPES.add(ConditionType.GREATER_THAN);
+        SUPPORTED_TYPES.add(ConditionType.GREATER_OR_EQUALS);
+        SUPPORTED_TYPES.add(ConditionType.LESS_THAN);
+        SUPPORTED_TYPES.add(ConditionType.LESS_OR_EQUALS);
     }
-    private ConditionType joiningType = ConditionType.AND;
+    private final ConditionType joiningType = ConditionType.AND;
     private T condition;
     
     private List<SearchCondition<T>> scts;
@@ -69,7 +69,7 @@ public class SimpleSearchCondition<T> implements SearchCondition<T>
{
         if (condition == null) {
             throw new IllegalArgumentException("condition is null");
         }
-        if (!supportedTypes.contains(cType)) {
+        if (!SUPPORTED_TYPES.contains(cType)) {
             throw new IllegalArgumentException("unsupported condition type: " + cType.name());
         }
         this.condition = condition;
@@ -83,6 +83,8 @@ public class SimpleSearchCondition<T> implements SearchCondition<T>
{
      * per-getter comparison strategy.
      * 
      * @param getters2operators getters names and operators to be used with them during comparison
+     * @param realGetters 
+     * @param propertyTypeInfo 
      * @param condition template object
      */
     public SimpleSearchCondition(Map<String, ConditionType> getters2operators, 
@@ -102,7 +104,7 @@ public class SimpleSearchCondition<T> implements SearchCondition<T>
{
         }
         this.condition = condition;
         for (ConditionType ct : getters2operators.values()) {
-            if (!supportedTypes.contains(ct)) {
+            if (!SUPPORTED_TYPES.contains(ct)) {
                 throw new IllegalArgumentException("unsupported condition type: " + ct.name());
             }
         }
@@ -114,6 +116,7 @@ public class SimpleSearchCondition<T> implements SearchCondition<T>
{
         this(getters2operators, null, null, condition);
     }
     
+    @Override
     public T getCondition() {
         return condition;
     }
@@ -123,6 +126,7 @@ public class SimpleSearchCondition<T> implements SearchCondition<T>
{
      * <p>
      * When constructor with map is used it returns null.
      */
+    @Override
     public ConditionType getConditionType() {
         if (scts.size() > 1) {
             return joiningType;
@@ -131,6 +135,7 @@ public class SimpleSearchCondition<T> implements SearchCondition<T>
{
         }
     }
 
+    @Override
     public List<SearchCondition<T>> getSearchConditions() {
         if (scts.size() > 1) {
             return Collections.unmodifiableList(scts);
@@ -145,9 +150,9 @@ public class SimpleSearchCondition<T> implements SearchCondition<T>
{
                                                       ConditionType sharedType) {
         if (isBuiltIn(condition)) {
             return Collections.singletonList(
-                (SearchCondition<T>)new PrimitiveSearchCondition<T>(null, condition,
null, sharedType, condition));
+                (SearchCondition<T>)new PrimitiveSearchCondition<>(null, condition,
null, sharedType, condition));
         } else {
-            List<SearchCondition<T>> list = new ArrayList<SearchCondition<T>>();
+            List<SearchCondition<T>> list = new ArrayList<>();
             Map<String, Object> get2val = getGettersAndValues();
             
             Set<String> keySet = get2val != null ? get2val.keySet()
@@ -172,8 +177,8 @@ public class SimpleSearchCondition<T> implements SearchCondition<T>
{
                 CollectionCheckInfo checkInfo = tInfo != null ? tInfo.getCollectionCheckInfo()
: null;
                 
                 PrimitiveSearchCondition<T> pc = checkInfo == null 
-                    ? new PrimitiveSearchCondition<T>(realGetter, rval, genType, ct,
condition)
-                    : new CollectionCheckCondition<T>(realGetter, rval, genType, ct,
condition, checkInfo);    
+                    ? new PrimitiveSearchCondition<>(realGetter, rval, genType, ct,
condition)
+                    : new CollectionCheckCondition<>(realGetter, rval, genType, ct,
condition, checkInfo);    
                 
                 list.add(pc);
                 
@@ -250,6 +255,7 @@ public class SimpleSearchCondition<T> implements SearchCondition<T>
{
      * 
      * @throws IllegalAccessException when security manager disallows reflective call of
getters.
      */
+    @Override
     public boolean isMet(T pojo) {
         for (SearchCondition<T> sc : scts) {
             if (!sc.isMet(pojo)) {
@@ -268,8 +274,8 @@ public class SimpleSearchCondition<T> implements SearchCondition<T>
{
      */
     private Map<String, Object> getGettersAndValues() {
         if (!SearchBean.class.isAssignableFrom(condition.getClass())) {
-            Map<String, Object> getters2values = new HashMap<String, Object>();
-            Beanspector<T> beanspector = new Beanspector<T>(condition);
+            Map<String, Object> getters2values = new HashMap<>();
+            Beanspector<T> beanspector = new Beanspector<>(condition);
             for (String getter : beanspector.getGettersNames()) {
                 Object value = getValue(beanspector, getter, condition);
                 getters2values.put(getter, value);
@@ -295,8 +301,9 @@ public class SimpleSearchCondition<T> implements SearchCondition<T>
{
     }
 
 
+    @Override
     public List<T> findAll(Collection<T> pojos) {
-        List<T> result = new ArrayList<T>();
+        List<T> result = new ArrayList<>();
         for (T pojo : pojos) {
             if (isMet(pojo)) {
                 result.add(pojo);
@@ -309,6 +316,7 @@ public class SimpleSearchCondition<T> implements SearchCondition<T>
{
         return SearchUtils.toSQL(this, table, columns);
     }
     
+    @Override
     public PrimitiveStatement getStatement() {
         if (scts.size() == 1) {
             return scts.get(0).getStatement();
@@ -317,9 +325,9 @@ public class SimpleSearchCondition<T> implements SearchCondition<T>
{
         }
     }
 
+    @Override
     public void accept(SearchConditionVisitor<T, ?> visitor) {
         visitor.visit(this);
     }
     
-    
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/301248b2/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
index 22df572..5329981 100644
--- a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
+++ b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
@@ -71,7 +71,7 @@ public class FiqlParser<T> extends AbstractSearchConditionParser<T>
{
     
     static {
         // operatorsMap
-        OPERATORS_MAP = new HashMap<String, ConditionType>();
+        OPERATORS_MAP = new HashMap<>();
         OPERATORS_MAP.put(GT, ConditionType.GREATER_THAN);
         OPERATORS_MAP.put(GE, ConditionType.GREATER_OR_EQUALS);
         OPERATORS_MAP.put(LT, ConditionType.LESS_THAN);
@@ -79,7 +79,7 @@ public class FiqlParser<T> extends AbstractSearchConditionParser<T>
{
         OPERATORS_MAP.put(EQ, ConditionType.EQUALS);
         OPERATORS_MAP.put(NEQ, ConditionType.NOT_EQUALS);
         
-        CONDITION_MAP = new HashMap<ConditionType, String>();
+        CONDITION_MAP = new HashMap<>();
         CONDITION_MAP.put(ConditionType.GREATER_THAN, GT);
         CONDITION_MAP.put(ConditionType.GREATER_OR_EQUALS, GE);
         CONDITION_MAP.put(ConditionType.LESS_THAN, LT);
@@ -97,8 +97,8 @@ public class FiqlParser<T> extends AbstractSearchConditionParser<T>
{
         COMPARATORS_PATTERN_SINGLE_EQUALS = Pattern.compile(s2);
     }
 
-    private Map<String, ConditionType> operatorsMap = OPERATORS_MAP;
-    private Pattern comparatorsPattern = COMPARATORS_PATTERN;
+    protected Map<String, ConditionType> operatorsMap = OPERATORS_MAP;
+    protected Pattern comparatorsPattern = COMPARATORS_PATTERN;
     /**
      * Creates FIQL parser.
      * 
@@ -125,7 +125,8 @@ public class FiqlParser<T> extends AbstractSearchConditionParser<T>
{
      * 
      * @param tclass - class of T used to create condition objects in built syntax tree.
Class T must have
      *            accessible no-arg constructor and complementary setters to these used in
FIQL expressions.
-     * @param contextProperties            
+     * @param contextProperties
+     * @param beanProperties 
      */
     public FiqlParser(Class<T> tclass, 
                       Map<String, String> contextProperties,
@@ -133,7 +134,7 @@ public class FiqlParser<T> extends AbstractSearchConditionParser<T>
{
         super(tclass, contextProperties, beanProperties);
         
         if (MessageUtils.isTrue(this.contextProperties.get(SUPPORT_SINGLE_EQUALS))) {
-            operatorsMap = new HashMap<String, ConditionType>(operatorsMap);
+            operatorsMap = new HashMap<>(operatorsMap);
             operatorsMap.put("=", ConditionType.EQUALS);
             comparatorsPattern = COMPARATORS_PATTERN_SINGLE_EQUALS;
         }
@@ -161,18 +162,18 @@ public class FiqlParser<T> extends AbstractSearchConditionParser<T>
{
      * @return tree of {@link SearchCondition} objects representing runtime search structure.
      * @throws SearchParseException when expression does not follow FIQL grammar
      */
+    @Override
     public SearchCondition<T> parse(String fiqlExpression) throws SearchParseException
{
         ASTNode<T> ast = parseAndsOrsBrackets(fiqlExpression);
         return ast.build();
     }
 
     private ASTNode<T> parseAndsOrsBrackets(String expr) throws SearchParseException
{
-        List<String> subexpressions = new ArrayList<String>();
-        List<String> operators = new ArrayList<String>();
+        List<String> subexpressions = new ArrayList<>();
+        List<String> operators = new ArrayList<>();
         int level = 0;
         int lastIdx = 0;
-        int idx = 0;
-        for (idx = 0; idx < expr.length(); idx++) {
+        for (int idx = 0; idx < expr.length(); idx++) {
             char c = expr.charAt(idx);
             if (c == '(') {
                 level++;
@@ -222,7 +223,7 @@ public class FiqlParser<T> extends AbstractSearchConditionParser<T>
{
             SubExpression ands = new SubExpression(AND);
             for (; from <= to; from++) {
                 String subex = subexpressions.get(from);
-                ASTNode<T> node = null;
+                ASTNode<T> node;
                 if (subex.startsWith("(")) {
                     node = parseAndsOrsBrackets(subex.substring(1, subex.length() - 1));
                 } else {
@@ -246,7 +247,7 @@ public class FiqlParser<T> extends AbstractSearchConditionParser<T>
{
         }
     }
 
-    private Comparison parseComparison(String expr) throws SearchParseException {
+    protected ASTNode<T> parseComparison(String expr) throws SearchParseException {
         Matcher m = comparatorsPattern.matcher(expr);
         if (m.find()) {
             String propertyName = expr.substring(0, m.start(1));
@@ -271,7 +272,7 @@ public class FiqlParser<T> extends AbstractSearchConditionParser<T>
{
     }
 
     
-    private TypeInfoObject parseType(String originalName, String setter, String value) throws
SearchParseException {
+    protected TypeInfoObject parseType(String originalName, String setter, String value)
throws SearchParseException {
         TypeInfo typeInfo = getTypeInfo(setter, value);
         if (isDecodeQueryValues()) {
             value = UrlUtils.urlDecode(value);
@@ -280,12 +281,13 @@ public class FiqlParser<T> extends AbstractSearchConditionParser<T>
{
         return new TypeInfoObject(object, typeInfo);
     }
     
+    @Override
     protected boolean isCount(String propName) {
         return propName.startsWith(EXTENSION_COUNT_OPEN);
     }
     
     
-    private String unwrapSetter(String setter) {
+    protected String unwrapSetter(String setter) {
         if (setter.startsWith(EXTENSION_COUNT_OPEN) && setter.endsWith(")")) {
             return setter.substring(EXTENSION_COUNT_OPEN.length(), setter.length() - 1);
       
         } else {
@@ -294,13 +296,13 @@ public class FiqlParser<T> extends AbstractSearchConditionParser<T>
{
     }
     
     // node of abstract syntax tree
-    private interface ASTNode<T> {
+    protected interface ASTNode<T> {
         SearchCondition<T> build() throws SearchParseException;
     }
 
     private class SubExpression implements ASTNode<T> {
-        private String operator;
-        private List<ASTNode<T>> subnodes = new ArrayList<ASTNode<T>>();
+        private final String operator;
+        private final List<ASTNode<T>> subnodes = new ArrayList<>();
 
         SubExpression(String operator) {
             this.operator = operator;
@@ -329,24 +331,25 @@ public class FiqlParser<T> extends AbstractSearchConditionParser<T>
{
             return builder.toString();
         }
 
+        @Override
         public SearchCondition<T> build() throws SearchParseException {
-            List<SearchCondition<T>> scNodes = new ArrayList<SearchCondition<T>>();
+            List<SearchCondition<T>> scNodes = new ArrayList<>();
             for (ASTNode<T> node : subnodes) {
                 scNodes.add(node.build());
             }
             if (OR.equals(operator)) {
-                return new OrSearchCondition<T>(scNodes);
+                return new OrSearchCondition<>(scNodes);
             } else {
-                return new AndSearchCondition<T>(scNodes);
+                return new AndSearchCondition<>(scNodes);
             }
             
         }
     }
 
     private class Comparison implements ASTNode<T> {
-        private String name;
-        private String operator;
-        private TypeInfoObject tvalue;
+        private final String name;
+        private final String operator;
+        private final TypeInfoObject tvalue;
 
         Comparison(String name, String operator, TypeInfoObject value) {
             this.name = name;
@@ -360,16 +363,17 @@ public class FiqlParser<T> extends AbstractSearchConditionParser<T>
{
                 + " (" + tvalue.getObject().getClass().getSimpleName() + ")";
         }
 
+        @Override
         public SearchCondition<T> build() throws SearchParseException {
             String templateName = getSetter(name);
             T cond = createTemplate(templateName);
             ConditionType ct = operatorsMap.get(operator);
             
             if (isPrimitive(cond)) {
-                return new SimpleSearchCondition<T>(ct, cond); 
+                return new SimpleSearchCondition<>(ct, cond); 
             } else {
                 String templateNameLCase = templateName.toLowerCase();
-                return new SimpleSearchCondition<T>(Collections.singletonMap(templateNameLCase,
ct),
+                return new SimpleSearchCondition<>(Collections.singletonMap(templateNameLCase,
ct),
                                                     Collections.singletonMap(templateNameLCase,
name),
                                                     Collections.singletonMap(templateNameLCase,
tvalue.getTypeInfo()),
                                                     cond);
@@ -397,9 +401,9 @@ public class FiqlParser<T> extends AbstractSearchConditionParser<T>
{
         }
     }
     
-    static class TypeInfoObject {
-        private Object object;
-        private TypeInfo typeInfo;
+    protected static class TypeInfoObject {
+        private final Object object;
+        private final TypeInfo typeInfo;
         
         TypeInfoObject(Object object, TypeInfo typeInfo) {
             this.object = object;


Mime
View raw message