* @throws JbpmException if no matching jBPM context service is found.
*/
private JcrService findService() {
String serviceName = null;
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
Services services = jbpmContext.getServices();
// if there is a service called jcr
if (services.hasService("jcr")) {
// use that one
serviceName = "jcr";
} else { // otherwise
// start matching the JCR workspace name with the jbpm service names
Iterator serviceNames = services.getServiceFactories().keySet().iterator();
while (serviceNames.hasNext()) {
String candidate = (String) serviceNames.next();
if (candidate.startsWith(workspace)) {
if (candidate.length()==workspace.length()) {
if (serviceName==null) {
serviceName = candidate;
}
} else if (candidate.endsWith(workspace)) {
serviceName = candidate;
}
}
}
}
if (serviceName==null) {
throw new JbpmException("couldn't find service for JCR repository '"+repository+"', workspace '"+workspace+"'");
}
return (JcrService) services.getService(serviceName);
}