1 | // Copyright 2004-2007 Jean-Francois Poilpret |
2 | // |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | // you may not use this file except in compliance with the License. |
5 | // You may obtain a copy of the License at |
6 | // |
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | // |
9 | // Unless required by applicable law or agreed to in writing, software |
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | // See the License for the specific language governing permissions and |
13 | // limitations under the License. |
14 | |
15 | package net.sourceforge.hiveboard.business; |
16 | |
17 | import net.sourceforge.hiveboard.Account; |
18 | import net.sourceforge.hiveboard.Board; |
19 | import net.sourceforge.hiveboard.Event; |
20 | import net.sourceforge.hiveboard.EventType; |
21 | |
22 | public final class EventFactory |
23 | { |
24 | private EventFactory() |
25 | { |
26 | } |
27 | |
28 | static public Event createLogin(int who) |
29 | { |
30 | return createEvent( EventType.EVT_LOGIN, who, 0, |
31 | null, null, null, null, null); |
32 | } |
33 | |
34 | static public Event createLogout(int who) |
35 | { |
36 | return createEvent( EventType.EVT_LOGOUT, who, 0, |
37 | null, null, null, null, null); |
38 | } |
39 | |
40 | static public Event createJoinBoard(int who, int board, byte[] raster, byte[] action) |
41 | { |
42 | return createEvent( EventType.EVT_JOIN_BOARD, who, board, |
43 | null, action, raster, null, null); |
44 | } |
45 | |
46 | static public Event createLeaveBoard(int who, int board) |
47 | { |
48 | return createEvent( EventType.EVT_LEAVE_BOARD, who, board, |
49 | null, null, null, null, null); |
50 | } |
51 | |
52 | static public Event createSendComment(int who, int board, String comment) |
53 | { |
54 | return createEvent( EventType.EVT_SEND_COMMENT, who, board, |
55 | comment, null, null, null, null); |
56 | } |
57 | |
58 | static public Event createSendDrawing(int who, int board, byte[] action) |
59 | { |
60 | return createEvent( EventType.EVT_SEND_DRAWING, who, board, |
61 | null, action, null, null, null); |
62 | } |
63 | |
64 | static public Event createRequestToken(int source, int board) |
65 | { |
66 | return createEvent( EventType.EVT_REQUEST_TOKEN, source, board, |
67 | null, null, null, null, null); |
68 | } |
69 | |
70 | static public Event createGiveToken(int target, int board) |
71 | { |
72 | return createEvent( EventType.EVT_GIVE_TOKEN, target, board, |
73 | null, null, null, null, null); |
74 | } |
75 | |
76 | static public Event createAddParticipant(int who, int board) |
77 | { |
78 | return createEvent( EventType.EVT_BOARD_ADD_PARTICIPANT, who, board, |
79 | null, null, null, null, null); |
80 | } |
81 | |
82 | static public Event createAddParticipant(int who, Board board) |
83 | { |
84 | return createEvent( EventType.EVT_BOARD_ADD_PARTICIPANT, who, board.getId(), |
85 | null, null, null, board, null); |
86 | } |
87 | |
88 | static public Event createDelParticipant(int who, int board) |
89 | { |
90 | return createEvent( EventType.EVT_BOARD_DEL_PARTICIPANT, who, board, |
91 | null, null, null, null, null); |
92 | } |
93 | |
94 | static public Event createCreateBoard(int who, Board board) |
95 | { |
96 | return createEvent( EventType.EVT_CREATE_BOARD, who, board.getId(), |
97 | null, null, null, board, null); |
98 | } |
99 | |
100 | static public Event createModifyBoard(int who, Board board) |
101 | { |
102 | return createEvent( EventType.EVT_MODIFY_BOARD, who, board.getId(), |
103 | null, null, null, board, null); |
104 | } |
105 | |
106 | static public Event createDestroyBoard(int who, int board) |
107 | { |
108 | return createEvent( EventType.EVT_DESTROY_BOARD, who, board, |
109 | null, null, null, null, null); |
110 | } |
111 | |
112 | static public Event createCreateAccount(Account account) |
113 | { |
114 | return createEvent( EventType.EVT_CREATE_ACCOUNT, account.getId(), 0, |
115 | null, null, null, null, account); |
116 | } |
117 | |
118 | static public Event createModifyAccount(Account account) |
119 | { |
120 | return createEvent( EventType.EVT_MODIFY_ACCOUNT, account.getId(), 0, |
121 | null, null, null, null, account); |
122 | } |
123 | |
124 | static public Event createDestroyAccount(int who) |
125 | { |
126 | return createEvent( EventType.EVT_DESTROY_ACCOUNT, who, 0, |
127 | null, null, null, null, null); |
128 | } |
129 | |
130 | // CSOFF: ParameterNumberCheck |
131 | static public Event createEvent( EventType type, |
132 | int who, |
133 | int where, |
134 | String comment, |
135 | byte[] action, |
136 | byte[] raster, |
137 | Board board, |
138 | Account account) |
139 | { |
140 | Event event = new Event(); |
141 | event.setType(type); |
142 | event.setWho(who); |
143 | event.setWhere(where); |
144 | event.setComment(comment); |
145 | event.setDrawingAction(action); |
146 | event.setRaster(raster); |
147 | event.setBoard(board); |
148 | event.setAccount(account); |
149 | return event; |
150 | } |
151 | // CSON: ParameterNumberCheck |
152 | } |