* org.apache.uima.resource.ResourceSpecifier, java.util.Map)
*/
public Resource produceResource(Class aResourceClass, ResourceSpecifier aSpecifier,
Map aAdditionalParams) throws ResourceInitializationException {
if (aSpecifier instanceof CasConsumerDescription) {
CasConsumerDescription desc = (CasConsumerDescription) aSpecifier;
final String frameworkImpl = desc.getFrameworkImplementation();
if (frameworkImpl == null || frameworkImpl.length() == 0) {
throw new ResourceInitializationException(
ResourceInitializationException.MISSING_FRAMEWORK_IMPLEMENTATION,
new Object[] { aSpecifier.getSourceUrlString() });
}
if (frameworkImpl.startsWith(Constants.JAVA_FRAMEWORK_NAME)) {
String className = desc.getImplementationName();
if (className == null || className.length() == 0) {
throw new ResourceInitializationException(
ResourceInitializationException.MISSING_IMPLEMENTATION_CLASS_NAME,
new Object[] { aSpecifier.getSourceUrlString() });
}
// load class using UIMA Extension ClassLoader if there is one
ClassLoader cl = null;
Class implClass = null;
ResourceManager resourceManager = null;
if (aAdditionalParams != null) {
resourceManager = (ResourceManager) aAdditionalParams
.get(Resource.PARAM_RESOURCE_MANAGER);
}
if (resourceManager != null) {
cl = resourceManager.getExtensionClassLoader();
}
if (cl == null) {
cl = this.getClass().getClassLoader();
}
try {
implClass = Class.forName(className, true, cl);
} catch (ClassNotFoundException e) {
throw new ResourceInitializationException(
ResourceInitializationException.CLASS_NOT_FOUND, new Object[] { className,
aSpecifier.getSourceUrlString() }, e);
}
// check to see if this is a subclass of Cas[Data]Consumer and of aResourceClass
if (!CasConsumer.class.isAssignableFrom(implClass)
&& !CasDataConsumer.class.isAssignableFrom(implClass)) {
throw new ResourceInitializationException(
ResourceInitializationException.NOT_A_CAS_CONSUMER, new Object[] { className,
aSpecifier.getSourceUrlString() });
}
if (!aResourceClass.isAssignableFrom(implClass)) {
throw new ResourceInitializationException(
ResourceInitializationException.RESOURCE_DOES_NOT_IMPLEMENT_INTERFACE,
new Object[] { className, aResourceClass.getName(),
aSpecifier.getSourceUrlString() });
}
// instantiate this Resource Class
Resource resource;
try {
resource = (Resource) implClass.newInstance();
} catch (InstantiationException e) {
throw new ResourceInitializationException(
ResourceInitializationException.COULD_NOT_INSTANTIATE, new Object[] { className,
aSpecifier.getSourceUrlString() }, e);
} catch (IllegalAccessException e) {
throw new ResourceInitializationException(
ResourceInitializationException.COULD_NOT_INSTANTIATE, new Object[] { className,
aSpecifier.getSourceUrlString() }, e);
}
// attempt to initialize it
if (resource.initialize(aSpecifier, aAdditionalParams)) {
// success!
return resource;
} else
// failure, for some unknown reason :( This isn't likely to happen
{
throw new ResourceInitializationException(
ResourceInitializationException.ERROR_INITIALIZING_FROM_DESCRIPTOR, new Object[] {
className, aSpecifier.getSourceUrlString() });
}
} else if (frameworkImpl.startsWith(Constants.CPP_FRAMEWORK_NAME)) {
Resource resource = new UimacppAnalysisEngineImpl();
if (resource.initialize(aSpecifier, aAdditionalParams)) {
// success!
return resource;
} else
// failure, for some unknown reason :( This isn't likely to happen
{
throw new ResourceInitializationException(
ResourceInitializationException.ERROR_INITIALIZING_FROM_DESCRIPTOR, new Object[] {
UimacppAnalysisComponent.class.getName(), aSpecifier.getSourceUrlString() });
}
} else {
throw new ResourceInitializationException(
ResourceInitializationException.UNSUPPORTED_FRAMEWORK_IMPLEMENTATION, new Object[] {
desc.getFrameworkImplementation(), aSpecifier.getSourceUrlString() });
}
} else {
return null;
}
}