Search in sources :

Example 6 with StringValueResolver

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;
}
Also used : StringValueResolver(org.osgl.util.StringValueResolver) Resolve(org.osgl.mvc.annotation.Resolve)

Example 7 with StringValueResolver

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);
}
Also used : StringValueResolver(org.osgl.util.StringValueResolver) Required(act.cli.Required) Optional(act.cli.Optional)

Example 8 with StringValueResolver

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;
        }
    };
}
Also used : StringValueResolver(org.osgl.util.StringValueResolver)

Aggregations

StringValueResolver (org.osgl.util.StringValueResolver)8 Resolve (org.osgl.mvc.annotation.Resolve)3 Annotation (java.lang.annotation.Annotation)2 Param (org.osgl.mvc.annotation.Param)2 Optional (act.cli.Optional)1 Required (act.cli.Required)1 DefaultValue (act.inject.DefaultValue)1 HeaderVariable (act.inject.HeaderVariable)1 SessionVariable (act.inject.SessionVariable)1