// instantiate Annotator class
String annotatorClassName;
annotatorClassName = mDescription.getImplementationName();
if (annotatorClassName == null || annotatorClassName.length() == 0) {
throw new ResourceInitializationException(
ResourceInitializationException.MISSING_ANNOTATOR_CLASS_NAME,
new Object[] { mDescription.getSourceUrlString() });
}
// load annotator class
Class<?> annotatorClass = null;
try {
// get UIMA extension ClassLoader if available
ClassLoader cl = getUimaContextAdmin().getResourceManager().getExtensionClassLoader();
if (cl != null) {
// use UIMA extension ClassLoader to load the class
annotatorClass = cl.loadClass(annotatorClassName);
} else {
// use application ClassLoader to load the class
annotatorClass = Class.forName(annotatorClassName);
}
} catch (ClassNotFoundException e) {
throw new ResourceInitializationException(
ResourceInitializationException.ANNOTATOR_CLASS_NOT_FOUND, new Object[] {
annotatorClassName, mDescription.getSourceUrlString() }, e);
}
// Make sure the specified class can be adapter to an AnalysisComponent.
if (!(AnalysisComponent.class.isAssignableFrom(annotatorClass))
&& !AnalysisComponentAdapterFactory.isAdaptable(annotatorClass)) {
throw new ResourceInitializationException(
ResourceInitializationException.NOT_AN_ANALYSIS_COMPONENT, new Object[] {
annotatorClass.getName(), mDescription.getSourceUrlString() });
}
// if we're in verification mode, stop here and do not try to instantiate the
// analysis component
if (mVerificationMode) {
return;
}
try {
Object userObject = annotatorClass.newInstance();
if (userObject instanceof AnalysisComponent) {
mAnalysisComponent = (AnalysisComponent) userObject;
} else {
mAnalysisComponent = AnalysisComponentAdapterFactory.createAdapter(userObject,
getAnalysisEngineMetaData(), aAdditionalParams);
}
} catch (ResourceInitializationException e) {
throw e;
} catch (Exception e) {
throw new ResourceInitializationException(
ResourceInitializationException.COULD_NOT_INSTANTIATE_ANNOTATOR, new Object[] {
annotatorClassName, mDescription.getSourceUrlString() }, e);
}
// Set Logger, to enable annotator-specific logging
UimaContextAdmin uimaContext = getUimaContextAdmin();
Logger logger = UIMAFramework.getLogger(annotatorClass);
logger.setResourceManager(this.getResourceManager());
uimaContext.setLogger(logger);
// initialize AnalysisComponent
try {
mAnalysisComponent.initialize(getUimaContext());
} catch (Exception e) {
throw new ResourceInitializationException(
ResourceInitializationException.ANNOTATOR_INITIALIZATION_FAILED, new Object[] {
annotatorClassName, mDescription.getSourceUrlString() }, e);
}
// set up the CAS pool for this AE (this won't do anything if