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  package example.localservice;
16  
17  import org.fourthline.cling.binding.annotations.*;
18  
19  /**
20   * Getting output values from a JavaBean
21   * <p>
22   * Here the action method does not return the output argument value directly,
23   * but a JavaBean instance is returned which offers a getter method to obtain
24   * the output argument value:
25   * </p>
26   * <a class="citation" href="javacode://this" style="include:INC1"/>
27   * <p>
28   * Cling will detect that you mapped a getter name in the output argument
29   * and that the action method is not <code>void</code>. It now expects that
30   * it will find the getter method on the returned JavaBean. If there are
31   * several output arguments, all of them have to be mapped to getter methods
32   * on the returned JavaBean.
33   * </p>
34   */
35  @UpnpService(
36          serviceId = @UpnpServiceId("SwitchPower"),
37          serviceType = @UpnpServiceType(value = "SwitchPower", version = 1)
38  )
39  public class SwitchPowerBeanReturn {
40  
41      @UpnpStateVariable(defaultValue = "0", sendEvents = false)
42      private boolean target = false;
43  
44      @UpnpStateVariable(defaultValue = "0")
45      private boolean status = false;
46  
47      @UpnpAction
48      public void setTarget(@UpnpInputArgument(name = "NewTargetValue")
49                            boolean newTargetValue) {
50          target = newTargetValue;
51          status = newTargetValue;
52          System.out.println("Switch is: " + status);
53      }
54  
55      @UpnpAction(out = @UpnpOutputArgument(name = "RetTargetValue"))
56      public boolean getTarget() {
57          return target;
58      }
59  
60      @UpnpAction(                                    // DOC:INC1
61              name = "GetStatus",
62              out = @UpnpOutputArgument(
63                      name = "ResultStatus",
64                      getterName = "getWrapped"
65              )
66      )
67      public StatusHolder getStatus() {
68          return new StatusHolder(status);
69      }
70  
71      public class StatusHolder {
72          boolean wrapped;
73  
74          public StatusHolder(boolean wrapped) {
75              this.wrapped = wrapped;
76          }
77  
78          public boolean getWrapped() {
79              return wrapped;
80          }
81      }                                               // DOC:INC1
82  
83  }