You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ModelErrorConversion.aj 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. aspect ModelErrorConversion {
  2. // convert exception types
  3. after(Entity entity) throwing (HibernateException e): modelExec(entity) {
  4. convertException(e, entity, thisJoinPoint);
  5. }
  6. after(Entity entity) throwing (ServiceException e): modelExec(entity) {
  7. convertException(e, entity, thisJoinPoint);
  8. }
  9. after(Entity entity) throwing (SOAPException e): modelExec(entity) {
  10. convertException(e, entity, thisJoinPoint);
  11. }
  12. after(Entity entity) throwing (SOAPFaultException e): modelExec(entity) {
  13. convertException(e, entity, thisJoinPoint);
  14. }
  15. /** execution of any method in the model */
  16. pointcut modelExecStatic() :
  17. execution(* model..*(..));
  18. pointcut modelExec(Entity entity) :
  19. modelExecStatic() && this(entity);
  20. // soften the checked exceptions
  21. declare soft: ServiceException: modelExecStatic();
  22. declare soft: SOAPException: modelExecStatic();
  23. /** Converts exceptions to model exceptions, storing context */
  24. private void convertException(Exception e, Entity entity,
  25. JoinPoint jp) {
  26. ModelException me = new ModelException(e);
  27. me.setEntity(entity);
  28. me.setArgs(jp.getArgs());
  29. // ModelException extends RuntimeException, so this is unchecked
  30. throw me;
  31. }
  32. }
  33. class HibernateException extends RuntimeException {}
  34. class ServiceException extends Exception {}
  35. class SOAPException extends Exception {}
  36. class SOAPFaultException extends RuntimeException {}
  37. class Entity {}
  38. class ModelException extends RuntimeException {
  39. public ModelException(Throwable t) { super(t); }
  40. public void setEntity(Entity entity) {}
  41. public void setArgs(Object[] argz) {}
  42. }