View Javadoc

1   package cz.cuni.amis.pogamut.base.communication.worldview.listener.annotation.exception;
2   
3   import java.lang.reflect.Method;
4   import java.util.logging.Logger;
5   
6   import cz.cuni.amis.pogamut.base.communication.worldview.listener.annotation.AnnotationListenerRegistrator;
7   import cz.cuni.amis.pogamut.base.communication.worldview.listener.annotation.EventListener;
8   import cz.cuni.amis.pogamut.base.communication.worldview.listener.annotation.ObjectClassListener;
9   import cz.cuni.amis.pogamut.base.communication.worldview.listener.annotation.ObjectClassEventListener;
10  import cz.cuni.amis.pogamut.base.communication.worldview.listener.annotation.ObjectListener;
11  import cz.cuni.amis.pogamut.base.communication.worldview.listener.annotation.ObjectEventListener;
12  import cz.cuni.amis.pogamut.base.communication.worldview.object.IWorldObjectEvent;
13  import cz.cuni.amis.utils.ClassUtils;
14  import cz.cuni.amis.utils.exception.PogamutException;
15  
16  public class ListenerMethodParametersException extends PogamutException {
17  
18  	public ListenerMethodParametersException(Method method, String message, AnnotationListenerRegistrator origin) {
19  		super("Method signature " + ClassUtils.getMethodSignature(method) + " is not suitable! " + message, origin);
20  	}
21  	
22  	public ListenerMethodParametersException(Method method, EventListener annotation, AnnotationListenerRegistrator origin) {
23  		super("Method signature " + ClassUtils.getMethodSignature(method) + " does not match required signature " + getLevelSignature(annotation, method) + ".", origin);
24  	}
25  	
26  	public ListenerMethodParametersException(Method method, ObjectClassListener annotation, AnnotationListenerRegistrator origin) {
27  		super("Method signature " + ClassUtils.getMethodSignature(method) + " does not match required signature " + getLevelSignature(annotation, method) + ".", origin);
28  	}
29  	
30  	public ListenerMethodParametersException(Method method, ObjectClassEventListener annotation, AnnotationListenerRegistrator origin) {
31  		super("Method signature " + ClassUtils.getMethodSignature(method) + " does not match required signature " + getLevelSignature(annotation, method) + ".", origin);
32  	}
33  	
34  	public ListenerMethodParametersException(Method method, ObjectListener annotation, AnnotationListenerRegistrator origin) {
35  		super("Method signature " + ClassUtils.getMethodSignature(method) + " does not match required signature " + getLevelSignature(annotation, method) + ".", origin);
36  	}
37  	
38  	public ListenerMethodParametersException(Method method, ObjectEventListener annotation, AnnotationListenerRegistrator origin) {
39  		super("Method signature " + ClassUtils.getMethodSignature(method) + " does not match required signature " + getLevelSignature(annotation, method) + ".", origin);
40  	}
41  	
42  	public ListenerMethodParametersException(Method method, EventListener annotation, Logger log, AnnotationListenerRegistrator origin) {
43  		super("Method signature " + ClassUtils.getMethodSignature(method) + " does not match required signature " + getLevelSignature(annotation, method) + ".", log, origin);
44  	}
45  
46  	public ListenerMethodParametersException(Method method, ObjectClassListener annotation, Logger log, AnnotationListenerRegistrator origin) {
47  		super("Method signature " + ClassUtils.getMethodSignature(method) + " does not match required signature " + getLevelSignature(annotation, method) + ".", log, origin);
48  	}
49  	
50  	public ListenerMethodParametersException(Method method, ObjectClassEventListener annotation, Logger log, AnnotationListenerRegistrator origin) {
51  		super("Method signature " + ClassUtils.getMethodSignature(method) + " does not match required signature " + getLevelSignature(annotation, method) + ".", log, origin);
52  	}
53  	
54  	public ListenerMethodParametersException(Method method, ObjectListener annotation, Logger log, AnnotationListenerRegistrator origin) {
55  		super("Method signature " + ClassUtils.getMethodSignature(method) + " does not match required signature " + getLevelSignature(annotation, method) + ".", log, origin);
56  	}
57  	
58  	public ListenerMethodParametersException(Method method, ObjectEventListener annotation, Logger log, AnnotationListenerRegistrator origin) {
59  		super("Method signature " + ClassUtils.getMethodSignature(method) + " does not match required signature " + getLevelSignature(annotation, method) + ".", log, origin);
60  	}
61  	
62  	private static String getLevelSignature(EventListener annotation, Method method) {
63  		return "void " + method.getName() + "(" + annotation.eventClass() + " event)";
64  	}
65  	
66  	private static String getLevelSignature(ObjectClassListener annotation, Method method) {
67  		return "void " + method.getName() + "(" + IWorldObjectEvent.class + " event)";
68  	}
69  	
70  	private static String getLevelSignature(ObjectClassEventListener annotation, Method method) {
71  		return "void " + method.getName() + "(" + annotation.eventClass() + " event)";
72  	}
73  	
74  	private static String getLevelSignature(ObjectListener annotation, Method method) {
75  		return "void " + method.getName() + "(" + IWorldObjectEvent.class + " event)";
76  	}
77  	
78  	private static String getLevelSignature(ObjectEventListener annotation, Method method) {
79  		return "void " + method.getName() + "(" + annotation.eventClass() + " event)";
80  	}
81  	
82  	
83  }