Details
-
Improvement
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
None
-
None
Description
The AnnotationFactory provides a shortcut alternative to creating an annotation and adding it to the indexes:
JCas/UIMA:
a) new Token(jcas, 1, 5).addToIndexes(); b) jcas.addFsToIndexes(jCas.getCas().createAnnotation(JCasUtil.getAnnotationType(jCas, typeClass), begin, end));
AnnotationFactory
a) createAnnotation(jcas, 1, 5, Token.class); b) createAnnotation(jcas, 1, 5, typeClass);
Internally, AnnotationFactory uses reflection on JCas classes to achieve that and if there is a problem while reflectively creating the annotation, it throws an UIMAException. It is very unlikely that a problem would occur. It could happen if security restrictions are in place on certain JCas wrapper classes. Yet, the UIMAException is not a RuntimeException, so it must be caught by client code.
AnnotationFactory could use the CAS interface instead of reflection to avoid the exception. We can be sure that any annotation created through the CAS interface can safely be cast to a JCas wrapper type, because the JCas has already been initialized when this method is calls (it receives a JCas as argument).