use of org.osgl.util.StringValueResolver in project actframework by actframework.
the class CliContextParamLoader method findDirectAnnotatedResolver.
private StringValueResolver findDirectAnnotatedResolver(BeanSpec spec) {
Resolve resolve = spec.getAnnotation(Resolve.class);
Class<?> rawType = spec.rawType();
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;
}
use of org.osgl.util.StringValueResolver in project actframework by actframework.
the class CliContextParamLoader method findContextSpecificLoader.
@Override
protected ParamValueLoader findContextSpecificLoader(String bindName, BeanSpec spec) {
boolean isArray = spec.isArray();
// = isArray ? resolverManager.resolver(rawType.getComponentType(), spec) : resolverManager.resolver(rawType, spec);
StringValueResolver resolver = findResolver(spec, isArray);
Required required = spec.getAnnotation(Required.class);
Optional optional = null == required ? spec.getAnnotation(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(spec.rawType().getComponentType(), resolver) : new CliArgumentLoader(resolver);
}
use of org.osgl.util.StringValueResolver in project actframework by actframework.
the class StringValueResolverManager method collectionResolver.
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;
}
};
}
Aggregations