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.binding.staging;
17  
18  import org.fourthline.cling.model.ValidationException;
19  import org.fourthline.cling.model.meta.Action;
20  import org.fourthline.cling.model.meta.Device;
21  import org.fourthline.cling.model.meta.Service;
22  import org.fourthline.cling.model.meta.StateVariable;
23  import org.fourthline.cling.model.types.ServiceId;
24  import org.fourthline.cling.model.types.ServiceType;
25  
26  import java.net.URI;
27  import java.util.ArrayList;
28  import java.util.List;
29  
30  /**
31   * @author Christian Bauer
32   */
33  public class MutableService {
34  
35      public ServiceType serviceType;
36      public ServiceId serviceId;
37      public URI descriptorURI;
38      public URI controlURI;
39      public URI eventSubscriptionURI;
40  
41      public List<MutableAction> actions = new ArrayList<>();
42      public List<MutableStateVariable> stateVariables = new ArrayList<>();
43  
44      public Service build(Device prototype) throws ValidationException {
45          return prototype.newInstance(
46                  serviceType, serviceId,
47                  descriptorURI, controlURI, eventSubscriptionURI,
48                  createActions(),
49                  createStateVariables()
50          );
51      }
52  
53      public Action[] createActions() {
54          Action[] array = new Action[actions.size()];
55          int i = 0;
56          for (MutableAction action : actions) {
57              array[i++] = action.build();
58          }
59          return array;
60      }
61  
62      public StateVariable[] createStateVariables() {
63          StateVariable[] array = new StateVariable[stateVariables.size()];
64          int i = 0;
65          for (MutableStateVariable stateVariable : stateVariables) {
66              array[i++] = stateVariable.build();
67          }
68          return array;
69      }
70  
71  }