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;
}
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;
}
Aggregations