in uimaj-core/src/main/java/org/apache/uima/util/CasCreationUtils.java [1977:2110]
private static List<ProcessingResourceMetaData> getMetaDataList(
Collection<? extends MetaDataObject> aComponentDescriptionOrMetaData,
ResourceManager aResourceManager, Map<String, ? super Exception> aOutputFailedRemotes,
String aContextName) throws ResourceInitializationException {
List<ProcessingResourceMetaData> mdList = new ArrayList<>();
if (null == aComponentDescriptionOrMetaData) {
return mdList;
}
Iterator<? extends MetaDataObject> iter = aComponentDescriptionOrMetaData.iterator();
while (iter.hasNext()) {
Object current = iter.next();
if (current instanceof ProcessingResourceMetaData) {
mdList.add((ProcessingResourceMetaData) ((ProcessingResourceMetaData) current).clone());
} else if (current instanceof AnalysisEngineDescription) {
AnalysisEngineDescription aeDesc = (AnalysisEngineDescription) current;
mdList.add((ProcessingResourceMetaData) aeDesc.getAnalysisEngineMetaData().clone());
// expand aggregate
if (!aeDesc.isPrimitive()) {
Map<String, ResourceSpecifier> delegateMap;
try {
delegateMap = aeDesc.getAllComponentSpecifiers(aResourceManager);
} catch (InvalidXMLException e) {
throw new ResourceInitializationException(e);
}
Iterator<Map.Entry<String, ResourceSpecifier>> delIter = delegateMap.entrySet()
.iterator();
while (delIter.hasNext()) {
Map.Entry<String, ResourceSpecifier> delEntry = delIter.next();
List<ResourceSpecifier> tempList = new ArrayList<>();
tempList.add(delEntry.getValue());
mdList.addAll(getMetaDataList(tempList, aResourceManager, aOutputFailedRemotes,
aContextName + "/" + delEntry.getKey()));
}
}
} else if (current instanceof CollectionReaderDescription) {
mdList.add((ProcessingResourceMetaData) ((CollectionReaderDescription) current)
.getCollectionReaderMetaData().clone());
} else if (current instanceof CasInitializerDescription) {
mdList.add((ProcessingResourceMetaData) ((CasInitializerDescription) current)
.getCasInitializerMetaData().clone());
} else if (current instanceof CasConsumerDescription) {
mdList.add((ProcessingResourceMetaData) ((CasConsumerDescription) current)
.getCasConsumerMetaData().clone());
} else if (current instanceof FlowControllerDescription) {
mdList.add((ProcessingResourceMetaData) ((FlowControllerDescription) current)
.getFlowControllerMetaData().clone());
} else if (current instanceof TypeSystemDescription) {
ProcessingResourceMetaData md = new ProcessingResourceMetaData_impl();
md.setTypeSystem((TypeSystemDescription) current);
mdList.add(md);
} else if (current instanceof FsIndexCollection) {
ProcessingResourceMetaData md = new ProcessingResourceMetaData_impl();
md.setFsIndexCollection((FsIndexCollection) current);
mdList.add(md);
} else if (current instanceof TypePriorities) {
ProcessingResourceMetaData md = new ProcessingResourceMetaData_impl();
md.setTypePriorities((TypePriorities) current);
mdList.add(md);
} else if (current instanceof ResourceSpecifier) {
// first try the cache
MetaDataCacheKey metaDataCacheKey = new MetaDataCacheKey((ResourceSpecifier) current,
aResourceManager);
synchronized (metaDataCache) {
MetaDataCacheEntry metaData = metaDataCache.get(metaDataCacheKey);
if (null != metaData) {
if (cacheDebug) {
System.err.format("GetMetaDataCache: using cached entry%n");
}
if (null != metaData.processingResourceMetaData) {
mdList.add(metaData.processingResourceMetaData);
}
continue;
}
}
// try to instantiate the resource
Resource resource = null;
Map<String, Object> prParams = new HashMap<>();
if (aResourceManager != null) {
prParams.put(Resource.PARAM_RESOURCE_MANAGER, aResourceManager);
}
prParams.put(AnalysisEngineImplBase.PARAM_VERIFICATION_MODE, Boolean.TRUE);
try {
resource = UIMAFramework.produceResource((ResourceSpecifier) current, prParams);
// (null == aResourceManager) ? Collections.<String, Object>emptyMap() :
// resourceMgrInMap);
} catch (Exception e) {
// record failure, so we don't ask for this again, for a while
synchronized (metaDataCache) {
if (cacheDebug) {
System.err.format("GetMetaDataCache: saving entry in cache%n");
}
metaDataCache.put(metaDataCacheKey, new MetaDataCacheEntry(null));
}
// failed. If aOutputFailedRemotes is non-null, add an entry to it to it, else throw the
// exception.
if (aOutputFailedRemotes != null) {
aOutputFailedRemotes.put(aContextName, e);
} else {
if (e instanceof ResourceInitializationException)
throw (ResourceInitializationException) e;
else if (e instanceof RuntimeException)
throw (RuntimeException) e;
else
throw new RuntimeException(e);
}
}
ResourceMetaData metadata = (resource == null) ? null : resource.getMetaData();
synchronized (metaDataCache) {
if (cacheDebug) {
System.err.format("GetMetaDataCache: saving entry in cache%n");
}
metaDataCache.put(metaDataCacheKey, new MetaDataCacheEntry(metadata));
}
if (resource != null) {
if (metadata instanceof ProcessingResourceMetaData) {
mdList.add((ProcessingResourceMetaData) metadata);
}
resource.destroy();
}
} else {
throw new ResourceInitializationException(
ResourceInitializationException.UNSUPPORTED_OBJECT_TYPE_IN_CREATE_CAS,
new Object[] { current.getClass().getName() });
}
}
return mdList;
}