use of io.leopard.web.xparam.XParam in project leopard by tanhaichao.
the class XParamHandlerMethodArgumentResolver method setBeanFactory.
// public XParamHandlerMethodArgumentResolver() {
// Iterator<XParam> iterator = ServiceLoader.load(XParam.class).iterator();
// while (iterator.hasNext()) {
// XParam xparam = iterator.next();
// data.put(xparam.getKey(), xparam);
// }
// }
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
UserinfoResolverImpl.setBeanFactory(beanFactory);
ListableBeanFactory factory = (ListableBeanFactory) beanFactory;
Map<String, XParam> map = factory.getBeansOfType(XParam.class);
for (Entry<String, XParam> entry : map.entrySet()) {
XParam xparam = entry.getValue();
List<XParam> xparamList = DATA.get(xparam.getKey());
if (xparamList == null) {
xparamList = new ArrayList<XParam>();
DATA.put(xparam.getKey(), xparamList);
}
xparamList.add(xparam);
}
for (Entry<String, List<XParam>> entry : DATA.entrySet()) {
List<XParam> xparamList = entry.getValue();
if (xparamList.size() > 1) {
AnnotationAwareOrderComparator.sort(xparamList);
}
}
}
use of io.leopard.web.xparam.XParam in project leopard by tanhaichao.
the class XParamHandlerMethodArgumentResolver method resolveName.
@Override
protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception {
// System.err.println("resolveName name:" + name);
List<XParam> xparamList = DATA.get(name);
if (xparamList == null) {
throw new IllegalArgumentException("未知参数名称[" + name + "].");
}
Object value = null;
for (XParam xparam : xparamList) {
value = xparam.getValue((HttpServletRequest) request.getNativeRequest(), parameter);
// logger.info("resolveName key:" + xparam.getKey() + " value:" + value + " xparam:" + xparam.getClass().getName());
if (value != null) {
break;
}
}
return value;
}
Aggregations