本文整理汇总了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.");
}
示例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.");
}
示例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();
}
}
示例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;
}
示例5: setConverter
import net.sourceforge.stripes.validation.TypeConverter; //导入依赖的package包/类
public void setConverter(Class<? extends TypeConverter<?>> converter) {
this.converter = converter;
this.stubTouched = true;
}
示例6: converter
import net.sourceforge.stripes.validation.TypeConverter; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public Class<? extends TypeConverter> converter() {
return converter;
}