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


Java TypeConverter类代码示例

本文整理汇总了Java中net.sourceforge.stripes.validation.TypeConverter的典型用法代码示例。如果您正苦于以下问题:Java TypeConverter类的具体用法?Java TypeConverter怎么用?Java TypeConverter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TypeConverter类属于net.sourceforge.stripes.validation包,在下文中一共展示了TypeConverter类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSimpleFind

import net.sourceforge.stripes.validation.TypeConverter; //导入依赖的package包/类
@Test(groups="slow")
public void testSimpleFind() throws Exception {
    // Because the tests package depends on stripes, it's safe to assume that
    // there will be some TypeConverter subclasses in the classpath
    ResolverUtil<TypeConverter<?>> resolver = new ResolverUtil<TypeConverter<?>>();
    resolver.findImplementations(TypeConverter.class, "net");
    Set<Class<? extends TypeConverter<?>>> impls = resolver.getClasses();

    // Check on a few random converters
    Assert.assertTrue(impls.contains(BooleanTypeConverter.class),
                      "BooleanTypeConverter went missing.");
    Assert.assertTrue(impls.contains(DateTypeConverter.class),
                      "DateTypeConverter went missing.");
    Assert.assertTrue(impls.contains(BooleanTypeConverter.class),
                      "ShortTypeConverter went missing.");

    Assert.assertTrue(impls.size() >= 10,
                      "Did not find all the built in TypeConverters.");
}
 
开发者ID:scarcher2,项目名称:stripes,代码行数:20,代码来源:ResolverUtilTest.java

示例2: testMoreSpecificFind

import net.sourceforge.stripes.validation.TypeConverter; //导入依赖的package包/类
@Test(groups="fast")
public void testMoreSpecificFind() throws Exception {
    // Because the tests package depends on stripes, it's safe to assume that
    // there will be some TypeConverter subclasses in the classpath
    ResolverUtil<TypeConverter<?>> resolver = new ResolverUtil<TypeConverter<?>>();
    resolver.findImplementations(TypeConverter.class, "net.sourceforge.stripes.validation");
    Set<Class<? extends TypeConverter<?>>> impls = resolver.getClasses();

    // Check on a few random converters
    Assert.assertTrue(impls.contains(BooleanTypeConverter.class),
                      "BooleanTypeConverter went missing.");
    Assert.assertTrue(impls.contains(DateTypeConverter.class),
                      "DateTypeConverter went missing.");
    Assert.assertTrue(impls.contains(BooleanTypeConverter.class),
                      "ShortTypeConverter went missing.");

    Assert.assertTrue(impls.size() >= 10,
                      "Did not find all the built in TypeConverters.");
}
 
开发者ID:scarcher2,项目名称:stripes,代码行数:20,代码来源:ResolverUtilTest.java

示例3: getKey

import net.sourceforge.stripes.validation.TypeConverter; //导入依赖的package包/类
/**
    * Attempts to convert the key to from the expression node to the correct type
    * as determined by reflection (using generics to find the Map key type). If generics
    * information is not present then the type found in the expression is used (String, int etc.).
    *
    * @param evaluation the current node evaluation
    * @return the key to use when interacting with the Map
    */
   @SuppressWarnings("unchecked")
protected Object getKey(NodeEvaluation evaluation) {
       Class declaredType = evaluation.getKeyType();
       Class nodeType     = evaluation.getNode().getTypedValue().getClass();

       if (nodeType.equals(declaredType) || declaredType == null) {
           return evaluation.getNode().getTypedValue();
       }
       else {
           try {
               // Collect the things needed to grab a type converter
               String stringKey = evaluation.getNode().getStringValue();
               ActionBean bean = (ActionBean) evaluation.getExpressionEvaluation().getBean();
               Locale locale = bean.getContext().getLocale();
               Collection errors = new ArrayList<ValidationError>();

               TypeConverter tc = StripesFilter.getConfiguration()
                       .getTypeConverterFactory().getTypeConverter(declaredType, locale);

               // If there is a type converter, try using it!
               if (tc != null) {
                   Object retval = tc.convert(stringKey, declaredType, errors);
                   if (errors.size() == 0) return retval;
               }
               // Otherwise look for a String constructor
               else {
                   return StripesFilter.getConfiguration().getObjectFactory()
                           .constructor(declaredType, String.class).newInstance(stringKey);
               }
           }
           catch (Exception e) {
               log.warn("Exception while converting Map key to appropriate type. Key: ",
                        evaluation.getNode().getStringValue());
           }

           // Return the original key if we couldn't type convert it
           return evaluation.getNode().getTypedValue();
       }
   }
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:48,代码来源:MapPropertyAccessor.java

示例4: getInstance

import net.sourceforge.stripes.validation.TypeConverter; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Override

public TypeConverter getInstance(Class<? extends TypeConverter> clazz,
		Locale locale) throws Exception {
	TypeConverter converter = super.getInstance(clazz, locale);
	SpringHelper.injectBeans(converter,
			ContextLoader.getCurrentWebApplicationContext());
	return converter;
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:11,代码来源:TypeConverterFactory.java

示例5: setConverter

import net.sourceforge.stripes.validation.TypeConverter; //导入依赖的package包/类
public void setConverter(Class<? extends TypeConverter<?>> converter) {
    this.converter = converter;
    this.stubTouched = true;
}
 
开发者ID:StripesFramework,项目名称:stripes-stuff,代码行数:5,代码来源:JpaValidationMetadataProvider.java

示例6: converter

import net.sourceforge.stripes.validation.TypeConverter; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public Class<? extends TypeConverter> converter() {
    return converter;
}
 
开发者ID:StripesFramework,项目名称:stripes-stuff,代码行数:5,代码来源:JpaValidationMetadataProvider.java


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