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.Device;
19  import org.fourthline.cling.model.meta.DeviceDetails;
20  import org.fourthline.cling.model.meta.DeviceIdentity;
21  import org.fourthline.cling.model.meta.Icon;
22  import org.fourthline.cling.model.meta.Service;
23  import org.fourthline.cling.model.profile.DeviceDetailsProvider;
24  import org.fourthline.cling.model.types.DeviceType;
25  
26  import java.lang.reflect.Constructor;
27  
28  /**
29   * @author Christian Bauer
30   */
31  public abstract class SampleDevice {
32  
33      public DeviceIdentity identity;
34      public Service service;
35      public Device embeddedDevice;
36  
37      protected SampleDevice(DeviceIdentity identity, Service service, Device embeddedDevice) {
38          this.identity = identity;
39          this.service = service;
40          this.embeddedDevice = embeddedDevice;
41      }
42  
43      public DeviceIdentity getIdentity() {
44          return identity;
45      }
46  
47      public Service getService() {
48          return service;
49      }
50  
51      public Device getEmbeddedDevice() {
52          return embeddedDevice;
53      }
54  
55      public abstract DeviceType getDeviceType();
56      public abstract DeviceDetails getDeviceDetails();
57      public abstract DeviceDetailsProvider getDeviceDetailsProvider();
58      public abstract Icon[] getIcons();
59  
60      public <D extends Device> D newInstance(Constructor<D> deviceConstructor) {
61          return newInstance(deviceConstructor, false);
62      }
63  
64      public <D extends Device> D newInstance(Constructor<D> deviceConstructor, boolean useProvider) {
65          try {
66              if (useProvider) {
67                  return deviceConstructor.newInstance(
68                          getIdentity(), getDeviceType(), getDeviceDetailsProvider(),
69                          getIcons(), getService(), getEmbeddedDevice()
70                  );
71              }
72              return deviceConstructor.newInstance(
73                      getIdentity(), getDeviceType(), getDeviceDetails(),
74                      getIcons(), getService(), getEmbeddedDevice()
75              );
76          } catch (Exception ex) {
77              throw new RuntimeException(ex);
78          }
79      }
80  }