Package org.apache.cxf.jaxrs.ext.search

Examples of org.apache.cxf.jaxrs.ext.search.SearchParseException


            try {
                Date now = new Date();
                DatatypeFactory.newInstance().newDuration(value).addTo(now);
                return now;
            } catch (DatatypeConfigurationException e1) {
                throw new SearchParseException(e1);
            } catch (IllegalArgumentException e1) {
                throw new SearchParseException("Can parse " + value + " neither as date nor duration", e);
            }
        }
    }
View Full Code Here


                    SearchBean bean = (SearchBean)conditionClass.newInstance();
                    bean.set(setter, tvalue.getObject().toString());
                    return (T)bean;
                }
            } catch (Throwable e) {
                throw new SearchParseException(e);
            }
        }
View Full Code Here

            if (c == '(') {
                level++;
            } else if (c == ')') {
                level--;
                if (level < 0) {
                    throw new SearchParseException(String.format("Unexpected closing bracket at position %d",
                                                               idx));
                }
            }
            String cs = Character.toString(c);
            boolean isOperator = AND.equals(cs) || OR.equals(cs);
            if (level == 0 && isOperator) {
                String s1 = expr.substring(lastIdx, idx);
                String s2 = expr.substring(idx, idx + 1);
                subexpressions.add(s1);
                operators.add(s2);
                lastIdx = idx + 1;
            }
            boolean isEnd = idx == expr.length() - 1;
            if (isEnd) {
                String s1 = expr.substring(lastIdx, idx + 1);
                subexpressions.add(s1);
                operators.add(null);
                lastIdx = idx + 1;
            }
        }
        if (level != 0) {
            throw new SearchParseException(String
                .format("Unmatched opening and closing brackets in expression: %s", expr));
        }
        if (operators.get(operators.size() - 1) != null) {
            String op = operators.get(operators.size() - 1);
            String ex = subexpressions.get(subexpressions.size() - 1);
            throw new SearchParseException("Dangling operator at the end of expression: ..." + ex + op);
        }
        // looking for adjacent ANDs then group them into ORs
        // Note: in case not ANDs is found (e.g only ORs) every single subexpression is
        // treated as "single item group of ANDs"
        int from = 0;
View Full Code Here

        if (m.find()) {
            String name = expr.substring(0, m.start(1));
            String operator = m.group(1);
            String value = expr.substring(m.end(1));
            if ("".equals(value)) {
                throw new SearchParseException("Not a comparison expression: " + expr);
            }
           
            String beanPropertyName = beanPropertiesMap == null ? null : beanPropertiesMap.get(name);
            if (beanPropertyName != null) {
                name = beanPropertyName;
            }
           
            TypeInfoObject castedValue = parseType(name, value);
            if (castedValue != null) {
                return new Comparison(name, operator, castedValue);
            } else if (MessageUtils.isTrue(contextProperties.get(SearchUtils.LAX_PROPERTY_MATCH))) {
                return null;
            } else {
                throw new PropertyNotFoundException(name, value);
            }
        } else {
            throw new SearchParseException("Not a comparison expression: " + expr);
        }
    }
View Full Code Here

                        castedValue = InjectionUtils.convertStringToPrimitive(value, actualType);
                        if (isCollection) {
                            castedValue = getCollectionSingleton(valueType, castedValue);
                        }
                    } catch (Exception e) {
                        throw new SearchParseException("Cannot convert String value \"" + value
                                                     + "\" to a value of class " + valueType.getName(), e);
                    }
                } else {
                    Class<?> classType = isCollection ? valueType : value.getClass();
                    try {
                        Method setterM = valueType.getMethod("set" + getMethodNameSuffix(setter),
                                                             new Class[]{classType});
                        Object objectValue = !isCollection ? value : getCollectionSingleton(valueType, value);
                        setterM.invoke(ownerBean, new Object[]{objectValue});
                        castedValue = objectValue;
                    } catch (Throwable ex) {
                        throw new SearchParseException("Cannot convert String value \"" + value
                                                       + "\" to a value of class " + valueType.getName(), ex);
                    }
                   
                }
            }
            if (lastCastedValue != null) {
                castedValue = lastCastedValue;
            }
            return castedValue;
        } else {
            String[] names = setter.split("\\.");
            try {
                String nextPart = getMethodNameSuffix(names[1]);
                Method getterM = actualType.getMethod("get" + nextPart, new Class[]{});  
                Class<?> returnType = getterM.getReturnType();
                boolean returnCollection = InjectionUtils.isSupportedCollectionOrArray(returnType);
               
                boolean isPrimitive = InjectionUtils.isPrimitive(returnType) || returnType.isEnum();
                boolean lastTry = names.length == 2
                    && (isPrimitive || returnType == Date.class || returnCollection);
               
                Object valueObject = lastTry && ownerBean != null ? ownerBean : actualType.newInstance();
                Object nextObject;
               
                if (lastTry) {
                    if (!returnCollection) {
                        nextObject = isPrimitive ? InjectionUtils.convertStringToPrimitive(value, returnType)
                            : convertToDate(value);
                    } else {
                        nextObject = Collections.singletonList(value);
                    }
                } else {
                    nextObject = returnType.newInstance();
                }
               
                Method setterM = actualType.getMethod("set" + nextPart, new Class[]{returnType});
                setterM.invoke(valueObject, new Object[]{nextObject});
               
                lastCastedValue = lastCastedValue == null ? valueObject : lastCastedValue;
                if (lastTry) {
                    return isCollection ? Collections.singletonList(lastCastedValue) : lastCastedValue;
                }
               
                TypeInfo nextTypeInfo = new TypeInfo(nextObject.getClass(), getterM.getGenericReturnType());
                return parseType(nextObject, lastCastedValue, setter.substring(index + 1),
                                 nextTypeInfo, value);
            } catch (Throwable e) {
                throw new SearchParseException("Cannot convert String value \"" + value
                                               + "\" to a value of class " + valueType.getName(), e);
            }
        }
    }
View Full Code Here

            try {
                Date now = new Date();
                DatatypeFactory.newInstance().newDuration(value).addTo(now);
                return now;
            } catch (DatatypeConfigurationException e1) {
                throw new SearchParseException(e1);
            } catch (IllegalArgumentException e1) {
                throw new SearchParseException("Can parse " + value + " neither as date nor duration", e);
            }
        }
    }
View Full Code Here

                    SearchBean bean = (SearchBean)conditionClass.newInstance();
                    bean.set(setter, tvalue.getObject().toString());
                    return (T)bean;
                }
            } catch (Throwable e) {
                throw new SearchParseException(e);
            }
        }
View Full Code Here

            final T condition = conditionClass.newInstance();
            final FilterExpression expression = parser.parseFilterString(searchExpression);
            final FilterExpressionVisitor visitor = new FilterExpressionVisitor(condition);           
            return (SearchCondition< T >)expression.accept(visitor);           
        } catch (ODataMessageException ex) {
            throw new SearchParseException(ex);
        } catch (ODataApplicationException ex) {
            throw new SearchParseException(ex);
        } catch (InstantiationException ex) {
            throw new SearchParseException(ex);
        } catch (IllegalAccessException ex) {
            throw new SearchParseException(ex);
        }
    }
View Full Code Here

                        return new AndSearchCondition< T >(conditions);
                    } else if (operator == BinaryOperator.OR) {
                        return new OrSearchCondition< T >(conditions);
                    }
                } else {
                    throw new SearchParseException(
                        "Unsupported binary operation arguments (SearchCondition expected): "
                            + leftSide + ", " + rightSide);
                }
            }

            // Property could be either on left side (Name eq 'Tom') or
            // right side ('Tom' eq Name)
            TypedValue value = null;
            TypedProperty property = null;
           
            if (leftSide instanceof TypedProperty && rightSide instanceof TypedValue) {
                property = (TypedProperty)leftSide;
                value = (TypedValue)rightSide;
            } else if (rightSide instanceof TypedProperty && leftSide instanceof TypedValue) {
                property = (TypedProperty)rightSide;
                value = (TypedValue)leftSide;
            } else {
                throw new SearchParseException(
                    "Unsupported binary operation arguments (TypedValue or TypedProperty expected): "
                        + leftSide + ", " + rightSide);
            }
                      
            ConditionType conditionType = null;
            switch (operator) {
            case EQ:   
                conditionType = ConditionType.EQUALS;
                break;
            case NE:
                conditionType = ConditionType.NOT_EQUALS;
                break;
            case LT:
                conditionType = ConditionType.LESS_THAN;
                break;
            case LE:
                conditionType = ConditionType.LESS_OR_EQUALS;
                break;
            case GT:
                conditionType = ConditionType.GREATER_THAN;
                break;               
            case GE:
                conditionType = ConditionType.GREATER_OR_EQUALS;
                break;               
            default:
                throw new SearchParseException("Unsupported binary operation: " + operator);
            }
           
            Object typedValue = null;
            // If property type and value type are compatible, just use them
            if (property.typeInfo.getWrappedTypeClass().isAssignableFrom(value.typeClass)) {
View Full Code Here

                final Object value = type.valueOfString(edmLiteral.getLiteral(),
                    EdmLiteralKind.DEFAULT, null, type.getDefaultType());
               
                return new TypedValue(type.getDefaultType(), edmLiteral.getLiteral(), value);
            } catch (EdmSimpleTypeException ex) {
                throw new SearchParseException("Failed to convert literal to a typed form: " + literal, ex);
            }
        }
View Full Code Here

TOP

Related Classes of org.apache.cxf.jaxrs.ext.search.SearchParseException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.