summaryrefslogtreecommitdiffstats
path: root/tests/bugs151/pr127299/ModelErrorConversion.aj
blob: 3366e15ca24f887e7c539577f8191ce098a153b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
aspect ModelErrorConversion {


  // convert exception types
  after(Entity entity) throwing (HibernateException e): modelExec(entity) {
      convertException(e, entity, thisJoinPoint);
  }
  after(Entity entity) throwing (ServiceException e): modelExec(entity) {
      convertException(e, entity, thisJoinPoint);
  }
  after(Entity entity) throwing (SOAPException e): modelExec(entity) {
      convertException(e, entity, thisJoinPoint);
  }
  after(Entity entity) throwing (SOAPFaultException e): modelExec(entity) {
      convertException(e, entity, thisJoinPoint);
  }

  /** execution of any method in the model */
  pointcut modelExecStatic() : 
      execution(* model..*(..));

  pointcut modelExec(Entity entity) : 
      modelExecStatic() && this(entity);
  // soften the checked exceptions
  declare soft: ServiceException: modelExecStatic(); 
  declare soft: SOAPException: modelExecStatic(); 


  /** Converts exceptions to model exceptions, storing context */
  private void convertException(Exception e, Entity entity, 
          JoinPoint jp) {
      ModelException me = new ModelException(e);
      me.setEntity(entity);
      me.setArgs(jp.getArgs());
      // ModelException extends RuntimeException, so this is unchecked
      throw me;
  }
}

class HibernateException extends RuntimeException {}
class ServiceException extends Exception {}
class SOAPException extends Exception {}
class SOAPFaultException extends RuntimeException {}

class Entity {}

class ModelException extends RuntimeException {
    public ModelException(Throwable t) { super(t); }
    public void setEntity(Entity entity) {}
    public void setArgs(Object[] argz) {}
}