}
}
public void instantiateJCas_Types(ClassLoader cl) {
Map<String, LoadedJCasType> loadedJCasTypes = null;
FSClassRegistry fscr = casImpl.getFSClassRegistry();
boolean alreadyLoaded; // means the "classes" have been loaded, but doesn't mean
// the _Type instances of those classes have been created.
boolean anyNewInstances = false; // true if any new instances of _Type are generated
FSGenerator[] newFSGeneratorSet;
synchronized (JCasImpl.class) {
Map<ClassLoader, Map<String, LoadedJCasType>> classLoaderToLoadedJCasTypes = typeSystemToLoadedJCasTypesByClassLoader.get(casImpl
.getTypeSystemImpl());
if (null != classLoaderToLoadedJCasTypes) {
loadedJCasTypes = classLoaderToLoadedJCasTypes.get(cl);
}
alreadyLoaded = (null != loadedJCasTypes);
if (!alreadyLoaded) {
loadedJCasTypes = loadJCasClasses(cl);
}
expandTypeArrayIfNeeded();
// if already loaded, can skip making new generators -
// in this case newFSGeneratorSet is never referenced
// Set it to null for "safety"
newFSGeneratorSet = alreadyLoaded ? null : fscr.getNewFSGeneratorSet();
for (Iterator<Map.Entry<String, LoadedJCasType>> it = loadedJCasTypes.entrySet().iterator(); it.hasNext();) {
// Explanation for this logic:
// Instances of _Types are kept per class loader, per Cas (e.g., in the cas pool)
// When switching class loaders (e.g. a pear in the pipeline), some of the
// _Type instances (e.g. the built-ins) might be already instantiated, but others are not
//
boolean madeNewInstance = makeInstanceOf_Type(it.next().getValue(), alreadyLoaded,
newFSGeneratorSet);
anyNewInstances = madeNewInstance || anyNewInstances;
}
// speed up - skip rest if nothing to do
if (!anyNewInstances) {
return;
}
if (!alreadyLoaded) {
copyDownSuperGenerators(loadedJCasTypes, newFSGeneratorSet);
if (casImpl.usingBaseClassLoader()) {
fscr.setBaseGenerators(newFSGeneratorSet); // should be under sync lock
}
fscr.saveGeneratorsForClassLoader(cl, newFSGeneratorSet);
}
}
if (alreadyLoaded) {
fscr.swapInGeneratorsForClassLoader(cl, casImpl);
} else {
casImpl.setLocalFsGenerators(newFSGeneratorSet);
}
}