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 org.joda.time.Duration;
25  import org.joda.time.ReadableInstant;
26  
27  import com.gcapmedia.dab.epg.*;
28  
29  /***
30   * 
31   */
32  public class LocationDeconstructor implements Deconstructor<Location> {
33  
34  	/***
35  	 * @see com.gcapmedia.dab.epg.binary.Deconstructor#deconstruct(com.gcapmedia.dab.epg.binary.Element)
36  	 */
37  	public Location deconstruct(Element element) {
38  		
39  		Location location = new Location();
40  		
41  		// elements
42  		for(Element child : element.getChildren(ElementTag.bearer)) {
43  			if(!child.hasAttribute(AttributeTag.bearerId)) {
44  				throw new IllegalArgumentException("Bearer must have an id attribute");
45  			}
46  			Attribute idAttribute = child.getAttribute(AttributeTag.bearerId);
47  			ContentIdType idType = (ContentIdType)idAttribute.getValue();
48  			ContentId id = idType.getContentId();
49  			String trigger = null;
50  			if(child.hasAttribute(AttributeTag.bearerTrigger)) {
51  				Attribute triggerAttribute = child.getAttribute(AttributeTag.bearerTrigger);
52  				StringType triggerType = (StringType)triggerAttribute.getValue();
53  				trigger = triggerType.toString();
54  			}
55  			Bearer bearer = null;
56  			if(trigger != null) {
57  				bearer = new Bearer(id, trigger);
58  			} else {
59  				bearer = new Bearer(id);
60  			}
61  			location.addBearer(bearer);
62  		}
63  		if(!element.hasChildren(ElementTag.time) && !element.hasChildren(ElementTag.relativeTime)) {
64  			throw new IllegalArgumentException("Either time or relativeTime must be specified for this location");
65  		}
66  		if(element.hasChildren(ElementTag.time) && element.hasChildren(ElementTag.relativeTime)) {
67  			throw new IllegalArgumentException("Only one of time or relativeTime should be specified for this location");
68  		}
69  		if(element.hasChildren(ElementTag.time)) {
70  			for(Element child : element.getChildren(ElementTag.time)) {
71  				ReadableInstant billedTime = null;
72  				if(child.hasAttribute(AttributeTag.timeTime)) {
73  					Attribute timeAttribute = child.getAttribute(AttributeTag.timeTime);
74  					TimepointType type = (TimepointType)timeAttribute.getValue();
75  					billedTime = type.getTimepoint();
76  				}
77  				Duration billedDuration = null;
78  				if(child.hasAttribute(AttributeTag.timeDuration)) {
79  					Attribute timeAttribute = child.getAttribute(AttributeTag.timeDuration);
80  					DurationType type = (DurationType)timeAttribute.getValue();
81  					billedDuration = type.getDuration();
82  				}
83  				ReadableInstant actualTime = null;
84  				if(child.hasAttribute(AttributeTag.timeActualTime)) {
85  					Attribute timeAttribute = child.getAttribute(AttributeTag.timeActualTime);
86  					TimepointType type = (TimepointType)timeAttribute.getValue();
87  					actualTime = type.getTimepoint();
88  				}
89  				Duration actualDuration = null;
90  				if(child.hasAttribute(AttributeTag.timeActualDuration)) {
91  					Attribute timeAttribute = child.getAttribute(AttributeTag.timeActualDuration);
92  					DurationType type = (DurationType)timeAttribute.getValue();
93  					actualDuration = type.getDuration();
94  				}
95  				location.addTime(new Time(billedTime, billedDuration, actualTime, actualDuration));
96  			}
97  		}
98  		if(element.hasChildren(ElementTag.relativeTime)) {
99  			for(Element child : element.getChildren(ElementTag.relativeTime)) {
100 				Duration billedTime = null;
101 				if(child.hasAttribute(AttributeTag.timeTime)) {
102 					Attribute timeAttribute = child.getAttribute(AttributeTag.timeTime);
103 					DurationType type = (DurationType)timeAttribute.getValue();
104 					billedTime = type.getDuration();
105 				}
106 				Duration billedDuration = null;
107 				if(child.hasAttribute(AttributeTag.timeDuration)) {
108 					Attribute timeAttribute = child.getAttribute(AttributeTag.timeDuration);
109 					DurationType type = (DurationType)timeAttribute.getValue();
110 					billedDuration = type.getDuration();
111 				}
112 				Duration actualTime = null;
113 				if(child.hasAttribute(AttributeTag.timeActualTime)) {
114 					Attribute timeAttribute = child.getAttribute(AttributeTag.timeActualTime);
115 					DurationType type = (DurationType)timeAttribute.getValue();
116 					actualTime = type.getDuration();
117 				}
118 				Duration actualDuration = null;
119 				if(child.hasAttribute(AttributeTag.timeActualDuration)) {
120 					Attribute timeAttribute = child.getAttribute(AttributeTag.timeActualDuration);
121 					DurationType type = (DurationType)timeAttribute.getValue();
122 					actualDuration = type.getDuration();
123 				}
124 				location.addRelativeTime(new RelativeTime(billedTime, billedDuration, actualTime, actualDuration));
125 			}
126 		}
127 		if(element.hasChildren(ElementTag.relativeTime)) {
128 			
129 		}
130 		
131 		return location;
132 	}
133 
134 }