org.apache.olingo.odata2.api.uri.expression.UnaryExpression Java Examples

The following examples show how to use org.apache.olingo.odata2.api.uri.expression.UnaryExpression. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FunctionalVisitor.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Object visitUnary(UnaryExpression ue, UnaryOperator operator, Object operand)
{
   // operand is a Node<?> (Expression Tree)
   // Returns an instance of Transformer<?> (functional java) as a Node<?> (Expression Tree)
   Transformer trans;
   switch (operator)
   {
      case   NOT: trans = Transformers.not();   break;
      case MINUS: trans = Transformers.minus(); break;

      default:
         throw new UnsupportedOperationException("Unsupported operator: " + operator.toUriLiteral());
   }
   ExecutableExpressionTree.Node param = ExecutableExpressionTree.Node.class.cast(operand);

   return ExecutableExpressionTree.Node.createNode(trans, param);
}
 
Example #2
Source File: FilterParserImpl.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
protected void validateUnaryOperatorTypes(final UnaryExpression unaryExpression)
    throws ExpressionParserInternalError {
  InfoUnaryOperator unOpt = availableUnaryOperators.get(unaryExpression.getOperator().toUriLiteral());
  EdmType operandType = unaryExpression.getOperand().getEdmType();

  if ((operandType == null) && (resourceEntityType == null)) {
    return;
  }

  List<EdmType> actualParameterTypes = new ArrayList<EdmType>();
  actualParameterTypes.add(operandType);

  ParameterSet parameterSet = unOpt.validateParameterSet(actualParameterTypes);
  if (parameterSet != null) {
    unaryExpression.setEdmType(parameterSet.getReturnType());
  }
}
 
Example #3
Source File: SQLVisitor.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Object visitUnary(UnaryExpression unary_expression,
      UnaryOperator operator, Object operand)
{
   switch (operator)
   {
      case MINUS:
      {
         if (operand instanceof Long)
         {
            return -((Long) operand);
         }
         else if (operand instanceof Double)
         {
            return -((Double) operand);
         }
         else
         {
            throw new UnsupportedOperationException("Invalid expression: " +
                  unary_expression.getUriLiteral());
         }
      }
      case NOT:
      {
         return Restrictions.not((Criterion) operand);
      }
      default:
         break;
   }
   throw new UnsupportedOperationException("Unsupported operator: " +
         operator.toUriLiteral());
}
 
Example #4
Source File: DebugInfoUri.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private void appendExpression(final CommonExpression expression, final Writer writer) throws IOException {
  final ExpressionKind kind = expression.getKind();
  writer.append("<span class=\"kind\">")
      .append(kind.toString())
      .append("</span> <span class=\"literal\">")
      .append(kind == ExpressionKind.MEMBER ? ((MemberExpression) expression).getProperty().getUriLiteral() :
          expression.getUriLiteral())
      .append("</span>, type <span class=\"type\">")
      .append(expression.getEdmType().toString())
      .append("</span>");
  if (kind == ExpressionKind.UNARY) {
    writer.append("<ul class=\"expr\"><li>");
    appendExpression(((UnaryExpression) expression).getOperand(), writer);
    writer.append("</li></ul>");
  } else if (kind == ExpressionKind.BINARY) {
    writer.append("<ol class=\"expr\"><li>");
    appendExpression(((BinaryExpression) expression).getLeftOperand(), writer);
    writer.append("</li><li>");
    appendExpression(((BinaryExpression) expression).getRightOperand(), writer);
    writer.append("</li></ol>");
  } else if (kind == ExpressionKind.METHOD) {
    final MethodExpression methodExpression = (MethodExpression) expression;
    if (methodExpression.getParameterCount() > 0) {
      writer.append("<ol class=\"expr\">");
      for (final CommonExpression parameter : methodExpression.getParameters()) {
        writer.append("<li>");
        appendExpression(parameter, writer);
        writer.append("</li>");
      }
      writer.append("</ol>");
    }
  } else if (kind == ExpressionKind.MEMBER) {
    writer.append("<ul class=\"expr\"><li>");
    appendExpression(((MemberExpression) expression).getPath(), writer);
    writer.append("</li></ul>");
  }
}
 
Example #5
Source File: FilterParserImpl.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
protected CommonExpression readUnaryoperator(final Token lookToken, final InfoUnaryOperator unaryOperator)
    throws ExpressionParserException, ExpressionParserInternalError {
  tokenList.expectToken(lookToken.getUriLiteral(), true);

  CommonExpression operand = readElement(null);
  UnaryExpression unaryExpression = new UnaryExpressionImpl(unaryOperator, operand);
  validateUnaryOperatorTypes(unaryExpression); // throws ExpressionInvalidOperatorTypeException

  return unaryExpression;
}
 
Example #6
Source File: JsonVisitor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public Object visitUnary(final UnaryExpression unaryExpression, final UnaryOperator operator, final Object operand) {
  try {
    StringWriter writer = new StringWriter();
    JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer);
    jsonStreamWriter.beginObject().namedStringValueRaw("nodeType", unaryExpression.getKind().toString()).separator()
        .namedStringValueRaw("operator", operator.toUriLiteral()).separator().namedStringValueRaw("type",
            getType(unaryExpression)).separator().name("operand").unquotedValue(operand.toString()).endObject();
    writer.flush();
    return writer.toString();
  } catch (final IOException e) {
    return null;
  }
}
 
Example #7
Source File: VisitorTool.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public Object visitUnary(final UnaryExpression unaryExpression, final UnaryOperator operator, final Object operand) {
  return "{" + operator.toUriLiteral() + " " + operand.toString() + "}";
}
 
Example #8
Source File: ODataParser.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
public Object visitUnary(UnaryExpression unaryExpression, UnaryOperator operator, Object operand) {
    throw new SearchParseException("Unsupported operation visitUnary: " + unaryExpression
        + "," + operator + "," + operand);
}