本文整理汇总了Java中org.springframework.format.Printer类的典型用法代码示例。如果您正苦于以下问题:Java Printer类的具体用法?Java Printer怎么用?Java Printer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Printer类属于org.springframework.format包,在下文中一共展示了Printer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convert
import org.springframework.format.Printer; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
Annotation ann = sourceType.getAnnotation(this.annotationType);
if (ann == null) {
throw new IllegalStateException(
"Expected [" + this.annotationType.getName() + "] to be present on " + sourceType);
}
AnnotationConverterKey converterKey = new AnnotationConverterKey(ann, sourceType.getObjectType());
GenericConverter converter = cachedPrinters.get(converterKey);
if (converter == null) {
Printer<?> printer = this.annotationFormatterFactory.getPrinter(
converterKey.getAnnotation(), converterKey.getFieldType());
converter = new PrinterConverter(this.fieldType, printer, FormattingConversionService.this);
cachedPrinters.put(converterKey, converter);
}
return converter.convert(source, sourceType, targetType);
}
示例2: PrinterConverter
import org.springframework.format.Printer; //导入依赖的package包/类
public PrinterConverter(Class<?> fieldType, Printer<?> printer, ConversionService conversionService) {
this.fieldType = fieldType;
this.printerObjectType = TypeDescriptor.valueOf(resolvePrinterObjectType(printer));
this.printer = printer;
this.conversionService = conversionService;
}
示例3: convert
import org.springframework.format.Printer; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
AnnotationConverterKey converterKey =
new AnnotationConverterKey(sourceType.getAnnotation(annotationType), sourceType.getObjectType());
GenericConverter converter = cachedPrinters.get(converterKey);
if (converter == null) {
Printer<?> printer = annotationFormatterFactory.getPrinter(
converterKey.getAnnotation(), converterKey.getFieldType());
converter = new PrinterConverter(fieldType, printer, FormattingConversionService.this);
cachedPrinters.put(converterKey, converter);
}
return converter.convert(source, sourceType, targetType);
}
示例4: getPrinter
import org.springframework.format.Printer; //导入依赖的package包/类
@Override
public Printer<?> getPrinter(DateTimeFormat annotation, Class<?> fieldType) {
DateTimeFormatter formatter = getFormatter(annotation, fieldType);
if (ReadablePartial.class.isAssignableFrom(fieldType)) {
return new ReadablePartialPrinter(formatter);
}
else if (ReadableInstant.class.isAssignableFrom(fieldType) || Calendar.class.isAssignableFrom(fieldType)) {
// assumes Calendar->ReadableInstant converter is registered
return new ReadableInstantPrinter(formatter);
}
else {
// assumes Date->Long converter is registered
return new MillisecondInstantPrinter(formatter);
}
}
示例5: addFormatterForFields
import org.springframework.format.Printer; //导入依赖的package包/类
private void addFormatterForFields(FormatterRegistry registry, Printer<?> printer,
Parser<?> parser, Class<?>... fieldTypes) {
for (Class<?> fieldType : fieldTypes) {
registry.addFormatterForFieldType(fieldType, printer, parser);
}
}
示例6: getPrinter
import org.springframework.format.Printer; //导入依赖的package包/类
@Override
public Printer<?> getPrinter(SpecialInt annotation, Class<?> fieldType) {
return new Printer<Integer>() {
@Override
public String print(Integer object, Locale locale) {
return ":" + object.toString();
}
};
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:FormattingConversionServiceFactoryBeanTests.java
示例7: getPrinter
import org.springframework.format.Printer; //导入依赖的package包/类
@Override
public Printer<?> getPrinter(EntityFormat annotation, Class<?> fieldType) {
// First use the message code at the field level
EntityFormat fieldAnnotation = AnnotationUtils.getAnnotation(annotation, EntityFormat.class);
String messageCode = fieldAnnotation.message();
if (!StringUtils.isEmpty(messageCode)) {
return createMessagePrinter(messageCode);
}
// Then the expression at the field level
String expression = fieldAnnotation.expression();
if (!StringUtils.isEmpty(expression)) {
return createPrinter(expression);
}
// If no message code or expression is provided at the field level, try with the annotation
// at the class level
EntityFormat classAnnotation =
AnnotatedElementUtils.findMergedAnnotation(fieldType, EntityFormat.class);
if (classAnnotation != null) {
// Then the message code at the class level
messageCode = classAnnotation.message();
if (!StringUtils.isEmpty(messageCode)) {
return createMessagePrinter(messageCode);
}
// Then the expression at the class level
expression = classAnnotation.expression();
}
return createPrinter(expression);
}
示例8: shouldReturnASpElPrinter
import org.springframework.format.Printer; //导入依赖的package包/类
/**
* Test method for {@link io.springlets.format.EntityFormatAnnotationFormatterFactory#getPrinter(io.springlets.format.EntityFormat, java.lang.Class)}.
*/
@Test
@Ignore("Whe have to find a way to mock AnnotationUtils")
public void shouldReturnASpElPrinter() {
// Prepare
when(format.message()).thenReturn(null);
when(format.expression()).thenReturn("expression");
// Exercise
Printer<?> printer = factory.getPrinter(format, Object.class);
// Verify
assertThat(printer).isInstanceOf(EntityPrinter.class);
}
示例9: shouldReturnASpElMessagePrinter
import org.springframework.format.Printer; //导入依赖的package包/类
/**
* Test method for {@link io.springlets.format.EntityFormatAnnotationFormatterFactory#getPrinter(io.springlets.format.EntityFormat, java.lang.Class)}.
*/
@Test
@Ignore("Whe have to find a way to mock AnnotationUtils")
public void shouldReturnASpElMessagePrinter() {
// Prepare
when(format.message()).thenReturn("messageCode");
when(format.expression()).thenReturn("expression");
// Exercise
Printer<?> printer = factory.getPrinter(format, Object.class);
// Verify
assertThat(printer).isInstanceOf(EntityMessagePrinter.class);
}
示例10: dateTime
import org.springframework.format.Printer; //导入依赖的package包/类
@Override
public final Printer<PointInTime> dateTime() {
if (dt == null) {
dt = createDateTimePrinter();
}
return dt;
}
示例11: date
import org.springframework.format.Printer; //导入依赖的package包/类
@Override
public final Printer<PointInTime> date() {
if (d == null) {
d = createDatePrinter();
}
return d;
}
示例12: year
import org.springframework.format.Printer; //导入依赖的package包/类
@Override
public Printer<PointInTime> year() {
if (y == null) {
y = createYearPrinter();
}
return y;
}
示例13: time
import org.springframework.format.Printer; //导入依赖的package包/类
@Override
public final Printer<PointInTime> time() {
if (t == null) {
t = createTimePrinter();
}
return t;
}
示例14: createDateTimePrinter
import org.springframework.format.Printer; //导入依赖的package包/类
@Override
protected Printer<PointInTime> createDateTimePrinter() {
Map<Precision, DateTimeFormatter> formatters = new HashMap<Precision, DateTimeFormatter>();
formatters.put(Precision.YEAR, PointInTimeFormat.year());
formatters.put(Precision.MONTH, DateTimeFormat.forPattern("MMM-yyyy"));
formatters.put(Precision.DATE, DateTimeFormat.forPattern("dd-MMM-yyyy"));
formatters.put(Precision.HOUR, DateTimeFormat.forPattern("dd-MMM-yyyy"));
formatters.put(Precision.MINUTE, DateTimeFormat.forPattern("dd-MMM-yyyy HH:mm"));
formatters.put(Precision.SECOND, DateTimeFormat.forPattern("dd-MMM-yyyy HH:mm"));
formatters.put(Precision.MILLISECOND, DateTimeFormat.forPattern("dd-MMM-yyyy HH:mm"));
return new HealthTimePrinter(formatters);
}
示例15: createDatePrinter
import org.springframework.format.Printer; //导入依赖的package包/类
@Override
protected Printer<PointInTime> createDatePrinter() {
Map<Precision, DateTimeFormatter> formatters = new HashMap<Precision, DateTimeFormatter>();
formatters.put(Precision.YEAR, PointInTimeFormat.year());
formatters.put(Precision.MONTH, DateTimeFormat.forPattern("MMM-yyyy"));
formatters.put(Precision.DATE, DateTimeFormat.forPattern("dd-MMM-yyyy"));
formatters.put(Precision.HOUR, DateTimeFormat.forPattern("dd-MMM-yyyy"));
formatters.put(Precision.MINUTE, DateTimeFormat.forPattern("dd-MMM-yyyy"));
formatters.put(Precision.SECOND, DateTimeFormat.forPattern("dd-MMM-yyyy"));
formatters.put(Precision.MILLISECOND, DateTimeFormat.forPattern("dd-MMM-yyyy"));
return new HealthTimePrinter(formatters);
}