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 String separator) {
final StringValueResolver elementResolver = resolver(elementType);
return new StringValueResolver<T>(targetType) {
@Override
public T resolve(String value) {
T col = app().getInstance(targetType);
String[] parts = value.split(separator);
for (String part : parts) {
col.add(elementResolver.resolve(part));
}
return col;
}
};
}
use of org.osgl.util.StringValueResolver 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;
}
use of org.osgl.util.StringValueResolver 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;
}
use of org.osgl.util.StringValueResolver in project actframework by actframework.
the class WebSocketConnectionHandler method params.
private Object[] params(WebSocketContext context) {
if (0 == paramCount) {
return DUMP_PARAMS;
}
Object[] params = paramLoaderService.loadMethodParams(host, method, context);
if (isSingleParam) {
for (int i = 0; i < paramCount; ++i) {
if (null == params[i]) {
String singleVal = context.stringMessage();
Class<?> paramType = paramTypes[i];
StringValueResolver resolver = context.app().resolverManager().resolver(paramType);
if (null != resolver) {
params[i] = resolver.apply(singleVal);
} else {
E.unexpected("Cannot determine string value resolver for param type: %s", paramType);
}
}
}
}
return params;
}
use of org.osgl.util.StringValueResolver in project actframework by actframework.
the class StringValueResolverFinder method found.
@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);
}
Aggregations