cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [2/3] cxf git commit: Minor changes to allow extending FiqlParser
Date Tue, 22 Nov 2016 10:44:09 GMT
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/9d4fb9a8
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/9d4fb9a8
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/9d4fb9a8

Branch: refs/heads/3.0.x-fixes
Commit: 9d4fb9a8aefddb7d6ba6c4520e7049c2c13bc6e6
Parents: 569678e
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:43:16 2016 +0100

----------------------------------------------------------------------
 .../jaxrs/ext/search/SimpleSearchCondition.java | 32 ++++++++++------
 .../cxf/jaxrs/ext/search/fiql/FiqlParser.java   | 40 +++++++++++---------
 2 files changed, 42 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/9d4fb9a8/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..b76beb4 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);
@@ -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)) {
@@ -295,6 +301,7 @@ public class SimpleSearchCondition<T> implements SearchCondition<T>
{
     }
 
 
+    @Override
     public List<T> findAll(Collection<T> pojos) {
         List<T> result = new ArrayList<T>();
         for (T pojo : pojos) {
@@ -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/9d4fb9a8/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 ef97c97..7df2977 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
@@ -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,
@@ -161,6 +162,7 @@ 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();
@@ -171,8 +173,7 @@ public class FiqlParser<T> extends AbstractSearchConditionParser<T>
{
         List<String> operators = new ArrayList<String>();
         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<ASTNode<T>>();
 
         public SubExpression(String operator) {
             this.operator = operator;
@@ -329,6 +331,7 @@ 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>>();
             for (ASTNode<T> node : subnodes) {
@@ -344,9 +347,9 @@ public class FiqlParser<T> extends AbstractSearchConditionParser<T>
{
     }
 
     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;
 
         public Comparison(String name, String operator, TypeInfoObject value) {
             this.name = name;
@@ -360,6 +363,7 @@ 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);
@@ -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;
         
         public TypeInfoObject(Object object, TypeInfo typeInfo) {
             this.object = object;


Mime
View raw message