for ( Element bindingEl : bindingChildren ) {
final Element dictEl = bindingEl.getChild( "dictionaryRef" );
final String dictID = dictEl.getAttributeValue( "idRef" );
final DictionaryEngine dictEngine = dictMap.get( dictID );
if ( dictEngine == null ) {
throw new AnnotatorContextException( "Dictionary undefined: " + dictID, null );
}
final Element lookupInitEl = bindingEl.getChild( "lookupInitializer" );
final String liClassName = lookupInitEl.getAttributeValue( "className" );
final Element liPropertiesEl = lookupInitEl.getChild( "properties" );
final Properties liProps = parsePropertiesXml( liPropertiesEl );
final Class<?> liClass = Class.forName( liClassName );
final Constructor<?> liConstr = liClass.getConstructor( constrArgs );
final Object[] liArgs = {annotCtx, liProps};
final LookupInitializer li = (LookupInitializer) liConstr.newInstance( liArgs );
final Element lookupConsumerEl = bindingEl.getChild( "lookupConsumer" );
final String lcClassName = lookupConsumerEl.getAttributeValue( "className" );
final Element lcPropertiesEl = lookupConsumerEl.getChild( "properties" );
final Properties lcProps = parsePropertiesXml( lcPropertiesEl );
final Class<?> lcClass = Class.forName( lcClassName );
final Constructor<?>[] consts = lcClass.getConstructors();
Constructor<?> lcConstr = null;
Object[] lcArgs = null;
for ( Constructor<?> constConstr : consts ) {
lcConstr = constConstr;
if ( Arrays.equals( constrArgsConsum, lcConstr.getParameterTypes() ) ) {
lcConstr = lcClass.getConstructor( constrArgsConsum );
lcArgs = new Object[]{annotCtx, lcProps, MAX_LIST_SIZE};//ohnlp-Bugs-3296301
} else if ( Arrays.equals( constrArgsConsumB, lcConstr.getParameterTypes() ) ) {
lcConstr = lcClass.getConstructor( constrArgsConsumB );
lcArgs = new Object[]{annotCtx, lcProps};
}
}
final LookupConsumer lc = (LookupConsumer) lcConstr.newInstance( lcArgs );
final LookupAlgorithm la = li.getLookupAlgorithm( dictEngine );
final LookupSpec ls = new LookupSpec( la, li, lc );
lsSet.add( ls );
}
// TODO refactor to catch ( ex1 | ex2 | ex3 ) when cTakes moves to java 7
} catch ( ClassNotFoundException cnfE ) {
// thrown by Class.forName(..)
throw new AnnotatorContextException( cnfE );
} catch ( NoSuchMethodException nsmE ) {
// thrown by Class.getConstructor(..)
throw new AnnotatorContextException( nsmE );
} catch ( SecurityException secE ) {
// thrown by Class.getConstructor(..)
throw new AnnotatorContextException( secE );
} catch ( InstantiationException instE ) {
// thrown by Class.newInstance(..)
throw new AnnotatorContextException( instE );
} catch ( IllegalAccessException iaE ) {
// thrown by Class.newInstance(..)
throw new AnnotatorContextException( iaE );
} catch ( InvocationTargetException itE ) {
// thrown by Class.newInstance(..)
throw new AnnotatorContextException( itE );
} catch ( AnnotatorInitializationException aiE ) {
// thrown by LookupInitializer.getLookupAlgorithm(..)
throw new AnnotatorContextException( aiE );
} catch ( ClassCastException ccE ) {
// thrown everywhere in this method ...
throw new AnnotatorContextException( ccE );
} catch ( NullPointerException npE ) {
// thrown everywhere in this method ...
throw new AnnotatorContextException( npE );
}
return lsSet;
}