*/
public CasProcessor[] getCasProcessors() throws ResourceConfigurationException {
checkForErrors();
try {
if (getCpeDescriptor().getCpeCasProcessors() == null) {
throw new ResourceConfigurationException(InvalidXMLException.ELEMENT_NOT_FOUND,
new Object[] { "<casProcessors>", "<cpeDescriptor>" }, new Exception(
CpmLocalizedMessage.getLocalizedMessage(CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
"UIMA_CPM_EXP_bad_cpe_descriptor__WARNING", new Object[] { Thread
.currentThread().getName() })));
}
CpeCasProcessors ct = getCpeDescriptor().getCpeCasProcessors();
CpeCasProcessor[] casProcessorList = ct.getAllCpeCasProcessors();
Vector v = new Vector();
if (casProcessorList == null || casProcessorList.length == 0) {
throw new ResourceConfigurationException(InvalidXMLException.ELEMENT_NOT_FOUND,
new Object[] { "<casProcessor>", "<casProcessors>" }, new Exception(
CpmLocalizedMessage.getLocalizedMessage(CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
"UIMA_CPM_EXP_bad_cpe_descriptor__WARNING", new Object[] { Thread
.currentThread().getName() })));
}
Hashtable namesMap = new Hashtable();
for (int i = 0; i < casProcessorList.length; i++) {
CpeCasProcessor processorType = casProcessorList[i];
if (processorType == null) {
throw new ResourceConfigurationException(InvalidXMLException.ELEMENT_NOT_FOUND,
new Object[] { "<casProcessor>", "<casProcessors>" }, new Exception(
CpmLocalizedMessage.getLocalizedMessage(CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
"UIMA_CPM_EXP_bad_cpe_descriptor__WARNING", new Object[] { Thread
.currentThread().getName() })));
}
// Check for duplicate Cas Processor names. Names must be unique
if (namesMap.containsKey(processorType.getName())) {
throw new ResourceConfigurationException(InvalidXMLException.INVALID_CPE_DESCRIPTOR,
new Object[] { "casProcessor", "name" }, new CPMException(CpmLocalizedMessage
.getLocalizedMessage(CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
"UIMA_CPM_EXP_duplicate_name__WARNING", new Object[] {
Thread.currentThread().getName(), processorType.getName() })));
} else {
namesMap.put(processorType.getName(), processorType.getName());
}
String deploymentType = processorType.getDeployment();
if (deploymentType == null) {
throw new ResourceConfigurationException(InvalidXMLException.REQUIRED_ATTRIBUTE_MISSING,
new Object[] { "deployment", "<casProcessor>" }, new Exception(
CpmLocalizedMessage.getLocalizedMessage(CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
"UIMA_CPM_EXP_missing_attribute_from_xml_element__WARNING",
new Object[] { Thread.currentThread().getName(),
processorType.getName(), "deployment", "casProcessor" })));
}
CasProcessor casProcessor = null;
String deployModel = "";
boolean cpInMap = false;
// Check if the CP has already been instantiated. The map holds one instance of a CP with a
// given name
// The purpose of the map is to provide access to CP operational parameters. This is needed
// to
// determine if multiple instances of the CP are allowed.
if (cpMap.containsKey(processorType.getName())) {
cpInMap = true; // the CasProcessor is in the map
casProcessor = (CasProcessor) cpMap.get(processorType.getName());
// Check operational parameters to determine if multiple instances of the CP are allowed
if (!casProcessor.getProcessingResourceMetaData().getOperationalProperties()
.isMultipleDeploymentAllowed()) {
continue; // one instance already created. Multiple instances of this CP not allowed
}
}
if (Constants.DEPLOYMENT_LOCAL.equals(deploymentType.toLowerCase())) {
casProcessor = produceLocalCasProcessor(processorType);
deployModel = Constants.DEPLOYMENT_LOCAL;
} else if (Constants.DEPLOYMENT_INTEGRATED.equals(deploymentType.toLowerCase())) {
casProcessor = produceIntegratedCasProcessor(processorType);
deployModel = Constants.DEPLOYMENT_INTEGRATED;
} else if (Constants.DEPLOYMENT_REMOTE.equals(deploymentType.toLowerCase())) {
casProcessor = produceRemoteCasProcessor(processorType);
deployModel = Constants.DEPLOYMENT_REMOTE;
} else {
throw new ResourceConfigurationException(InvalidXMLException.REQUIRED_ATTRIBUTE_MISSING,
new Object[] { "deployment", "<casProcessor>" }, new Exception(
CpmLocalizedMessage.getLocalizedMessage(CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
"UIMA_CPM_Exception_invalid_deployment__WARNING", new Object[] {
Thread.currentThread().getName(), processorType.getName(),
deploymentType })));
}
// Add the casProcessor instantiated above to the map. The map is used to check if
// multiple instances of the cp are allowed. Need to store an instance in the map
// since the only way to determine whether or not multiple instances are allowed is
// to check OperationalProperties in the CP metadata.
if (!cpInMap) {
cpMap.put(processorType.getName(), casProcessor);
}
String name = casProcessor.getProcessingResourceMetaData().getName();
if (!casProcessorConfigMap.containsKey(name)) {
casProcessorConfigMap.put(name, processorType);
} else {
// Throw an exception due to a non-unique name. CPM requires Cas Processors to have a
// unique name.
// The unique name enforcement for Local and Remote CP's is done
// above 'if ( namesMap.containsKey(processorType.getName()))'. In case of integrated CP,
// the
// name is taken from the CP descriptor. For Local and Remote, the names are taken from
// the
// CPE descriptor
if (firstTime && Constants.DEPLOYMENT_INTEGRATED.equalsIgnoreCase(deployModel)) {
throw new ResourceConfigurationException(new CPMException(CpmLocalizedMessage
.getLocalizedMessage(CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
"UIMA_CPM_EXP_duplicate_name__WARNING", new Object[] {
Thread.currentThread().getName(), processorType.getName() })));
}
}
v.add(casProcessor);
}
CasProcessor[] processors = new CasProcessor[v.size()];
v.copyInto(processors);
return processors;
} catch (ResourceConfigurationException e) {
throw e;
} catch (Exception e) {
throw new ResourceConfigurationException(e);
} finally {
firstTime = false;
}
}