Search in sources :

Example 1 with Resolve

use of org.osgl.mvc.annotation.Resolve in project actframework by actframework.

the class ActionContextParamLoader method findContextSpecificLoader.

@Override
protected ParamValueLoader findContextSpecificLoader(String bindName, BeanSpec spec) {
    HeaderVariable headerVariable = spec.getAnnotation(HeaderVariable.class);
    if (null != headerVariable) {
        return new HeaderValueLoader(headerVariable.value(), spec);
    }
    SessionVariable sessionVariable = spec.getAnnotation(SessionVariable.class);
    if (null != sessionVariable) {
        return new SessionValueLoader(sessionVariable.value(), spec);
    }
    if (spec.hasAnnotation(PartialPath.class)) {
        return new PartialPathLoader(bindName);
    }
    DefaultValue def = spec.getAnnotation(DefaultValue.class);
    Class<?> rawType = spec.rawType();
    ParamValueLoader loader = binder(spec, bindName);
    if (null == loader) {
        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())) {
                    loader = new StringValueResolverValueLoader(ParamKey.of(bindName), resolver, null, def, rawType);
                }
            }
        }
    }
    if (null == loader) {
        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())) {
                        loader = new StringValueResolverValueLoader(ParamKey.of(bindName), resolver, null, def, rawType);
                        break;
                    }
                }
            }
        }
    }
    if (null == loader) {
        StringValueResolver resolver = null;
        Param param = spec.getAnnotation(Param.class);
        if (null != param) {
            Class<? extends StringValueResolver> resolverClass = param.resolverClass();
            if (Param.DEFAULT_RESOLVER.class != resolverClass) {
                resolver = injector.get(resolverClass);
            }
        }
        if (null == resolver) {
            resolver = resolverManager.resolver(rawType, spec);
        }
        loader = (null != resolver) ? new StringValueResolverValueLoader(ParamKey.of(bindName), resolver, param, def, rawType) : buildLoader(ParamKey.of(bindName), spec);
    }
    return loader;
}
Also used : HeaderVariable(act.inject.HeaderVariable) SessionVariable(act.inject.SessionVariable) Resolve(org.osgl.mvc.annotation.Resolve) Annotation(java.lang.annotation.Annotation) StringValueResolver(org.osgl.util.StringValueResolver) DefaultValue(act.inject.DefaultValue) Param(org.osgl.mvc.annotation.Param)

Example 2 with Resolve

use of org.osgl.mvc.annotation.Resolve in project actframework by actframework.

the class CliContextParamLoader method findIndirectAnnotatedResolver.

private StringValueResolver findIndirectAnnotatedResolver(BeanSpec spec) {
    Annotation[] aa = spec.allAnnotations();
    Class<?> rawType = spec.rawType();
    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;
}
Also used : StringValueResolver(org.osgl.util.StringValueResolver) Resolve(org.osgl.mvc.annotation.Resolve) Annotation(java.lang.annotation.Annotation)

Example 3 with Resolve

use of org.osgl.mvc.annotation.Resolve 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)

Aggregations

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