Search in sources :

Example 1 with XParam

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);
        }
    }
}
Also used : XParam(io.leopard.web.xparam.XParam) ArrayList(java.util.ArrayList) List(java.util.List) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory)

Example 2 with XParam

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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) XParam(io.leopard.web.xparam.XParam)

Aggregations

XParam (io.leopard.web.xparam.XParam)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 ListableBeanFactory (org.springframework.beans.factory.ListableBeanFactory)1