View Javadoc
1   /*
2    * Copyright (C) 2013 4th Line GmbH, Switzerland
3    *
4    * The contents of this file are subject to the terms of either the GNU
5    * Lesser General Public License Version 2 or later ("LGPL") or the
6    * Common Development and Distribution License Version 1 or later
7    * ("CDDL") (collectively, the "License"). You may not use this file
8    * except in compliance with the License. See LICENSE.txt for more
9    * information.
10   *
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14   */
15  
16  package org.fourthline.cling.model.message.header;
17  
18  /**
19   * @author Christian Bauer
20   */
21  public class MXHeader extends UpnpHeader<Integer> {
22  
23      // 3 second seems like a good default to spread search responses (UDA says 120?!? wtf)
24      public static final Integer DEFAULT_VALUE = 3;
25  
26      /**
27       * Defaults to 3 seconds.
28       */
29      public MXHeader() {
30          setValue(DEFAULT_VALUE);
31      }
32  
33      public MXHeader(Integer delayInSeconds) {
34          setValue(delayInSeconds);
35      }
36  
37      public void setString(String s) throws InvalidHeaderException {
38          Integer value;
39          try {
40              value = Integer.parseInt(s);
41          } catch (Exception ex) {
42              throw new InvalidHeaderException("Can't parse MX seconds integer from: " + s);
43          }
44  
45          // UDA 1.0, section 1.2.3: "If the MX header specifies a value greater than 120, the device
46          // should assume that it contained the value 120 or less."
47          if (value < 0 || value > 120) {
48              setValue(DEFAULT_VALUE);
49          } else {
50              setValue(value);
51          }
52      }
53  
54      public String getString() {
55          return getValue().toString();
56      }
57  }