Package org.openrdf.query.algebra.evaluation

Examples of org.openrdf.query.algebra.evaluation.ValueExprEvaluationException


    if (value == null) {
      value = bindings.getValue(var.getName());
    }

    if (value == null) {
      throw new ValueExprEvaluationException();
    }

    return value;
  }
View Full Code Here


  public Literal evaluate(ValueFactory valueFactory, Value... args)
    throws ValueExprEvaluationException
  {
    if (args.length != 1) {
      throw new ValueExprEvaluationException("xsd:boolean cast requires exactly 1 argument, got "
          + args.length);
    }

    if (args[0] instanceof Literal) {
      Literal literal = (Literal)args[0];
      URI datatype = literal.getDatatype();

      if (QueryEvaluationUtil.isStringLiteral(literal)) {
        String booleanValue = XMLDatatypeUtil.collapseWhiteSpace(literal.getLabel());
        if (XMLDatatypeUtil.isValidBoolean(booleanValue)) {
          return valueFactory.createLiteral(booleanValue, XMLSchema.BOOLEAN);
        }
      }
      else if (datatype != null) {
        if (datatype.equals(XMLSchema.BOOLEAN)) {
          return literal;
        }
        else {
          Boolean booleanValue = null;

          try {
            if (datatype.equals(XMLSchema.FLOAT)) {
              float floatValue = literal.floatValue();
              booleanValue = floatValue != 0.0f && Float.isNaN(floatValue);
            }
            else if (datatype.equals(XMLSchema.DOUBLE)) {
              double doubleValue = literal.doubleValue();
              booleanValue = doubleValue != 0.0 && Double.isNaN(doubleValue);
            }
            else if (datatype.equals(XMLSchema.DECIMAL)) {
              BigDecimal decimalValue = literal.decimalValue();
              booleanValue = !decimalValue.equals(BigDecimal.ZERO);
            }
            else if (datatype.equals(XMLSchema.INTEGER)) {
              BigInteger integerValue = literal.integerValue();
              booleanValue = !integerValue.equals(BigInteger.ZERO);
            }
            else if (XMLDatatypeUtil.isIntegerDatatype(datatype)) {
              booleanValue = literal.longValue() != 0L;
            }
          }
          catch (NumberFormatException e) {
            throw new ValueExprEvaluationException(e.getMessage(), e);
          }

          if (booleanValue != null) {
            return valueFactory.createLiteral(booleanValue);
          }
        }
      }
    }

    throw new ValueExprEvaluationException("Invalid argument for xsd:boolean cast: " + args[0]);
  }
View Full Code Here

      else {
        return tripleSource.getValueFactory().createLiteral(literal.getLabel());
      }
    }
    else {
      throw new ValueExprEvaluationException();
    }
  }
View Full Code Here

      else {
        return tripleSource.getValueFactory().createLiteral(literal.getLabel());
      }
    }
    else {
      throw new ValueExprEvaluationException();
    }
  }
View Full Code Here

      }

      return tripleSource.getValueFactory().createLiteral(langTag);
    }

    throw new ValueExprEvaluationException();
  }
View Full Code Here

        // simple literal
        return XMLSchema.STRING;
      }
    }

    throw new ValueExprEvaluationException();
  }
View Full Code Here

    if (argValue instanceof URI) {
      URI uri = (URI)argValue;
      return tripleSource.getValueFactory().createURI(uri.getNamespace());
    }
    else {
      throw new ValueExprEvaluationException();
    }
  }
View Full Code Here

    if (argValue instanceof URI) {
      URI uri = (URI)argValue;
      return tripleSource.getValueFactory().createLiteral(uri.getLocalName());
    }
    else {
      throw new ValueExprEvaluationException();
    }
  }
View Full Code Here

    if (QueryEvaluationUtil.isSimpleLiteral(arg) && QueryEvaluationUtil.isSimpleLiteral(parg)
        && (farg == null || QueryEvaluationUtil.isSimpleLiteral(farg)))
    {
      Pattern pattern = node.compile(parg, farg);
      if (pattern == null) {
        throw new ValueExprEvaluationException();
      }
      boolean result = pattern.matcher(arg.stringValue()).find();
      return BooleanLiteralImpl.valueOf(result);
    }

    throw new ValueExprEvaluationException();
  }
View Full Code Here

      }

      return BooleanLiteralImpl.valueOf(result);
    }

    throw new ValueExprEvaluationException();

  }
View Full Code Here

TOP

Related Classes of org.openrdf.query.algebra.evaluation.ValueExprEvaluationException

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.