1 /***
2 * Java DAB EPG API - Serialize/Deserialize To/From POJOs to XML/Binary as per
3 * ETSI specifications TS 102 818 (XML Specification for DAB EPG) and TS 102
4 * 371 (Transportation and Binary Encoding Specification for EPG).
5 *
6 * Copyright (C) 2007 GCap Media PLC
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22 package com.gcapmedia.dab.epg;
23
24 import java.util.*;
25
26 /***
27 *
28 */
29 public class Programme {
30
31 /***
32 * Programme names
33 */
34 private NameGroup names;
35
36 /***
37 * Programme locations
38 */
39 private List<Location> locations;
40
41 /***
42 * Programme media descriptions
43 */
44 private MediaGroup media;
45
46 /***
47 * Programme genres
48 */
49 private List<Genre> genres;
50
51 /***
52 * Conditional Access type
53 */
54 private CAType ca = CAType.NONE;
55
56 /***
57 * Programme keywords
58 */
59 private Keywords keywords;
60
61 /***
62 * Groups this programme is a member of
63 */
64 private List<Membership> memberships;
65
66 /***
67 * Used to link to additional information or content
68 */
69 private List<Link> links;
70
71 /***
72 * Short CRID
73 */
74 private ShortCrid shortId;
75
76 /***
77 * Programme CRID
78 */
79 private Crid id;
80
81 /***
82 * Programme version
83 */
84 private int version;
85
86 /***
87 * This is used by the broadcaster to indicate a recommended
88 * programme or programme event.
89 */
90 private Recommendation recommendation = Recommendation.NO;
91
92 /***
93 * This indicates, for the duration of this programme or event,
94 * whether the parent service is being broadcast (i.e. "on-air")
95 * or not (i.e. "off-air"). At times when a service is not being
96 * broadcast the broadcast can use this facility to include "dummy"
97 * EPG entries that promote the service.
98 */
99 private BroadcastFlag broadcastFlag;
100
101 /***
102 * Bitrate
103 */
104 private int bitrate;
105
106 /***
107 * Programme locale in order to determine the two letter language
108 * code in ISO 639-1
109 */
110 private Locale locale = Locale.getDefault();
111
112 /***
113 * Programme events can be used to break a programme into sections
114 * or to highlight particular sections of the programme.
115 */
116 private List<ProgrammeEvent> events;
117
118 /***
119 * Create a new programme
120 */
121 public Programme(ShortCrid id) {
122 this.shortId = id;
123 names = new NameGroup();
124 media = new MediaGroup();
125 locations = new ArrayList<Location>();
126 genres = new ArrayList<Genre>();
127 memberships = new ArrayList<Membership>();
128 links = new ArrayList<Link>();
129 events = new ArrayList<ProgrammeEvent>();
130 version = 1;
131 }
132
133 /***
134 * Sets the programme bitrate. Where individual programmes vary
135 * from the default service bitrate, this represents tthe highest bitrate
136 * that the programme broadcasts at.
137 * @param bitrate The programme bitrate in Kbps.
138 */
139 public void setBitrate(int bitrate) {
140 this.bitrate = bitrate;
141 }
142
143 /***
144 * @return Returns the programme bitrate in Kbps. Where individual programmes vary
145 * from the default service bitrate, this represents tthe highest bitrate
146 * that the programme broadcasts at.
147 */
148 public int getBitrate() {
149 return bitrate;
150 }
151
152 /***
153 * Sets the broadcast flag.
154 * @param By default, this flag is <b>on-air</b> and should not be set. Can be
155 * set to <b>off-air</b> to generate dummy programmes for when a service is not
156 * being broadcast.
157 */
158 public BroadcastFlag setBroadcastFlag(BroadcastFlag flag) {
159 return broadcastFlag;
160 }
161
162 /***
163 * @return Returns the broadcast flag: Can be set to <b>off-air</b> to generate
164 * dummy programmes for when a service is not being broadcast. By default, this
165 * flag is <b>on-air</b> and should not be set.
166 */
167 public BroadcastFlag getBroadcastFlag() {
168 return broadcastFlag;
169 }
170
171 /***
172 * Sets the Conditional Access (CA) type
173 * @param ca CA type to set
174 */
175 public void setCA(CAType ca) {
176 this.ca = ca;
177 }
178
179 /***
180 * @return Returns the Conditional Access (CA) type
181 */
182 public CAType getCA() {
183 return ca;
184 }
185
186 /***
187 * Adds a genre to the programme
188 * @param genre Genre to add
189 */
190 public void addGenre(Genre genre) {
191 genres.add(genre);
192 }
193
194 /***
195 * Clears all genre from the programme
196 */
197 public void clearGenres() {
198 genres.clear();
199 }
200
201 /***
202 * Removes a genre from the programme
203 * @param genre Genre to remove
204 */
205 public void removeGenre(Genre genre) {
206 genres.remove(genre);
207 }
208
209 /***
210 * @return Returns the programme genres
211 */
212 public List<Genre> getGenres() {
213 return genres;
214 }
215
216 /***
217 * Sets the programme Content Reference ID (CRID)
218 * @param id CRID to set
219 */
220 public void setId(Crid id) {
221 this.id = id;
222 }
223
224 /***
225 * @return Returns the programme Content Reference ID (CRID)
226 */
227 public Crid getId() {
228 return id;
229 }
230
231 /***
232 * Set the keywords associated with this programme
233 * @param keywords Keywords to use
234 */
235 public void setKeywords(Keywords keywords) {
236 this.keywords = keywords;
237 }
238
239 /***
240 * @return Returns the keywords associated with this programme
241 */
242 public Keywords getKeywords() {
243 return keywords;
244 }
245
246 /***
247 * Sets the locale associated with this programme
248 * @param locale Locale associated with this programme
249 */
250 public void setLocale(Locale locale) {
251 this.locale = locale;
252 }
253
254 /***
255 * @return Returns the language code (ISO-639) associated with
256 * this programme
257 */
258 public String getLanguage() {
259 return locale.getLanguage();
260 }
261
262 /***
263 * @return Returns links to additional information or content
264 */
265 public Collection<Link> getLinks() {
266 return Collections.unmodifiableCollection(links);
267 }
268
269 /***
270 * Add a link from this programme to additional information or content
271 * @param link Link to add
272 */
273 public void addLink(Link link) {
274 links.add(link);
275 }
276
277 /***
278 * Remove a link from this programme
279 * @param link Link to remove
280 */
281 public void removeLink(Link link) {
282 links.remove(link);
283 }
284
285 /***
286 * Clear all links from this programme
287 */
288 public void clearLinks() {
289 links.clear();
290 }
291
292 /***
293 * @return Returns all locations from this programme
294 */
295 public Collection<Location> getLocations() {
296 return Collections.unmodifiableCollection(locations);
297 }
298
299 /***
300 * Add a location to this programme
301 * @param location Location to add
302 */
303 public void addLocation(Location location) {
304
305
306 if(location.getRelativeTimes().size() > 0) {
307 throw new IllegalArgumentException("Cannot use a location with relative times for a programme");
308 }
309
310 locations.add(location);
311 }
312
313 /***
314 * Remove a location from this programme
315 * @param location Location to remove
316 */
317 public void removeLocation(Location location) {
318 locations.remove(location);
319 }
320
321 /***
322 * Clear all locations from this programme
323 */
324 public void clearLocations() {
325 locations.clear();
326 }
327
328 /***
329 * @return Returns media descriptions related to this programme
330 */
331 public MediaGroup getMedia() {
332 return media;
333 }
334
335 /***
336 * @return Returns memberships this programme has
337 */
338 public Collection<Membership> getMemberships() {
339 return Collections.unmodifiableCollection(memberships);
340 }
341
342 /***
343 * Add a membership to this programme
344 * @param membership Membership to add
345 */
346 public void addMembership(Membership membership) {
347 memberships.add(membership);
348 }
349
350 /***
351 * Removes a membership from this programme
352 * @param membership Membership to remove
353 */
354 public void removeMembership(Membership membership) {
355 memberships.remove(membership);
356 }
357
358 /***
359 * Clears all memberships from this programme
360 */
361 public void clearMemberships() {
362 memberships.clear();
363 }
364
365 /***
366 * @return Returns the name group for this programme
367 */
368 public NameGroup getNames() {
369 return names;
370 }
371
372 /***
373 * Sets the recommendation flag on this programme
374 * @param recommendation Recommendation flag to set
375 */
376 public void setRecommendation(Recommendation recommendation) {
377 this.recommendation = recommendation;
378 }
379
380 /***
381 * @return Returns whether this programme is recommended
382 */
383 public Recommendation getRecommendation() {
384 return recommendation;
385 }
386
387 /***
388 * Sets the programme Short ID
389 * @param shortId Programme Short ID
390 */
391 public void setShortId(ShortCrid shortId) {
392 this.shortId = shortId;
393 }
394
395 /***
396 * @return Returns the programme short ID
397 */
398 public ShortCrid getShortId() {
399 return shortId;
400 }
401
402 /***
403 * Adds a programme event to the programme
404 * @param event Programme event to add
405 */
406 public void addEvent(ProgrammeEvent event) {
407 events.add(event);
408 }
409
410 /***
411 * @return Returns all programme events
412 */
413 public Collection<ProgrammeEvent> getEvents() {
414 return Collections.unmodifiableCollection(events);
415 }
416
417 /***
418 * Set the programme version
419 * @param version Programme version
420 */
421 public void setVersion(int version) {
422 this.version = version;
423 }
424
425 /***
426 * @return Returns the programme version
427 */
428 public int getVersion() {
429 return version;
430 }
431
432 /***
433 * @see java.lang.Object#equals(java.lang.Object)
434 */
435 @Override
436 public boolean equals(Object obj) {
437 if(!(obj instanceof Programme)) {
438 return false;
439 }
440 Programme that = (Programme)obj;
441 return this.shortId.equals(that.shortId);
442 }
443
444 /***
445 * @see java.lang.Object#toString()
446 */
447 public String toString() {
448 StringBuilder buf = new StringBuilder();
449 buf.append("Programme [scrid=" + shortId);
450 if(id != null) {
451 buf.append(", crid=" + id);
452 }
453 buf.append("]");
454 return buf.toString();
455 }
456
457 }