• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TypeConverter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java StepContext类代码示例发布时间:2022-05-23
下一篇:
Java FilterClause类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap