Package org.modeshape.jcr.query.xpath.XPath

Examples of org.modeshape.jcr.query.xpath.XPath.Literal


                                               OrderBy orderBy ) {
        return new PathExpression(true, steps, orderBy);
    }

    protected Literal literal( String value ) {
        return new Literal(value);
    }
View Full Code Here


                value = value + tokens.consume() + tokens.consume(); // +/-EXP
            }
            try {
                // Convert to a double and then back to a string to get canonical form ...
                String canonical = typeSystem.getDoubleFactory().asString(value);
                return new Literal(canonical);
            } catch (ValueFormatException e) {
                String msg = GraphI18n.expectingLiteralAndUnableToParseAsDouble.text(value, pos.getLine(), pos.getColumn());
                throw new ParsingException(pos, msg);
            }
        }
        // try to parse an a long ...
        String value = sign + number;
        try {
            // Convert to a long and then back to a string to get canonical form ...
            String canonical = typeSystem.getLongFactory().asString(value);
            return new Literal(canonical);
        } catch (ValueFormatException e) {
            String msg = GraphI18n.expectingLiteralAndUnableToParseAsLong.text(value, pos.getLine(), pos.getColumn());
            throw new ParsingException(pos, msg);
        }
    }
View Full Code Here

    protected Literal parseStringLiteral( TokenStream tokens ) {
        boolean removeQuotes = tokens.matches(XPathTokenizer.QUOTED_STRING);
        String value = tokens.consume();
        if (removeQuotes) value = removeQuotes(value);
        return new Literal(value);
    }
View Full Code Here

            translatePredicate(union.getLeft(), tableName, where);
            where.or();
            translatePredicate(union.getRight(), tableName, where);
            where.closeParen();
        } else if (predicate instanceof Literal) {
            Literal literal = (Literal)predicate;
            if (literal.isInteger()) return tableName; // do nothing, since this is a path constraint and is handled elsewhere
        } else if (predicate instanceof AttributeNameTest) {
            // This adds the criteria that the attribute exists, and adds it to the select ...
            AttributeNameTest attribute = (AttributeNameTest)predicate;
            String propertyName = nameFrom(attribute.getNameTest());
            // There is nothing in the JCR 1.0 spec that says that a property constrain implies it should be included in the
            // result columns
            // builder.select(tableName + "." + propertyName);
            where.hasProperty(tableName, propertyName);
        } else if (predicate instanceof NameTest) {
            // This adds the criteria that the child node exists ...
            NameTest childName = (NameTest)predicate;
            String alias = newAlias();
            builder.joinAllNodesAs(alias).onChildNode(tableName, alias);
            if (!childName.isWildcard()) where.nodeName(alias).isEqualTo(nameFrom(childName));
            tableName = alias;
        } else if (predicate instanceof Comparison) {
            Comparison comparison = (Comparison)predicate;
            Component left = comparison.getLeft();
            Component right = comparison.getRight();
            Operator operator = comparison.getOperator();
            if (left instanceof Literal) {
                Component temp = left;
                left = right;
                right = temp;
                operator = operator.reverse();
            }
            if (left instanceof NodeTest) {
                NodeTest nodeTest = (NodeTest)left;
                String propertyName = null;
                if (nodeTest instanceof AttributeNameTest) {
                    AttributeNameTest attribute = (AttributeNameTest)left;
                    propertyName = nameFrom(attribute.getNameTest());
                } else if (nodeTest instanceof NameTest) {
                    NameTest nameTest = (NameTest)left;
                    propertyName = nameFrom(nameTest);
                } else {
                    throw new InvalidQueryException(query,
                                                    "Left hand side of a comparison must be a name test or attribute name test; therefore '"
                                                    + comparison + "' is not valid");
                }
                if (right instanceof Literal) {
                    String value = ((Literal)right).getValue();
                    where.propertyValue(tableName, propertyName).is(operator, value);
                } else if (right instanceof FunctionCall) {
                    FunctionCall call = (FunctionCall)right;
                    NameTest functionName = call.getName();
                    List<Component> parameters = call.getParameters();
                    // Is this a cast ...
                    String castType = CAST_FUNCTION_NAME_TO_TYPE.get(functionName);
                    if (castType != null) {
                        if (parameters.size() == 1 && parameters.get(0).collapse() instanceof Literal) {
                            // The first parameter can be the type name (or table name) ...
                            Literal value = (Literal)parameters.get(0).collapse();
                            where.propertyValue(tableName, propertyName).is(operator).cast(value.getValue()).as(castType);
                        } else {
                            throw new InvalidQueryException(query, "A cast function requires one literal parameter; therefore '"
                                                                   + comparison + "' is not valid");
                        }
                    } else {
View Full Code Here

TOP

Related Classes of org.modeshape.jcr.query.xpath.XPath.Literal

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.