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.control;
17  
18  import org.fourthline.cling.model.Constants;
19  import org.fourthline.cling.model.meta.Action;
20  import org.fourthline.cling.model.meta.QueryStateVariableAction;
21  import org.fourthline.cling.model.message.StreamResponseMessage;
22  import org.fourthline.cling.model.message.UpnpResponse;
23  import org.fourthline.cling.model.message.header.ContentTypeHeader;
24  import org.fourthline.cling.model.message.header.EXTHeader;
25  import org.fourthline.cling.model.message.header.ServerHeader;
26  import org.fourthline.cling.model.message.header.UpnpHeader;
27  
28  /**
29   * @author Christian Bauer
30   */
31  public class OutgoingActionResponseMessage extends StreamResponseMessage implements ActionResponseMessage {
32  
33      private String actionNamespace;
34  
35      public OutgoingActionResponseMessage(Action action) {
36          this(UpnpResponse.Status.OK, action);
37      }
38  
39      public OutgoingActionResponseMessage(UpnpResponse.Status status) {
40          this(status, null);
41      }
42  
43      public OutgoingActionResponseMessage(UpnpResponse.Status status, Action action) {
44          super(new UpnpResponse(status));
45  
46          if (action != null) {
47              if (action instanceof QueryStateVariableAction) {
48                  this.actionNamespace = Constants.NS_UPNP_CONTROL_10;
49              } else {
50                  this.actionNamespace = action.getService().getServiceType().toString();
51              }
52          }
53  
54          addHeaders();
55      }
56  
57      protected void addHeaders() {
58          getHeaders().add(
59                  UpnpHeader.Type.CONTENT_TYPE,
60                  new ContentTypeHeader(ContentTypeHeader.DEFAULT_CONTENT_TYPE_UTF8)
61          );
62          getHeaders().add(
63                  UpnpHeader.Type.SERVER,
64                  new ServerHeader()
65          );
66          getHeaders().add(
67                  UpnpHeader.Type.EXT,
68                  new EXTHeader()
69          );
70      }
71  
72      public String getActionNamespace() {
73          return actionNamespace;
74      }
75  
76  
77  }