本文整理汇总了Java中org.springframework.format.Parser类的典型用法代码示例。如果您正苦于以下问题:Java Parser类的具体用法?Java Parser怎么用?Java Parser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Parser类属于org.springframework.format包,在下文中一共展示了Parser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convert
import org.springframework.format.Parser; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
Annotation ann = targetType.getAnnotation(this.annotationType);
if (ann == null) {
throw new IllegalStateException(
"Expected [" + this.annotationType.getName() + "] to be present on " + targetType);
}
AnnotationConverterKey converterKey = new AnnotationConverterKey(ann, targetType.getObjectType());
GenericConverter converter = cachedParsers.get(converterKey);
if (converter == null) {
Parser<?> parser = this.annotationFormatterFactory.getParser(
converterKey.getAnnotation(), converterKey.getFieldType());
converter = new ParserConverter(this.fieldType, parser, FormattingConversionService.this);
cachedParsers.put(converterKey, converter);
}
return converter.convert(source, sourceType, targetType);
}
示例2: getParser
import org.springframework.format.Parser; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Parser<String> getParser(NonEmpty annotation, Class<?> fieldType) {
return new Parser<String>() {
@Override
public String parse(String text, Locale locale)
throws ParseException {
if (!StringUtils.hasText(text)) {
return null;
} else {
return text;
}
}
};
}
示例3: doUpdate
import org.springframework.format.Parser; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected void doUpdate() {
Object value = controlAccessor.getControlValue();
if (controlAccessor.isTextControl()) {
Parser<?> parser = getParser();
if (parser != null)
try {
value = parser.parse((String) value, Locale.getDefault());
} catch (ParseException e) {
log.error("Can't parse String : " + value.toString());
}
}
setValue(value);
}
示例4: convert
import org.springframework.format.Parser; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
AnnotationConverterKey converterKey =
new AnnotationConverterKey(targetType.getAnnotation(annotationType), targetType.getObjectType());
GenericConverter converter = cachedParsers.get(converterKey);
if (converter == null) {
Parser<?> parser = annotationFormatterFactory.getParser(
converterKey.getAnnotation(), converterKey.getFieldType());
converter = new ParserConverter(fieldType, parser, FormattingConversionService.this);
cachedParsers.put(converterKey, converter);
}
return converter.convert(source, sourceType, targetType);
}
示例5: getParser
import org.springframework.format.Parser; //导入依赖的package包/类
@Override
public Parser<?> getParser(DateTimeFormat annotation, Class<?> fieldType) {
if (LocalDate.class.equals(fieldType)) {
return new LocalDateParser(getFormatter(annotation, fieldType));
}
else if (LocalTime.class.equals(fieldType)) {
return new LocalTimeParser(getFormatter(annotation, fieldType));
}
else if (LocalDateTime.class.equals(fieldType)) {
return new LocalDateTimeParser(getFormatter(annotation, fieldType));
}
else {
return new DateTimeParser(getFormatter(annotation, fieldType));
}
}
示例6: addFormatterForFields
import org.springframework.format.Parser; //导入依赖的package包/类
private void addFormatterForFields(FormatterRegistry registry, Printer<?> printer,
Parser<?> parser, Class<?>... fieldTypes) {
for (Class<?> fieldType : fieldTypes) {
registry.addFormatterForFieldType(fieldType, printer, parser);
}
}
示例7: getParser
import org.springframework.format.Parser; //导入依赖的package包/类
@Override
public Parser<?> getParser(DateTimeFormat annotation, Class<?> fieldType) {
if (LocalDate.class == fieldType) {
return new LocalDateParser(getFormatter(annotation, fieldType));
}
else if (LocalTime.class == fieldType) {
return new LocalTimeParser(getFormatter(annotation, fieldType));
}
else if (LocalDateTime.class == fieldType) {
return new LocalDateTimeParser(getFormatter(annotation, fieldType));
}
else {
return new DateTimeParser(getFormatter(annotation, fieldType));
}
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:JodaDateTimeFormatAnnotationFormatterFactory.java
示例8: getParser
import org.springframework.format.Parser; //导入依赖的package包/类
@Override
public Parser<?> getParser(SpecialInt annotation, Class<?> fieldType) {
return new Parser<Integer>() {
@Override
public Integer parse(String text, Locale locale) throws ParseException {
return Integer.parseInt(text.substring(1));
}
};
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:FormattingConversionServiceFactoryBeanTests.java
示例9: getParser
import org.springframework.format.Parser; //导入依赖的package包/类
@Override
public Parser<?> getParser(EntityFormat annotation, Class<?> fieldType) {
Assert.notNull(annotation, "The EntityFormat annotation is required");
Assert.notNull(fieldType, "The Class of the field to parse is required");
EntityResolver<?, ?> resolver = entity2Resolver.get(fieldType);
if (resolver == null) {
throw new IllegalArgumentException(
"Not found a required EntityService bean for the type: " + fieldType);
}
return new EntityParser<>(resolver, conversionService);
}
示例10: shouldReturnEntityParser
import org.springframework.format.Parser; //导入依赖的package包/类
/**
* Test method for {@link io.springlets.format.EntityFormatAnnotationFormatterFactory#getParser(io.springlets.format.EntityFormat, java.lang.Class)}.
*/
@Test
public void shouldReturnEntityParser() {
// Exercise
Parser<?> parser = factory.getParser(format, Object.class);
// Verify
assertThat(parser).isNotNull();
}
示例11: getParser
import org.springframework.format.Parser; //导入依赖的package包/类
public Parser<Date> getParser(DateTimeFormat annotation, Class<?> fieldType) {
if (Date.class.isAssignableFrom(fieldType)) {
return new DatePrinter(annotation);
} else {
return null;
}
}
示例12: getParser
import org.springframework.format.Parser; //导入依赖的package包/类
@Override
public Parser<Number> getParser(CustomNumberFormat annotation, Class<?> fieldType) {
int value = adjust(annotation.value());
final NumberFormatter formatter = (isNotEmpty(annotation.pattern()) ? new NumberFormatter(annotation.pattern())
: numberFormatter.get(value));
final int scale = (annotation.scale() < 0 ? value : annotation.scale());
return new Parser<Number>() {
@Override
public Number parse(String text, Locale locale) throws ParseException {
return NumberUtil.setScale(formatter.parse(text, locale), scale, RoundingMode.DOWN);
}
};
}
示例13: convert
import org.springframework.format.Parser; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
AnnotationConverterKey converterKey =
new AnnotationConverterKey(targetType.getAnnotation(annotationType), targetType.getObjectType());
GenericConverter converter = cachedParsers.get(converterKey);
if (converter == null) {
Parser<?> parser = annotationFormatterFactory.getParser(
converterKey.getAnnotation(), converterKey.getFieldType());
converter = new ParserConverter(fieldType, parser, FormattingConversionService.this);
cachedParsers.put(converterKey, converter);
}
return converter.convert(source, sourceType, targetType);
}
示例14: testGetParser
import org.springframework.format.Parser; //导入依赖的package包/类
/**
* Test method for
* {@link de.ppi.fuwesta.spring.mvc.formatter.NonEmptyStringAnnotationFormatterFactory#getParser(de.ppi.fuwesta.spring.mvc.formatter.NonEmpty, java.lang.Class)}
* .
*
* @throws ParseException if a parse-error happens.
*/
@Test
public void testGetParser() throws ParseException {
// Arrange
final String anyString = "Foo";
// Act
Parser<String> parser = testee.getParser(null, String.class);
// Assert
assertThat(parser.parse(null, Locale.getDefault())).isEqualTo(null);
assertThat(parser.parse(anyString, null)).isEqualTo(anyString);
assertThat(parser.parse(" ", null)).isEqualTo(null);
}
示例15: getParser
import org.springframework.format.Parser; //导入依赖的package包/类
@Override
public Parser<Number> getParser(NumberFormat annotation, Class<?> fieldType) {
return configureFormatterFrom(annotation);
}