protected void initRecognizers(final Map<String, String> properties) { for (final ExceptionRecognizer ers : exceptionRecognizers) { ers.init(properties); } }
public ExceptionRecognizerComposite(final List<? extends ExceptionRecognizer> exceptionRecognizers) { for (final ExceptionRecognizer er : exceptionRecognizers) { add(er); } }
/** * Returns a recognition of the specified type (assuming a non-null reason); else null. */ public static Recognition of(final Category category, final String reason) { return reason != null? new Recognition(category, reason): null; }
/** * Returns the non-<tt>null</tt> recognition of the first {@link #add(ExceptionRecognizer) add}ed * (that is also an {@link org.apache.isis.applib.services.exceprecog.ExceptionRecognizer2}). * * <p> * If none (as {@link org.apache.isis.applib.services.exceprecog.ExceptionRecognizer2}) recognize * the exception, then falls back to using {@link #recognize(Throwable)}, returning a * {@link org.apache.isis.applib.services.exceprecog.ExceptionRecognizer2.Recognition} with a * category of {@link org.apache.isis.applib.services.exceprecog.ExceptionRecognizer2.Category#CLIENT_ERROR}. * </p> */ @Programmatic public final Recognition recognize2(final Throwable ex) { for (final ExceptionRecognizer ers : exceptionRecognizers) { if(ers instanceof ExceptionRecognizer2) { final ExceptionRecognizer2 recognizer2 = (ExceptionRecognizer2) ers; final Recognition recognition = recognizer2.recognize2(ex); if(recognition != null) { return recognition; } } } // backward compatible so far as possible. return Recognition.of(Category.OTHER, recognize(ex)); }
@Test public void whenRecognized() { ersGeneral = new ExceptionRecognizerAbstract(Predicates.<Throwable>alwaysTrue()){}; assertThat(ersGeneral.recognize(new FooException()), is("foo")); }
@Test public void whenRecognized() { ersForType = new ExceptionRecognizerForType(FooException.class); assertThat(ersForType.recognize(new FooException()), is("foo")); }
@Test public void whenDoesNotRecognize() { ersForType = new ExceptionRecognizerForType(FooException.class); assertThat(ersForType.recognize(new BarException()), is(nullValue())); }
/** * Returns the non-<tt>null</tt> message of the first {@link #add(ExceptionRecognizer) add}ed * {@link ExceptionRecognizer service} that recognizes the exception. */ @Programmatic public final String recognize(final Throwable ex) { for (final ExceptionRecognizer ers : exceptionRecognizers) { final String message = ers.recognize(ex); if(message != null) { return message; } } return null; }
@Before public void setUp() throws Exception { composite = new ExceptionRecognizerComposite(); composite.container = mockContainer; composite.translationService = mockTranslationService; context.ignoring(mockContainer); context.ignoring(mockTranslationService); }
public ExceptionRecognizerForType(Category category, final Class<? extends Exception> exceptionType, final Function<String,String> messageParser) { this(category, ofType(exceptionType), messageParser); }
@PreDestroy @Override @Programmatic public void shutdown() { for (final ExceptionRecognizer ers : exceptionRecognizers) { ers.shutdown(); } }
@Test public void whenRecognizedWithMessageParser() { ersGeneral = new ExceptionRecognizerAbstract(Predicates.<Throwable>alwaysTrue(), prepend){}; assertThat(ersGeneral.recognize(new FooException()), is("pre: foo")); }
@Test public void whenRecognizedWithMessageParser() { ersForType = new ExceptionRecognizerForType(FooException.class, prepend); assertThat(ersForType.recognize(new FooException()), is("pre: foo")); }
@Test public void whenDoesNotRecognize() { ersGeneral = new ExceptionRecognizerAbstract(Predicates.<Throwable>alwaysFalse()){}; assertThat(ersGeneral.recognize(new FooException()), is(nullValue())); }