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.test.data;
17  
18  import org.fourthline.cling.model.meta.Action;
19  import org.fourthline.cling.model.meta.Service;
20  import org.fourthline.cling.model.meta.StateVariable;
21  import org.fourthline.cling.model.types.ServiceId;
22  import org.fourthline.cling.model.types.ServiceType;
23  
24  import java.lang.reflect.Constructor;
25  import java.net.URI;
26  
27  /**
28   * @author Christian Bauer
29   */
30  public abstract class SampleService {
31  
32      public abstract ServiceType getServiceType();
33      public abstract ServiceId getServiceId();
34      public abstract URI getDescriptorURI();
35      public abstract URI getControlURI();
36      public abstract URI getEventSubscriptionURI();
37      public abstract Action[] getActions();
38      public abstract StateVariable[] getStateVariables();
39  
40      public <S extends Service> S newInstanceLocal(Constructor<S> ctor) {
41          try {
42              return ctor.newInstance(
43                      getServiceType(), getServiceId(),
44                      getActions(), getStateVariables()
45              );
46          } catch (Exception ex) {
47              throw new RuntimeException(ex);
48          }
49      }
50  
51      public <S extends Service> S newInstanceRemote(Constructor<S> ctor) {
52          try {
53              return ctor.newInstance(
54                      getServiceType(), getServiceId(),
55                      getDescriptorURI(), getControlURI(), getEventSubscriptionURI(),
56                      getActions(), getStateVariables()
57              );
58          } catch (Exception ex) {
59              throw new RuntimeException(ex);
60          }
61      }
62  
63  }