本文整理汇总了Java中org.apache.olingo.server.api.uri.queryoption.expression.Literal类的典型用法代码示例。如果您正苦于以下问题:Java Literal类的具体用法?Java Literal怎么用?Java Literal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Literal类属于org.apache.olingo.server.api.uri.queryoption.expression包,在下文中一共展示了Literal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: accept
import org.apache.olingo.server.api.uri.queryoption.expression.Literal; //导入依赖的package包/类
public void accept(Expression expr) {
if (expr instanceof Alias) {
visit((Alias) expr);
} else if (expr instanceof Binary) {
visit((Binary) expr);
} else if (expr instanceof Enumeration) {
visit((Enumeration) expr);
} else if (expr instanceof LambdaRef) {
visit((LambdaRef) expr);
} else if (expr instanceof Literal) {
visit((Literal) expr);
} else if (expr instanceof Member) {
visit((Member) expr);
} else if (expr instanceof Method) {
visit((Method) expr);
} else if (expr instanceof TypeLiteral) {
visit((TypeLiteral) expr);
} else if (expr instanceof Unary) {
visit((Unary) expr);
}
}
示例2: getFunctionParameters
import org.apache.olingo.server.api.uri.queryoption.expression.Literal; //导入依赖的package包/类
private Map<String, Parameter> getFunctionParameters(final EdmFunction function,
final List<UriParameter> parameters, final UriInfoResource uriInfo) throws DataProviderException {
Map<String, Parameter> values = new HashMap<String, Parameter>();
for (final UriParameter parameter : parameters) {
if (parameter.getExpression() != null && !(parameter.getExpression() instanceof Literal)) {
throw new DataProviderException("Expression in function-parameter value is not supported yet!",
HttpStatusCode.NOT_IMPLEMENTED);
}
final EdmParameter edmParameter = function.getParameter(parameter.getName());
final String text = parameter.getAlias() == null ?
parameter.getText() :
uriInfo.getValueForAlias(parameter.getAlias());
if (text != null) {
try {
values.put(parameter.getName(),
odata.createFixedFormatDeserializer().parameter(text, edmParameter));
} catch (final DeserializerException e) {
throw new DataProviderException("Invalid function parameter.", HttpStatusCode.BAD_REQUEST, e);
}
}
}
return values;
}
示例3: isType
import org.apache.olingo.server.api.uri.queryoption.expression.Literal; //导入依赖的package包/类
public FilterValidator isType(final FullQualifiedName fullName) {
EdmType actualType = null;
if (curExpression instanceof Member) {
actualType = ((Member) curExpression).getType();
} else if (curExpression instanceof TypeLiteral) {
actualType = ((TypeLiteral) curExpression).getType();
} else if (curExpression instanceof Literal) {
actualType = ((Literal) curExpression).getType();
} else if (curExpression instanceof Enumeration) {
actualType = ((Enumeration) curExpression).getType();
} else if (curExpression instanceof Unary) {
actualType = ((UnaryImpl) curExpression).getType();
} else if (curExpression instanceof Binary) {
actualType = ((BinaryImpl) curExpression).getType();
} else if (curExpression instanceof Method) {
actualType = ((MethodImpl) curExpression).getType();
}
assertNotNull("Current expression not typed", actualType);
assertEquals(fullName, actualType.getFullQualifiedName());
return this;
}
示例4: visitLiteral
import org.apache.olingo.server.api.uri.queryoption.expression.Literal; //导入依赖的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);
}
}
}
示例5: visitLiteral
import org.apache.olingo.server.api.uri.queryoption.expression.Literal; //导入依赖的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);
}
}
}
示例6: visitLiteral
import org.apache.olingo.server.api.uri.queryoption.expression.Literal; //导入依赖的package包/类
@Override
public Object visitLiteral(Literal literal)
throws ExpressionVisitException, ODataApplicationException {
String value = literal.getText();
if (literal.getType() instanceof EdmString) {
value = LiteralUtils.unquote(value);
}
return value;
}
示例7: visitLiteral
import org.apache.olingo.server.api.uri.queryoption.expression.Literal; //导入依赖的package包/类
@Override
public Object visitLiteral(Literal literal) throws ExpressionVisitException, ODataApplicationException {
String decodedEntityKey = SparqlEntity.URLDecodeEntityKey(literal.toString());
try{
return "<"+ this.rdfModel.getRdfPrefixes().expandPredicateKey(decodedEntityKey)+">";
} catch(Exception e) {
switch (literal.getType().toString()) {
case "Null":
return "null";
case "Edm.Time":
return "\"" + literal.getText() + "\"^^xsd:time";
case "Edm.Date":
return "\"" + literal.getText() + "\"^^xsd:date";
case "Edm.DateTime":
return "\"" + literal.getText() + "\"^^xsd:dateTime";
case "Edm.DateTimeOffset":
case "Edm.String":
return "\"" + literal.getText().substring(1, literal.getText().length() - 1) + "\"";
case "Edm.Guid":
return "guid\"" + literal.getText() + "\"";
case "Edm.Binary":
return "X\"" + literal.getText() + "\"";
default:
return literal.getText();
}
}
}
示例8: visitLiteral
import org.apache.olingo.server.api.uri.queryoption.expression.Literal; //导入依赖的package包/类
@Override
public ExpressionMember visitLiteral(Literal literal)
throws ExpressionVisitException, ODataApplicationException {
String literalAsString = literal.getText();
EdmType type = literal.getType();
return new LiteralMember(literalAsString, type);
}
示例9: visit
import org.apache.olingo.server.api.uri.queryoption.expression.Literal; //导入依赖的package包/类
@Override
public void visit(Literal expr) {
Object value = LiteralParser.parseLiteral(expr.getText());
if (this.prepared) {
stack.add(new Reference(this.params.size()));
this.params.add(new SQLParam(value, JDBCSQLTypeInfo.getSQLTypeFromClass(value.getClass().getName())));
} else {
this.stack.add(new Constant(value));
}
}
示例10: read
import org.apache.olingo.server.api.uri.queryoption.expression.Literal; //导入依赖的package包/类
public Entity read(final EdmEntityType edmEntityType, final EntityCollection entitySet,
final List<UriParameter> keys) throws DataProviderException {
try {
for (final Entity entity : entitySet.getEntities()) {
boolean found = true;
for (final UriParameter key : keys) {
EdmKeyPropertyRef refType = edmEntityType.getKeyPropertyRef(key.getName());
Object value = findPropertyRefValue(entity, refType);
final EdmProperty property = refType.getProperty();
final EdmPrimitiveType type = (EdmPrimitiveType) property.getType();
if (key.getExpression() != null && !(key.getExpression() instanceof Literal)) {
throw new DataProviderException("Expression in key value is not supported yet!",
HttpStatusCode.NOT_IMPLEMENTED);
}
final String text = key.getAlias() == null ? key.getText() : ((Literal) key.getExpression()).getText();
final Object keyValue = type.valueOfString(type.fromUriLiteral(text),
property.isNullable(), property.getMaxLength(), property.getPrecision(), property.getScale(),
property.isUnicode(),
Calendar.class.isAssignableFrom(value.getClass()) ? Calendar.class : value.getClass());
if (!value.equals(keyValue)) {
found = false;
break;
}
}
if (found) {
return entity;
}
}
return null;
} catch (final EdmPrimitiveTypeException e) {
throw new DataProviderException("Wrong key!", HttpStatusCode.BAD_REQUEST, e);
}
}
示例11: readDataFromEntity
import org.apache.olingo.server.api.uri.queryoption.expression.Literal; //导入依赖的package包/类
public Entity readDataFromEntity(final EdmEntityType edmEntityType,
final List<UriParameter> keys) throws DataProviderException {
EntityCollection coll = data.get(edmEntityType.getName());
List<Entity> entities = coll.getEntities();
try {
for (final Entity entity : entities) {
boolean found = true;
for (final UriParameter key : keys) {
EdmKeyPropertyRef refType = edmEntityType.getKeyPropertyRef(key.getName());
Object value = findPropertyRefValue(entity, refType);
final EdmProperty property = refType.getProperty();
final EdmPrimitiveType type = (EdmPrimitiveType) property.getType();
if (key.getExpression() != null && !(key.getExpression() instanceof Literal)) {
throw new DataProviderException("Expression in key value is not supported yet!",
HttpStatusCode.NOT_IMPLEMENTED);
}
final String text = key.getAlias() == null ? key.getText() : ((Literal) key.getExpression()).getText();
final Object keyValue = type.valueOfString(type.fromUriLiteral(text),
property.isNullable(), property.getMaxLength(), property.getPrecision(), property.getScale(),
property.isUnicode(),
Calendar.class.isAssignableFrom(value.getClass()) ? Calendar.class : value.getClass());
if (!value.equals(keyValue)) {
found = false;
break;
}
}
if (found) {
return entity;
}
}
return null;
} catch (final EdmPrimitiveTypeException e) {
throw new DataProviderException("Wrong key!", HttpStatusCode.BAD_REQUEST, e);
}
}
示例12: visitLiteral
import org.apache.olingo.server.api.uri.queryoption.expression.Literal; //导入依赖的package包/类
@Override
public JsonNode visitLiteral(final Literal literal) throws ExpressionVisitException, ODataApplicationException {
return nodeFactory.objectNode()
.put(NODE_TYPE_NAME, LITERAL_NAME)
.put(TYPE_NAME, getTypeString(literal.getType()))
.put(VALUE_NAME, literal.getText());
}
示例13: getType
import org.apache.olingo.server.api.uri.queryoption.expression.Literal; //导入依赖的package包/类
protected static EdmType getType(final Expression expression) throws UriParserException {
EdmType type;
if (expression instanceof Literal) {
type = ((Literal) expression).getType();
} else if (expression instanceof TypeLiteral) {
type = ((TypeLiteral) expression).getType();
} else if (expression instanceof Enumeration) {
type = ((Enumeration) expression).getType();
} else if (expression instanceof Member) {
type = ((Member) expression).getType();
} else if (expression instanceof Unary) {
type = ((UnaryImpl) expression).getType();
} else if (expression instanceof Binary) {
type = ((BinaryImpl) expression).getType();
} else if (expression instanceof Method) {
type = ((MethodImpl) expression).getType();
} else if (expression instanceof Alias) {
final AliasQueryOption alias = ((AliasImpl) expression).getAlias();
type = alias == null || alias.getValue() == null ? null : getType(alias.getValue());
} else if (expression instanceof LambdaRef) {
throw new UriParserSemanticException("Type determination not implemented.",
UriParserSemanticException.MessageKeys.NOT_IMPLEMENTED, expression.toString());
} else {
throw new UriParserSemanticException("Unknown expression type.",
UriParserSemanticException.MessageKeys.NOT_IMPLEMENTED, expression.toString());
}
if (type != null && type.getKind() == EdmTypeKind.DEFINITION) {
type = ((EdmTypeDefinition) type).getUnderlyingType();
}
return type;
}
示例14: visitLiteral
import org.apache.olingo.server.api.uri.queryoption.expression.Literal; //导入依赖的package包/类
@Override
public SQLExpression visitLiteral(Literal literal) throws ExpressionVisitException, ODataApplicationException {
String literalAsString = literal.getText();
if(literal.getType() instanceof EdmString) {
return new StringValue(literal.getText());
} else {
try {
return new LongValue(literalAsString);
} catch(NumberFormatException e) {
throw new ODataApplicationException("Only Edm.Int32 and Edm.String literals are implemented",
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ENGLISH);
}
}
}
示例15: visit
import org.apache.olingo.server.api.uri.queryoption.expression.Literal; //导入依赖的package包/类
void visit(@SuppressWarnings("unused") Literal expr) {
}