本文整理汇总了Java中org.osgl.util.StringValueResolver类的典型用法代码示例。如果您正苦于以下问题:Java StringValueResolver类的具体用法?Java StringValueResolver怎么用?Java StringValueResolver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StringValueResolver类属于org.osgl.util包,在下文中一共展示了StringValueResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolver
import org.osgl.util.StringValueResolver; //导入依赖的package包/类
public <T> StringValueResolver<T> resolver(final Class<T> targetType) {
StringValueResolver<T> r = resolvers.get(targetType);
final Class<? extends Enum> clazz = $.cast(targetType);
if (null == r && Enum.class.isAssignableFrom(targetType)) {
if (app().config().enumResolvingCaseSensitive()) {
r = new StringValueResolver<T>(targetType) {
@Override
public T resolve(String value) {
//TODO should we handle exception here?
return (T)Enum.valueOf(clazz, value);
}
};
} else {
r = new StringValueResolver<T>(targetType) {
@Override
public T resolve(String value) {
return (T) $.asEnum(clazz, value);
}
};
}
resolvers.put(targetType, r);
}
return r;
}
示例2: findContextSpecificLoader
import org.osgl.util.StringValueResolver; //导入依赖的package包/类
@Override
protected ParamValueLoader findContextSpecificLoader(
String bindName,
Class<?> rawType,
BeanSpec spec,
Type type,
Annotation[] annotations
) {
boolean isArray = rawType.isArray();
StringValueResolver resolver = findResolver(spec, rawType, isArray); //= isArray ? resolverManager.resolver(rawType.getComponentType(), spec) : resolverManager.resolver(rawType, spec);
Required required = filter(annotations, Required.class);
Optional optional = null == required ? filter(annotations, Optional.class) : null;
if (null != required) {
return new OptionLoader(bindName, required, resolver, spec);
} else if (null != optional) {
return new OptionLoader(bindName, optional, resolver, spec);
}
return isArray ? new CliVarArgumentLoader(rawType.getComponentType(), resolver) : new CliArgumentLoader(resolver);
}
示例3: findIndirectAnnotatedResolver
import org.osgl.util.StringValueResolver; //导入依赖的package包/类
private StringValueResolver findIndirectAnnotatedResolver(BeanSpec spec, Class rawType) {
Annotation[] aa = spec.allAnnotations();
for (Annotation a : aa) {
Resolve resolve = AnnotationUtil.tagAnnotation(a, Resolve.class);
if (null != resolve) {
Class<? extends StringValueResolver>[] resolvers = resolve.value();
for (Class<? extends StringValueResolver> resolverClass : resolvers) {
StringValueResolver resolver = injector.get(resolverClass);
resolver.attributes($.evaluate(a));
if (rawType.isAssignableFrom(resolver.targetType())) {
return resolver;
}
}
}
}
return null;
}
示例4: cast
import org.osgl.util.StringValueResolver; //导入依赖的package包/类
private T cast(Object val, BeanSpec spec) {
Class<?> type = spec.rawType();
if (type.isInstance(val)) {
return (T) val;
}
if ($.isSimpleType(type)) {
StringValueResolver svr = StringValueResolver.predefined(type);
if (null != svr) {
return (T) svr.resolve(S.string(val));
}
}
throw new InjectException("Cannot cast value type[%s] to required type[%]", val.getClass(), type);
}
示例5: collectionResolver
import org.osgl.util.StringValueResolver; //导入依赖的package包/类
public <T extends Collection> StringValueResolver<T> collectionResolver(final Class<T> targetType, final Class<?> elementType, final char separator) {
final StringValueResolver elementResolver = resolver(elementType);
return new StringValueResolver<T>(targetType) {
@Override
public T resolve(String value) {
T col = app().getInstance(targetType);
List<String> parts = S.fastSplit(value, String.valueOf(separator));
for (String part : parts) {
col.add(elementResolver.resolve(part));
}
return col;
}
};
}
示例6: found
import org.osgl.util.StringValueResolver; //导入依赖的package包/类
@Override
protected void found(Class<? extends StringValueResolver> target, App app) {
if (target == Param.DEFAULT_RESOLVER.class) {
return;
}
if (target.isAnnotationPresent(NoAutoRegister.class)) {
return;
}
StringValueResolver resolver = app.getInstance(target);
app.resolverManager().register(resolver.targetType(), resolver);
}
示例7: StringValueResolverValueLoaderBase
import org.osgl.util.StringValueResolver; //导入依赖的package包/类
public StringValueResolverValueLoaderBase(ParamKey key, StringValueResolver<?> resolver, Param param, DefaultValue def, Class<?> type, boolean simpleKeyOnly) {
E.illegalArgumentIf(simpleKeyOnly && !key.isSimple());
this.paramKey = key;
this.stringValueResolver = resolver;
this.defSpec = def;
Object _defVal = defVal(param, type);
if (null == _defVal && null != def) {
_defVal = resolver.resolve(def.value());
}
this.defVal = _defVal;
}
示例8: findDirectAnnotatedResolver
import org.osgl.util.StringValueResolver; //导入依赖的package包/类
private StringValueResolver findDirectAnnotatedResolver(BeanSpec spec, Class rawType) {
Resolve resolve = spec.getAnnotation(Resolve.class);
if (null != resolve) {
Class<? extends StringValueResolver>[] resolvers = resolve.value();
for (Class<? extends StringValueResolver> resolverClass : resolvers) {
StringValueResolver resolver = injector.get(resolverClass);
if (rawType.isAssignableFrom(resolver.targetType())) {
return resolver;
}
}
}
return null;
}
示例9: OptionLoader
import org.osgl.util.StringValueResolver; //导入依赖的package包/类
OptionLoader(String bindName, Optional optional, StringValueResolver resolver, BeanSpec beanSpec) {
this.bindName = bindName;
this.required = false;
this.parseLeads(optional.lead());
this.defVal = optional.defVal();
this.requiredGroup = null;
this.beanSpec = beanSpec;
this.errorTemplate = errorTemplate(optional);
this.resolver = resolver;
CliContext.ParsingContextBuilder.foundOptional();
}
示例10: resolve
import org.osgl.util.StringValueResolver; //导入依赖的package包/类
private <T> T resolve(String val, StringValueResolver<T> resolver) {
if (null == errorTemplate) {
return resolver.resolve(val);
}
try {
return resolver.resolve(val);
} catch (Exception e) {
throw E.unexpected(errorTemplate, val);
}
}
示例11: register
import org.osgl.util.StringValueResolver; //导入依赖的package包/类
@Override
public void register() {
StringValueResolver.addPredefinedResolver(targetType(), this);
}
示例12: amended
import org.osgl.util.StringValueResolver; //导入依赖的package包/类
@Override
public final StringValueResolver<T> amended(AnnotationAware beanSpec) {
Pattern pattern = beanSpec.getAnnotation(Pattern.class);
return null == pattern ? this : create(pattern.value());
}
示例13: register
import org.osgl.util.StringValueResolver; //导入依赖的package包/类
public <T> StringValueResolverManager register(Class<T> targetType, StringValueResolver<T> resolver) {
resolvers.put(targetType, resolver);
return this;
}
示例14: resolve
import org.osgl.util.StringValueResolver; //导入依赖的package包/类
public <T> T resolve(String strVal, Class<T> targetType) {
StringValueResolver<T> r = resolver(targetType);
return null != r ? r.resolve(strVal) : null;
}
示例15: registerPredefinedResolvers
import org.osgl.util.StringValueResolver; //导入依赖的package包/类
private void registerPredefinedResolvers() {
resolvers.putAll(StringValueResolver.predefined());
}