View Javadoc

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.binary;
23  
24  
25  /***
26   * Enumeration for enum types, confusingly enough.
27   * TODO need to work a mechanism for creating and parsing of default values.
28   */
29  public enum EnumType implements Encodable {
30  	
31  	epgSystemDAB(AttributeTag.epgSystem, 0x01),
32  	epgSystemDRM(AttributeTag.epgSystem, 0x02),
33  	
34  	programmeGroupTypeSeries(AttributeTag.programmeGroupType, 0x02),
35  	programmeGroupTypeShow(AttributeTag.programmeGroupType, 0x03),
36  	programmeGroupTypeProgramConcept(AttributeTag.programmeGroupType, 0x04),
37  	programmeGroupTypeMagazine(AttributeTag.programmeGroupType, 0x05),
38  	programmeGroupTypeProgramCompilation(AttributeTag.programmeGroupType, 0x06),
39  	programmeGroupTypeOtherCollection(AttributeTag.programmeGroupType, 0x07),
40  	programmeGroupTypeOtherChoice(AttributeTag.programmeGroupType, 0x08),
41  	programmeGroupTypeTopic(AttributeTag.programmeGroupType, 0x09),
42  	
43  	alternateSourceProtocolURL(AttributeTag.alternateSourceProtocol, 0x01),
44  	alternateSourceProtocolDAB(AttributeTag.alternateSourceProtocol, 0x02),
45  	alternateSourceProtocolDRN(AttributeTag.alternateSourceProtocol, 0x03),
46  	
47  	alternateSourceTypeIdentical(AttributeTag.alternateSourceType, 0x01),
48  	alternateSourceTypeMore(AttributeTag.alternateSourceType, 0x02),
49  	alternateSourceTypeLess(AttributeTag.alternateSourceType, 0x03),
50  	alternateSourceTypeSimilar(AttributeTag.alternateSourceType, 0x04),
51  	
52  	frequencyTypePrimary(AttributeTag.frequencyType, 0x01),
53  	frequencyTypeSecondary(AttributeTag.frequencyType, 0x02),
54  	
55  	serviceFormatAudio(AttributeTag.serviceFormat, 0x01),
56  	serviceFormatDLS(AttributeTag.serviceFormat, 0x02),
57  	serviceFormatMOTSlideshow(AttributeTag.serviceFormat, 0x03),
58  	serviceFormatMOTBWS(AttributeTag.serviceFormat, 0x04),
59  	serviceFormatTPEG(AttributeTag.serviceFormat, 0x05),
60  	serviceFormatDGPS(AttributeTag.serviceFormat, 0x06),
61  	serviceFormatProprietary(AttributeTag.serviceFormat, 0x07),
62  	
63  	serviceIDTypePrimary(AttributeTag.serviceIdType, 0x01),
64  	serviceIDTypeSecondary(AttributeTag.serviceIdType, 0x02),
65  	
66  	CATypeNone(AttributeTag.CAType, 0x01),
67  	CATypeUnspecified(AttributeTag.CAType, 0x02),
68  	
69  	programmeBroadcastOnair(AttributeTag.programmeBroadcast, 0x01),
70  	programmeBroadcastOffair(AttributeTag.programmeBroadcast, 0x02),
71  	
72  	programmeEventBroadcastOnair(AttributeTag.programmeEventBroadcast, 0x01),
73  	programmeEventBroadcastOffair(AttributeTag.programmeEventBroadcast, 0x02),
74  	
75  	programmeRecommendationNo(AttributeTag.programmeRecommendation, 0x01),
76  	programmeRecommendationYes(AttributeTag.programmeRecommendation, 0x02),
77  	
78  	programmeEventRecommendationNo(AttributeTag.programmeEventRecommendation, 0x01),
79  	programmeEventRecommendationYes(AttributeTag.programmeEventRecommendation, 0x02),
80  	
81  	multimediaTypeLogoUnrestricted(AttributeTag.multimediaType, 0x02),
82  	multimediaTypeLogoMonoSquare(AttributeTag.multimediaType, 0x03),
83  	multimediaTypeLogoColourSquare(AttributeTag.multimediaType, 0x04),
84  	multimediaTypeLogoMonoRectangle(AttributeTag.multimediaType, 0x05),
85  	multimediaTypeLogoColourRectangle(AttributeTag.multimediaType, 0x06),
86  	
87  	genreTypeMain(AttributeTag.genreType, 0x01),
88  	genreTypeSecondary(AttributeTag.genreType, 0x02),
89  	genreTypeOther(AttributeTag.genreType, 0x03);
90  	
91  	/***
92  	 * Parent attribute tag - this is needed to be able
93  	 * to parse the tag successfully.
94  	 */
95  	private AttributeTag parent;
96  	
97  	/***
98  	 * Enum tag value
99  	 */
100 	private byte value;
101 	
102 	private EnumType(AttributeTag parent, int value) {
103 		this.parent = parent;
104 		this.value = (byte)value;
105 	}
106 	
107 	/***
108 	 * @return Returns the tags parent attribute tag
109 	 */
110 	public AttributeTag getParent() {
111 		return parent;
112 	}
113 	
114 	/***
115 	 * @return Returns the tag value
116 	 */
117 	public int getValue() {
118 		return value & 0xFF;
119 	}
120 
121 	/***
122 	 * @see com.gcapmedia.dab.epg.binary.Encodable#getBytes()
123 	 */
124 	public byte[] getBytes() {
125 		BitBuilder bits = new BitBuilder(8);
126 		bits.put(0, value);
127 		return bits.toByteArray();
128 	}
129 
130 	/***
131 	 * @see com.gcapmedia.dab.epg.binary.Encodable#getLength()
132 	 */
133 	public int getLength() {
134 		return 1;
135 	}
136 	
137 	/***
138 	 * Parse an object from its byte array representation
139 	 * @param parent Tag parent
140 	 * @param bytes Byte array representation
141 	 */
142 	public static EnumType fromByte(AttributeTag parent, byte value) {
143 		EnumType result = null;
144 		for(EnumType tag : values()) {
145 			if(tag.parent == parent && tag.getValue() == value) {
146 				result = tag;
147 				break;
148 			}
149 		}
150 		if(result == null) {
151 			throw new IllegalArgumentException("EnumType for parent " + parent + " not found: " + value);
152 		}
153 		return result;
154 	}
155 }