当前位置: 首页>>代码示例>>Java>>正文


Java Parser类代码示例

本文整理汇总了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);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:FormattingConversionService.java

示例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;
            }

        }
    };
}
 
开发者ID:opensource21,项目名称:fuwesta,代码行数:19,代码来源:NonEmptyStringAnnotationFormatterFactory.java

示例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);
	
}
 
开发者ID:chelu,项目名称:jdal,代码行数:20,代码来源:ControlBinder.java

示例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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:FormattingConversionService.java

示例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));
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:16,代码来源:JodaDateTimeFormatAnnotationFormatterFactory.java

示例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);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:JodaTimeFormatterRegistrar.java

示例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);
}
 
开发者ID:DISID,项目名称:springlets,代码行数:15,代码来源:EntityFormatAnnotationFormatterFactory.java

示例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();
}
 
开发者ID:DISID,项目名称:springlets,代码行数:12,代码来源:EntityFormatAnnotationFormatterFactoryTest.java

示例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;
	}
}
 
开发者ID:JD-Software,项目名称:JDeSurvey,代码行数:8,代码来源:DateTimeFormatAnnotationFormatterFactory.java

示例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);
		}
	};
}
 
开发者ID:agwlvssainokuni,项目名称:sqlapp,代码行数:14,代码来源:CustomNumberFormatAnnotationFormatterFactory.java

示例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);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:14,代码来源:FormattingConversionService.java

示例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);
}
 
开发者ID:opensource21,项目名称:fuwesta,代码行数:21,代码来源:NonEmptyStringAnnotationFormatterFactoryTest.java

示例15: getParser

import org.springframework.format.Parser; //导入依赖的package包/类
@Override
public Parser<Number> getParser(NumberFormat annotation, Class<?> fieldType) {
	return configureFormatterFrom(annotation);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:5,代码来源:NumberFormatAnnotationFormatterFactory.java


注:本文中的org.springframework.format.Parser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。