private void init(IJobDriver jd, String crxml, String crcfg, CasDispatchMap casDispatchMap) throws IOException, ResourceInitializationException, InvalidXMLException, ResourceConfigurationException {
String location = "init";
this.casDispatchMap = casDispatchMap;
casLimbo = new CasLimbo(jd);
IDuccWorkJob job = jd.getJob();
// CR descriptor
String crDescriptor = crxml;
//
// Read and parse the collection reader
//
XMLParser xmlParser = UIMAFramework.getXMLParser();
XMLInputSource in = null;
try {
in = UimaUtils.getXMLInputSource(crDescriptor);
} catch (InvalidXMLException e) {
duccOut.error(location, job.getDuccId(), e);
throw e;
}
ResourceSpecifier crrs = xmlParser.parseCollectionReaderDescription(in);
duccOut.debug(location, job.getDuccId(), crcfg);
// CR overrides
ResourceCreationSpecifier specifier = (ResourceCreationSpecifier) crrs;
ConfigurationParameterDeclarations configurationParameterDeclarations = specifier.getMetaData().getConfigurationParameterDeclarations();
ConfigurationParameterSettings cps = specifier.getMetaData().getConfigurationParameterSettings();
if(crcfg!= null) {
// Tokenize override assignments on whitespace, honoring but stripping quotes
// Then create a map from all of them
ArrayList<String> toks = QuotedOptions.tokenizeList(crcfg, true);
Map<String,String> map = QuotedOptions.parseAssignments(toks, false);
for (Entry<String, String> ent : map.entrySet()) {
String name = ent.getKey();
String value = ent.getValue();
duccOut.debug(location, job.getDuccId(), "config param name:"+name+" "+"value:"+value);
ConfigurationParameter configurationParameter = UimaUtils.findConfigurationParameter(configurationParameterDeclarations, name);
if (configurationParameter == null) {
throw new ResourceConfigurationException(
ResourceConfigurationException.NONEXISTENT_PARAMETER, new Object[] { name, "CollectionReader" });
}
Object object = UimaUtils.getOverrideValueObject(configurationParameter, value);
cps.setParameterValue(name, object);
}
}
// CR
duccOut.debug(location, job.getDuccId(), "CR creation...");
cr = UIMAFramework.produceCollectionReader(crrs);
Properties props = new Properties();
// Change the heap size to reduce CAS size. The size here depends on what we intend to
// put into the CAS. If its just a pointer to data (like question id), the size of the
// heap can be reduced even more
props.setProperty(UIMAFramework.CAS_INITIAL_HEAP_SIZE, "1000");
// save CR type system. It will be used to initialize CASes later, in getEmptyCas()
init(cr.getProcessingResourceMetaData().getTypeSystem(),
cr.getProcessingResourceMetaData().getTypePriorities(),
cr.getProcessingResourceMetaData().getFsIndexes(),
props);
duccOut.debug(location, job.getDuccId(), "CR created.");
}