//first just match on service,request
List matches = new ArrayList();
for (Iterator itr = services.iterator(); itr.hasNext();) {
Service sBean = (Service) itr.next();
if (sBean.getId().equalsIgnoreCase(id)) {
matches.add(sBean);
}
}
if (matches.isEmpty()) {
String msg = "No service: ( " + id + " )";
throw new ServiceException(msg, "InvalidParameterValue", "service");
}
Service sBean = null;
//if multiple, use version to filter match
if (matches.size() > 1) {
List vmatches = new ArrayList(matches);
//match up the version
if (version != null) {
//version specified, look for a match
for (Iterator itr = vmatches.iterator(); itr.hasNext();) {
Service s = (Service) itr.next();
if (version.equals(s.getVersion())) {
continue;
}
itr.remove();
}
if (vmatches.isEmpty()) {
//no matching version found, drop out and next step
// will sort to return highest version
vmatches = new ArrayList(matches);
}
}
//multiple services found, sort by version
if (vmatches.size() > 1) {
//use highest version
Comparator comparator = new Comparator() {
public int compare(Object o1, Object o2) {
Service s1 = (Service) o1;
Service s2 = (Service) o2;
return s1.getVersion().compareTo(s2.getVersion());
}
};
Collections.sort(vmatches, comparator);
}