01: package dalma.endpoints.email;
02:
03: import dalma.impl.EndPointImpl;
04:
05: import javax.mail.MessagingException;
06: import javax.mail.internet.MimeMessage;
07:
08: /**
09: * Listens to the incoming e-mail messages and pass it to
10: * {@link EmailEndPoint}.
11: *
12: * <p>
13: * Derived classes are expected to provide the actual implementation of the listeneing logic.
14: *
15: * @author Kohsuke Kawaguchi
16: */
17: public abstract class Listener {
18: protected Listener() {
19: }
20:
21: /**
22: * {@link EmailEndPoint} associated to this listener.
23: */
24: private EmailEndPoint endPoint;
25:
26: /**
27: * Invoked when a {@link Listener} is added to {@link EmailEndPoint}.
28: */
29: protected void setEndPoint(EmailEndPoint ep) {
30: if (this .endPoint != null)
31: throw new IllegalStateException(
32: "this listener is already registered with an endpoint");
33: this .endPoint = ep;
34: }
35:
36: /**
37: * Gets the {@link EmailEndPoint} associated with this {@link Listener}.
38: *
39: * @return
40: * null if no association is made yet.
41: */
42: public EmailEndPoint getEndPoint() {
43: return endPoint;
44: }
45:
46: /**
47: * Derived classes should call this method when
48: * a new e-mail is received.
49: *
50: * This method can be invoked from any thread.
51: */
52: protected void handleMessage(MimeMessage msg)
53: throws MessagingException {
54: endPoint.handleMessage(msg);
55: }
56:
57: /**
58: * @see EndPointImpl#start()
59: */
60: protected abstract void start();
61:
62: /**
63: * @see EndPointImpl#stop()
64: */
65: protected abstract void stop();
66: }
|