Search in sources :

Example 1 with ClassResourceInfoComparator

use of org.apache.cxf.jaxrs.model.ClassResourceInfoComparator in project tomee by apache.

the class JAXRSUtils method selectResourceClass.

public static Map<ClassResourceInfo, MultivaluedMap<String, String>> selectResourceClass(List<ClassResourceInfo> resources, String path, Message message) {
    LOG.fine(() -> new org.apache.cxf.common.i18n.Message("START_CRI_MATCH", BUNDLE, path).toString());
    if (resources.size() == 1) {
        MultivaluedMap<String, String> values = new MetadataMap<>();
        return resources.get(0).getURITemplate().match(path, values) ? Collections.singletonMap(resources.get(0), values) : null;
    }
    SortedMap<ClassResourceInfo, MultivaluedMap<String, String>> candidateList = new TreeMap<ClassResourceInfo, MultivaluedMap<String, String>>(new ClassResourceInfoComparator(message));
    for (ClassResourceInfo cri : resources) {
        MultivaluedMap<String, String> map = new MetadataMap<>();
        if (cri.getURITemplate().match(path, map)) {
            candidateList.put(cri, map);
            LOG.fine(() -> new org.apache.cxf.common.i18n.Message("CRI_SELECTED_POSSIBLY", BUNDLE, cri.getServiceClass().getName(), path, cri.getURITemplate().getValue()).toString());
        } else {
            LOG.fine(() -> new org.apache.cxf.common.i18n.Message("CRI_NO_MATCH", BUNDLE, path, cri.getServiceClass().getName()).toString());
        }
    }
    if (!candidateList.isEmpty()) {
        Map<ClassResourceInfo, MultivaluedMap<String, String>> cris = new LinkedHashMap<>(candidateList.size());
        ClassResourceInfo firstCri = null;
        for (Map.Entry<ClassResourceInfo, MultivaluedMap<String, String>> entry : candidateList.entrySet()) {
            ClassResourceInfo cri = entry.getKey();
            if (cris.isEmpty()) {
                firstCri = cri;
                cris.put(cri, entry.getValue());
            } else if (firstCri != null && URITemplate.compareTemplates(firstCri.getURITemplate(), cri.getURITemplate()) == 0) {
                cris.put(cri, entry.getValue());
            } else {
                break;
            }
            LOG.fine(() -> new org.apache.cxf.common.i18n.Message("CRI_SELECTED", BUNDLE, cri.getServiceClass().getName(), path, cri.getURITemplate().getValue()).toString());
        }
        return cris;
    }
    return null;
}
Also used : Message(org.apache.cxf.message.Message) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) TreeMap(java.util.TreeMap) LinkedHashMap(java.util.LinkedHashMap) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) ClassResourceInfoComparator(org.apache.cxf.jaxrs.model.ClassResourceInfoComparator) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap)

Example 2 with ClassResourceInfoComparator

use of org.apache.cxf.jaxrs.model.ClassResourceInfoComparator in project cxf by apache.

the class JAXRSUtils method selectResourceClass.

public static Map<ClassResourceInfo, MultivaluedMap<String, String>> selectResourceClass(List<ClassResourceInfo> resources, String path, Message message) {
    LOG.fine(() -> new org.apache.cxf.common.i18n.Message("START_CRI_MATCH", BUNDLE, path).toString());
    if (resources.size() == 1) {
        MultivaluedMap<String, String> values = new MetadataMap<>();
        return resources.get(0).getURITemplate().match(path, values) ? Collections.singletonMap(resources.get(0), values) : null;
    }
    SortedMap<ClassResourceInfo, MultivaluedMap<String, String>> candidateList = new TreeMap<ClassResourceInfo, MultivaluedMap<String, String>>(new ClassResourceInfoComparator(message));
    for (ClassResourceInfo cri : resources) {
        MultivaluedMap<String, String> map = new MetadataMap<>();
        if (cri.getURITemplate().match(path, map)) {
            candidateList.put(cri, map);
            LOG.fine(() -> new org.apache.cxf.common.i18n.Message("CRI_SELECTED_POSSIBLY", BUNDLE, cri.getServiceClass().getName(), path, cri.getURITemplate().getValue()).toString());
        } else {
            LOG.fine(() -> new org.apache.cxf.common.i18n.Message("CRI_NO_MATCH", BUNDLE, path, cri.getServiceClass().getName()).toString());
        }
    }
    if (!candidateList.isEmpty()) {
        Map<ClassResourceInfo, MultivaluedMap<String, String>> cris = new LinkedHashMap<>(candidateList.size());
        ClassResourceInfo firstCri = null;
        for (Map.Entry<ClassResourceInfo, MultivaluedMap<String, String>> entry : candidateList.entrySet()) {
            ClassResourceInfo cri = entry.getKey();
            if (cris.isEmpty()) {
                firstCri = cri;
                cris.put(cri, entry.getValue());
            } else if (firstCri != null && URITemplate.compareTemplates(firstCri.getURITemplate(), cri.getURITemplate()) == 0) {
                cris.put(cri, entry.getValue());
            } else {
                break;
            }
            LOG.fine(() -> new org.apache.cxf.common.i18n.Message("CRI_SELECTED", BUNDLE, cri.getServiceClass().getName(), path, cri.getURITemplate().getValue()).toString());
        }
        return cris;
    }
    return null;
}
Also used : Message(org.apache.cxf.message.Message) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) TreeMap(java.util.TreeMap) LinkedHashMap(java.util.LinkedHashMap) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) ClassResourceInfoComparator(org.apache.cxf.jaxrs.model.ClassResourceInfoComparator) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)2 MetadataMap (org.apache.cxf.jaxrs.impl.MetadataMap)2 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)2 ClassResourceInfoComparator (org.apache.cxf.jaxrs.model.ClassResourceInfoComparator)2 Message (org.apache.cxf.message.Message)2