/** * 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; }
private Object loadPersistentPojo(final RootOid rootOid) { Object result; try { final Class<?> cls = clsOf(rootOid); final Object jdoObjectId = JdoObjectIdSerializer.toJdoObjectId(rootOid); FetchPlan fetchPlan = persistenceManager.getFetchPlan(); fetchPlan.addGroup(FetchGroup.DEFAULT); result = persistenceManager.getObjectById(cls, jdoObjectId); } catch (final RuntimeException e) { Class<ExceptionRecognizer> serviceClass = ExceptionRecognizer.class; final List<ExceptionRecognizer> exceptionRecognizers = lookupServices(serviceClass); for (ExceptionRecognizer exceptionRecognizer : exceptionRecognizers) { if(exceptionRecognizer instanceof ExceptionRecognizer2) { final ExceptionRecognizer2 recognizer = (ExceptionRecognizer2) exceptionRecognizer; final ExceptionRecognizer2.Recognition recognition = recognizer.recognize2(e); if(recognition != null) { if(recognition.getCategory() == ExceptionRecognizer2.Category.NOT_FOUND) { throw new ObjectNotFoundException(rootOid, e); } } } } throw e; } if (result == null) { throw new ObjectNotFoundException(rootOid); } return result; }
/** * 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)); }
@Programmatic @Override public Recognition recognize2(Throwable ex) { return Recognition.of(category, recognize(ex)); }