本文整理汇总了Java中org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException类的典型用法代码示例。如果您正苦于以下问题:Java ExpressionVisitException类的具体用法?Java ExpressionVisitException怎么用?Java ExpressionVisitException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExpressionVisitException类属于org.apache.olingo.server.api.uri.queryoption.expression包,在下文中一共展示了ExpressionVisitException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitUnaryOperator
import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException; //导入依赖的package包/类
@Override
public Object visitUnaryOperator(UnaryOperatorKind operator, Object operand)
throws ExpressionVisitException, ODataApplicationException {
String sparqlunary = "";
switch (operator) {
case MINUS:
sparqlunary = "-";
break;
case NOT:
sparqlunary = "!";
break;
default:
throw new UnsupportedOperationException("Unsupported unary: " + operator.toString());
}
return sparqlunary;
}
示例2: readReferenceCollection
import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException; //导入依赖的package包/类
static public EntityCollection readReferenceCollection(RdfEdmProvider rdfEdmProvider, UriInfo uriInfo,
UriType uriType) throws OData2SparqlException, EdmException, ODataApplicationException, ExpressionVisitException {
List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
RdfEntityType rdfEntityType = null;
EdmEntitySet edmEntitySet = null;
UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0);
edmEntitySet = uriResourceEntitySet.getEntitySet();
rdfEntityType = rdfEdmProvider.getRdfEntityTypefromEdmEntitySet(edmEntitySet);
SparqlQueryBuilder sparqlBuilder = new SparqlQueryBuilder(rdfEdmProvider.getRdfModel(),
rdfEdmProvider.getEdmMetadata(), uriInfo, uriType);
//prepareQuery
SparqlStatement sparqlStatement = sparqlBuilder.prepareEntityLinksSparql();
SparqlEntityCollection rdfResults = sparqlStatement.executeConstruct(rdfEdmProvider, rdfEntityType, null, null);
if (rdfResults == null) {
throw new ODataApplicationException("No results", HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(),
Locale.ENGLISH);
} else {
return rdfResults;
}
}
示例3: visitMethodCall
import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException; //导入依赖的package包/类
@Override
public ExpressionMember visitMethodCall(MethodKind methodCall,
List<ExpressionMember> parameters)
throws ExpressionVisitException, ODataApplicationException {
switch (methodCall) {
case CONTAINS:
return parameters.get(0).contains(parameters.get(1));
case STARTSWITH:
return parameters.get(0).startsWith(parameters.get(1));
case ENDSWITH:
return parameters.get(0).endsWith(parameters.get(1));
case DATE:
return parameters.get(0).date();
default:
return throwNotImplemented(
String.format("Method call %s is not implemented", methodCall));
}
}
示例4: visitUnaryOperator
import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException; //导入依赖的package包/类
@Override
public VisitorOperand visitUnaryOperator(final UnaryOperatorKind operator, final VisitorOperand operand)
throws ExpressionVisitException, ODataApplicationException {
final UnaryOperator unaryOperator = new UnaryOperator(operand);
switch (operator) {
case MINUS:
return unaryOperator.minusOperation();
case NOT:
return unaryOperator.notOperation();
default:
// Can't happen.
return throwNotImplemented();
}
}
示例5: visitMember
import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException; //导入依赖的package包/类
@Override
public String visitMember(final Member member) throws ExpressionVisitException, ODataApplicationException {
String ret = "";
for (UriResource item : member.getResourcePath().getUriResourceParts()) {
String tmp = "";
if (item instanceof UriResourceLambdaAll) {
UriResourceLambdaAll all = (UriResourceLambdaAll) item;
tmp = visitLambdaExpression("ALL", all.getLambdaVariable(), all.getExpression());
} else if (item instanceof UriResourceLambdaAny) {
UriResourceLambdaAny any = (UriResourceLambdaAny) item;
tmp = visitLambdaExpression("ANY", any.getLambdaVariable(), any.getExpression());
} else if (item instanceof UriResourcePartTyped) {
UriResourcePartTyped typed = (UriResourcePartTyped) item;
tmp = typed.toString(true);
}
if (ret.length() > 0) {
ret += "/";
}
ret += tmp;
}
return "<" + ret + ">";
}
示例6: isParameterText
import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException; //导入依赖的package包/类
public FilterValidator isParameterText(final int parameterIndex, final String parameterText)
throws ExpressionVisitException, ODataApplicationException {
if (curExpression instanceof MethodImpl) {
MethodImpl methodCall = (MethodImpl) curExpression;
Expression parameter = methodCall.getParameters().get(parameterIndex);
String actualParameterText = FilterTreeToText.Serialize(parameter);
assertEquals(parameterText, actualParameterText);
} else if (curExpression instanceof MemberImpl) {
final MemberImpl member = (MemberImpl) curExpression;
final List<UriResource> uriResourceParts = member.getResourcePath().getUriResourceParts();
if (!uriResourceParts.isEmpty() && uriResourceParts.get(0) instanceof UriResourceFunctionImpl) {
assertEquals(parameterText, ((UriResourceFunctionImpl) uriResourceParts.get(0)).getParameters()
.get(parameterIndex).getText());
} else {
fail("Current expression is not a method or function");
}
} else {
fail("Current expression is not a method or function");
}
return this;
}
示例7: visitMember
import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException; //导入依赖的package包/类
@Override
public Object visitMember(final Member member) throws ExpressionVisitException, ODataApplicationException {
// To keeps things simple, this tutorial allows only primitive properties.
// We have faith that the java type of Edm.Int32 is Integer
final List<UriResource> uriResourceParts = member.getResourcePath().getUriResourceParts();
// Make sure that the resource path of the property contains only a single segment and a primitive property
// has been addressed. We can be sure, that the property exists because the UriParser checks if the
// property has been defined in service metadata document.
if(uriResourceParts.size() == 1 && uriResourceParts.get(0) instanceof UriResourcePrimitiveProperty) {
UriResourcePrimitiveProperty uriResourceProperty = (UriResourcePrimitiveProperty) uriResourceParts.get(0);
return currentEntity.getProperty(uriResourceProperty.getProperty().getName()).getValue();
} else {
// The OData specification allows in addition complex properties and navigation properties
// with a target cardinality 0..1 or 1.
// This means any combination can occur e.g. Supplier/Address/City
// -> Navigation properties Supplier
// -> Complex Property Address
// -> Primitive Property City
// For such cases the resource path returns a list of UriResourceParts
throw new ODataApplicationException("Only primitive properties are implemented in filter expressions",
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ENGLISH);
}
}
示例8: visitLiteral
import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException; //导入依赖的package包/类
@Override
public Object visitLiteral(Literal literal) throws ExpressionVisitException, ODataApplicationException {
// To keep this tutorial simple, our filter expression visitor supports only Edm.Int32 and Edm.String
// In real world scenarios it can be difficult to guess the type of an literal.
// We can be sure, that the literal is a valid OData literal because the URI Parser checks
// the lexicographical structure
// String literals start and end with an single quotation mark
String literalAsString = literal.getText();
if(literal.getType() instanceof EdmString) {
String stringLiteral = "";
if(literal.getText().length() > 2) {
stringLiteral = literalAsString.substring(1, literalAsString.length() - 1);
}
return stringLiteral;
} else {
// Try to convert the literal into an Java Integer
try {
return Integer.parseInt(literalAsString);
} catch(NumberFormatException e) {
throw new ODataApplicationException("Only Edm.Int32 and Edm.String literals are implemented",
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ENGLISH);
}
}
}
示例9: visitUnaryOperator
import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException; //导入依赖的package包/类
@Override
public Object visitUnaryOperator(UnaryOperatorKind operator, Object operand)
throws ExpressionVisitException, ODataApplicationException {
// OData allows two different unary operators. We have to take care, that the type of the operand fits to
// operand
if(operator == UnaryOperatorKind.NOT && operand instanceof Boolean) {
// 1.) boolean negation
return !(Boolean) operand;
} else if(operator == UnaryOperatorKind.MINUS && operand instanceof Integer){
// 2.) arithmetic minus
return -(Integer) operand;
}
// Operation not processed, throw an exception
throw new ODataApplicationException("Invalid type for unary operator",
HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ENGLISH);
}
示例10: visitMember
import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException; //导入依赖的package包/类
public Object visitMember(final Member member) throws ExpressionVisitException, ODataApplicationException {
// To keeps things simple, this tutorial allows only primitive properties.
// We have faith that the java type of Edm.Int32 is Integer
final List<UriResource> uriResourceParts = member.getResourcePath().getUriResourceParts();
// Make sure that the resource path of the property contains only a single segment and a primitive property
// has been addressed. We can be sure, that the property exists because the UriParser checks if the
// property has been defined in service metadata document.
if(uriResourceParts.size() == 1 && uriResourceParts.get(0) instanceof UriResourcePrimitiveProperty) {
UriResourcePrimitiveProperty uriResourceProperty = (UriResourcePrimitiveProperty) uriResourceParts.get(0);
return currentEntity.getProperty(uriResourceProperty.getProperty().getName()).getValue();
} else {
// The OData specification allows in addition complex properties and navigation properties
// with a target cardinality 0..1 or 1.
// This means any combination can occur e.g. Supplier/Address/City
// -> Navigation properties Supplier
// -> Complex Property Address
// -> Primitive Property City
// For such cases the resource path returns a list of UriResourceParts
throw new ODataApplicationException("Only primitive properties are implemented in filter expressions",
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ENGLISH);
}
}
示例11: visitLiteral
import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException; //导入依赖的package包/类
public Object visitLiteral(Literal literal) throws ExpressionVisitException, ODataApplicationException {
// To keep this tutorial simple, our filter expression visitor supports only Edm.Int32 and Edm.String
// In real world scenarios it can be difficult to guess the type of an literal.
// We can be sure, that the literal is a valid OData literal because the URI Parser checks
// the lexicographical structure
// String literals start and end with an single quotation mark
String literalAsString = literal.getText();
if(literal.getType() instanceof EdmString) {
String stringLiteral = "";
if(literal.getText().length() > 2) {
stringLiteral = literalAsString.substring(1, literalAsString.length() - 1);
}
return stringLiteral;
} else {
// Try to convert the literal into an Java Integer
try {
return Integer.parseInt(literalAsString);
} catch(NumberFormatException e) {
throw new ODataApplicationException("Only Edm.Int32 and Edm.String literals are implemented",
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ENGLISH);
}
}
}
示例12: visitUnaryOperator
import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException; //导入依赖的package包/类
public Object visitUnaryOperator(UnaryOperatorKind operator, Object operand)
throws ExpressionVisitException, ODataApplicationException {
// OData allows two different unary operators. We have to take care, that the type of the operand fits to
// operand
if(operator == UnaryOperatorKind.NOT && operand instanceof Boolean) {
// 1.) boolean negation
return !(Boolean) operand;
} else if(operator == UnaryOperatorKind.MINUS && operand instanceof Integer){
// 2.) arithmetic minus
return -(Integer) operand;
}
// Operation not processed, throw an exception
throw new ODataApplicationException("Invalid type for unary operator",
HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ENGLISH);
}
示例13: applyFilterSystemQuery
import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException; //导入依赖的package包/类
/**
* This method applies filter query option to the given entity collection.
*
* @param filterOption Filter option
* @param entitySet Entity collection
* @param edmEntitySet Entity set
* @throws ODataApplicationException
*/
public static void applyFilterSystemQuery(final FilterOption filterOption, final EntityCollection entitySet,
final EdmBindingTarget edmEntitySet) throws ODataApplicationException {
try {
final Iterator<Entity> iter = entitySet.getEntities().iterator();
while (iter.hasNext()) {
final VisitorOperand operand =
filterOption.getExpression().accept(new ExpressionVisitorImpl(iter.next(), edmEntitySet));
final TypedOperand typedOperand = operand.asTypedOperand();
if (typedOperand.is(ODataConstants.primitiveBoolean)) {
if (Boolean.FALSE.equals(typedOperand.getTypedValue(Boolean.class))) {
iter.remove();
}
} else {
throw new ODataApplicationException(
"Invalid filter expression. Filter expressions must return a value of " +
"type Edm.Boolean", HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ROOT);
}
}
} catch (ExpressionVisitException e) {
throw new ODataApplicationException("Exception in filter evaluation",
HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT);
}
}
示例14: visitMember
import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException; //导入依赖的package包/类
@Override
public VisitorOperand visitMember(Member member) throws ExpressionVisitException, ODataApplicationException {
final List<UriResource> uriResourceParts = member.getResourcePath().getUriResourceParts();
int size = uriResourceParts.size();
if (uriResourceParts.get(0) instanceof UriResourceProperty) {
EdmProperty currentEdmProperty = ((UriResourceProperty) uriResourceParts.get(0)).getProperty();
Property currentProperty = entity.getProperty(currentEdmProperty.getName());
return new TypedOperand(currentProperty.getValue(), currentEdmProperty.getType(), currentEdmProperty);
} else if (uriResourceParts.get(size - 1) instanceof UriResourceLambdaAll) {
return throwNotImplemented();
} else if (uriResourceParts.get(size - 1) instanceof UriResourceLambdaAny) {
return throwNotImplemented();
} else {
return throwNotImplemented();
}
}
示例15: visitBinaryOperator
import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException; //导入依赖的package包/类
@Override
public SQLExpression visitBinaryOperator(BinaryOperatorKind operator, SQLExpression left, SQLExpression right)
throws ExpressionVisitException, ODataApplicationException {
switch (operator){
case MUL: return new Multiplication().setLeftExpression(left).setRightExpression(right);
case DIV: return new Division().setLeftExpression(left).setRightExpression(right);
case MOD: return new Function().setName("MOD").setParameters(new ExpressionList(Arrays.asList(left,right)));
case ADD: return new Addition().setLeftExpression(left).setRightExpression(right);
case SUB: return new Subtraction().setLeftExpression(left).setRightExpression(right);
case GT: return new GreaterThan().setLeftExpression(left).setRightExpression(right);
case GE: return new GreaterThanEquals().setLeftExpression(left).setRightExpression(right);
case LT: return new MinorThan().setLeftExpression(left).setRightExpression(right);
case LE: return new MinorThanEquals().setLeftExpression(left).setRightExpression(right);
case EQ: return new EqualsTo().setLeftExpression(left).setRightExpression(right);
case NE: return new NotEqualsTo().setLeftExpression(left).setRightExpression(right);
case AND: return new AndExpression().setLeftExpression(left).setRightExpression(right);
case OR: return new OrExpression().setLeftExpression(left).setRightExpression(right);
default:
break;
}
throw new ODataApplicationException(operator + " operator is not implemented",
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
}