本文整理汇总了Java中org.springframework.expression.spel.support.StandardTypeConverter类的典型用法代码示例。如果您正苦于以下问题:Java StandardTypeConverter类的具体用法?Java StandardTypeConverter怎么用?Java StandardTypeConverter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StandardTypeConverter类属于org.springframework.expression.spel.support包,在下文中一共展示了StandardTypeConverter类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testConvertAndHandleNull
import org.springframework.expression.spel.support.StandardTypeConverter; //导入依赖的package包/类
@Test
public void testConvertAndHandleNull() { // SPR-9445
// without null conversion
evaluateAndCheckError("null or true", SpelMessage.TYPE_CONVERSION_ERROR, 0, "null", "boolean");
evaluateAndCheckError("null and true", SpelMessage.TYPE_CONVERSION_ERROR, 0, "null", "boolean");
evaluateAndCheckError("!null", SpelMessage.TYPE_CONVERSION_ERROR, 1, "null", "boolean");
evaluateAndCheckError("null ? 'foo' : 'bar'", SpelMessage.TYPE_CONVERSION_ERROR, 0, "null", "boolean");
// with null conversion (null -> false)
GenericConversionService conversionService = new GenericConversionService() {
@Override
protected Object convertNullSource(TypeDescriptor sourceType, TypeDescriptor targetType) {
return targetType.getType() == Boolean.class ? false : null;
}
};
eContext.setTypeConverter(new StandardTypeConverter(conversionService));
evaluate("null or true", Boolean.TRUE, Boolean.class, false);
evaluate("null and true", Boolean.FALSE, Boolean.class, false);
evaluate("!null", Boolean.TRUE, Boolean.class, false);
evaluate("null ? 'foo' : 'bar'", "bar", String.class, false);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:BooleanExpressionTests.java
示例2: registerConversionServiceInSpelExpressions
import org.springframework.expression.spel.support.StandardTypeConverter; //导入依赖的package包/类
private void registerConversionServiceInSpelExpressions(Expression parsedExpression) {
if (conversionService == null) {
return;
}
StandardTypeConverter converter = new StandardTypeConverter(conversionService);
StandardEvaluationContext context = new StandardEvaluationContext();
context.setTypeConverter(converter);
setContextIfSpelExpression(parsedExpression, context);
if (parsedExpression instanceof CompositeStringExpression) {
CompositeStringExpression composite = (CompositeStringExpression) parsedExpression;
for (Expression childExpresion : composite.getExpressions()) {
setContextIfSpelExpression(childExpresion, context);
}
}
}
开发者ID:DISID,项目名称:springlets,代码行数:17,代码来源:EntityExpressionSupport.java
示例3: CoreMappingEvaluationContext
import org.springframework.expression.spel.support.StandardTypeConverter; //导入依赖的package包/类
public CoreMappingEvaluationContext(Object root) {
super(root);
try {
// Add functions for use in the mapping expressions.
registerFunction("substring", StringUtils.class.getMethod("substring", String.class, int.class, int.class));
registerFunction("upperCase", StringUtils.class.getMethod("upperCase", String.class));
registerFunction("leftPad", StringUtils.class.getMethod("leftPad", String.class, int.class, String.class));
registerFunction("rightPad", StringUtils.class.getMethod("rightPad", String.class, int.class, String.class));
registerFunction("trim", StringUtils.class.getMethod("trim", String.class));
registerFunction("capitalize", WordUtils.class.getMethod("capitalizeFully", String.class));
registerFunction("isBlank", StringUtils.class.getMethod("isBlank", CharSequence.class));
registerFunction("split", StringUtils.class.getMethod("split", String.class, char.class));
registerFunction("join", StringUtils.class.getMethod("join", Object[].class, char.class));
registerFunction("toBoolean", BooleanUtils.class.getMethod("toBoolean", String.class));
DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
conversionService.addFormatterForFieldType(Date.class, new DateFormatter("MM/dd/yyyy"));
setTypeConverter(new StandardTypeConverter(conversionService));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
开发者ID:SmarterApp,项目名称:TechnologyReadinessTool,代码行数:23,代码来源:CoreMappingEvaluationContext.java
示例4: createEvaluationContext
import org.springframework.expression.spel.support.StandardTypeConverter; //导入依赖的package包/类
private EvaluationContext createEvaluationContext(PageContext pageContext) {
StandardEvaluationContext context = new StandardEvaluationContext();
context.addPropertyAccessor(new JspPropertyAccessor(pageContext));
context.addPropertyAccessor(new MapAccessor());
context.addPropertyAccessor(new EnvironmentAccessor());
context.setBeanResolver(new BeanFactoryResolver(getRequestContext().getWebApplicationContext()));
ConversionService conversionService = getConversionService(pageContext);
if (conversionService != null) {
context.setTypeConverter(new StandardTypeConverter(conversionService));
}
return context;
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:EvalTag.java
示例5: test_binaryPlusWithTimeConverted
import org.springframework.expression.spel.support.StandardTypeConverter; //导入依赖的package包/类
@Test
public void test_binaryPlusWithTimeConverted() {
final SimpleDateFormat format = new SimpleDateFormat("hh :--: mm :--: ss", Locale.ENGLISH);
GenericConversionService conversionService = new GenericConversionService();
conversionService.addConverter(new Converter<Time, String>() {
@Override
public String convert(Time source) {
return format.format(source);
}
});
StandardEvaluationContext evaluationContextConverter = new StandardEvaluationContext();
evaluationContextConverter.setTypeConverter(new StandardTypeConverter(conversionService));
ExpressionState expressionState = new ExpressionState(evaluationContextConverter);
Time time = new Time(new Date().getTime());
VariableReference var = new VariableReference("timeVar", -1);
var.setValue(expressionState, time);
StringLiteral n2 = new StringLiteral("\" is now\"", -1, "\" is now\"");
OpPlus o = new OpPlus(-1, var, n2);
TypedValue value = o.getValueInternal(expressionState);
assertEquals(String.class, value.getTypeDescriptor().getObjectType());
assertEquals(String.class, value.getTypeDescriptor().getType());
assertEquals(format.format(time) + " is now", value.getValue());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:32,代码来源:OpPlusTests.java
示例6: evaluate
import org.springframework.expression.spel.support.StandardTypeConverter; //导入依赖的package包/类
public Object evaluate(String value, BeanExpressionContext evalContext) throws BeansException {
if (!StringUtils.hasLength(value)) {
return value;
}
try {
Expression expr = this.expressionCache.get(value);
if (expr == null) {
expr = this.expressionParser.parseExpression(value, this.beanExpressionParserContext);
this.expressionCache.put(value, expr);
}
StandardEvaluationContext sec = this.evaluationCache.get(evalContext);
if (sec == null) {
sec = new StandardEvaluationContext();
sec.setRootObject(evalContext);
sec.addPropertyAccessor(new BeanExpressionContextAccessor());
sec.addPropertyAccessor(new BeanFactoryAccessor());
sec.addPropertyAccessor(new MapAccessor());
sec.addPropertyAccessor(new EnvironmentAccessor());
sec.setBeanResolver(new BeanFactoryResolver(evalContext.getBeanFactory()));
sec.setTypeLocator(new StandardTypeLocator(evalContext.getBeanFactory().getBeanClassLoader()));
ConversionService conversionService = evalContext.getBeanFactory().getConversionService();
if (conversionService != null) {
sec.setTypeConverter(new StandardTypeConverter(conversionService));
}
customizeEvaluationContext(sec);
this.evaluationCache.put(evalContext, sec);
}
return expr.getValue(sec);
}
catch (Exception ex) {
throw new BeanExpressionException("Expression parsing failed", ex);
}
}
开发者ID:deathspeeder,项目名称:class-guard,代码行数:34,代码来源:StandardBeanExpressionResolver.java
注:本文中的org.springframework.expression.spel.support.StandardTypeConverter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论