]> git.somenet.org - pub/jan/sbc.git/blob - src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/spacehelpers/SpaceListenerImplBuilder.java
GUI fix for Tables OutOfBoundsException
[pub/jan/sbc.git] / src / main / java / at / ac / tuwien / sbc / valesriegler / xvsm / spacehelpers / SpaceListenerImplBuilder.java
1 package at.ac.tuwien.sbc.valesriegler.xvsm.spacehelpers;
2
3 import at.ac.tuwien.sbc.valesriegler.common.Util;
4 import org.mozartspaces.core.Capi;
5 import org.mozartspaces.core.ContainerReference;
6 import org.mozartspaces.notifications.NotificationManager;
7 import org.mozartspaces.notifications.Operation;
8
9 public class SpaceListenerImplBuilder {
10     private Capi capi;
11     private ContainerReference cref;
12     private int timeout = 3000;
13     private SpaceAction spaceAction;
14     private boolean lookaround = false;
15     private NotificationManager notificationManager;
16     private boolean countAll = false;
17     private String name;
18
19     public SpaceListenerImplBuilder setCapi(Capi capi) {
20         this.capi = capi;
21         return this;
22     }
23
24     public SpaceListenerImplBuilder setCref(ContainerReference cref) {
25         this.cref = cref;
26         return this;
27     }
28
29     public SpaceListenerImplBuilder setTimeout(int timeout) {
30         this.timeout = timeout;
31         return this;
32     }
33
34     public SpaceListenerImplBuilder setSpaceAction(SpaceAction spaceAction) {
35         this.spaceAction = spaceAction;
36         return this;
37     }
38
39     public SpaceListenerImplBuilder setNotificationManager(NotificationManager mgr) {
40         this.notificationManager = mgr;
41         return this;
42     }
43
44     public SpaceListenerImplBuilder enableCountAll() {
45         this.countAll = true;
46         return this;
47     }
48
49     public SpaceListenerImplBuilder setLookaround(boolean lookaround) {
50         this.lookaround = lookaround;
51         return this;
52     }
53
54     public SpaceListenerImpl createSpaceListenerImpl() {
55         final SpaceListenerImpl spaceListener = new SpaceListenerImpl(capi, cref, timeout, spaceAction, notificationManager, lookaround, countAll, name);
56         spaceListener.startHandlingAbsenceOfNotifications();
57         try {
58            notificationManager.createNotification(cref, spaceListener, Operation.WRITE);
59         } catch (Exception e) {
60             Util.handleSpaceErrorAndTerminate(e);
61         }
62         return spaceListener;
63     }
64
65     public SpaceListenerImplBuilder setName(String name) {
66         this.name = name;
67         return this;
68     }
69 }