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  import com.gcapmedia.dab.epg.Genre;
25  
26  /***
27   * 
28   */
29  public class GenreDeconstructor implements Deconstructor<Genre> {
30  
31  	/***
32  	 * @see com.gcapmedia.dab.epg.binary.Deconstructor#deconstruct(com.gcapmedia.dab.epg.binary.Element)
33  	 */
34  	public Genre deconstruct(Element element) {
35  		
36  		// attributes
37  		if(!element.hasAttribute(AttributeTag.genreHref)) {
38  			throw new IllegalArgumentException("Genre must has an HREF attribute");
39  		}
40  		GenreType genreType = (GenreType)element.getAttribute(AttributeTag.genreHref).getValue();
41  		Genre genre = genreType.getGenre();
42  
43  		if(element.hasAttribute(AttributeTag.genreType)) {
44  			Attribute attribute = element.getAttribute(AttributeTag.genreType);
45  			EnumType type = (EnumType)attribute.getValue();
46  			if(type == EnumType.genreTypeMain) {
47  				genre.setType(Genre.Type.MAIN);
48  			} else if(type == EnumType.genreTypeSecondary) {
49  				genre.setType(Genre.Type.SECONDARY);
50  			} else if(type == EnumType.genreTypeOther) {
51  				genre.setType(Genre.Type.OTHER);
52  			}
53  		}
54  		
55  		return genre;
56  	}
57  
58  }