1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.model.meta;
17
18 import org.fourthline.cling.model.ValidationError;
19 import org.fourthline.cling.model.ValidationException;
20 import org.fourthline.cling.model.types.ServiceId;
21 import org.fourthline.cling.model.types.ServiceType;
22
23 import java.net.URI;
24 import java.util.ArrayList;
25 import java.util.List;
26
27
28
29
30
31
32
33
34
35
36 public class RemoteService extends Service<RemoteDevice, RemoteService> {
37
38 final private URI descriptorURI;
39 final private URI controlURI;
40 final private URI eventSubscriptionURI;
41
42 public RemoteService(ServiceType serviceType, ServiceId serviceId,
43 URI descriptorURI, URI controlURI, URI eventSubscriptionURI) throws ValidationException {
44 this(serviceType, serviceId, descriptorURI, controlURI, eventSubscriptionURI, null, null);
45 }
46
47 public RemoteService(ServiceType serviceType, ServiceId serviceId,
48 URI descriptorURI, URI controlURI, URI eventSubscriptionURI,
49 Action<RemoteService>[] actions, StateVariable<RemoteService>[] stateVariables) throws ValidationException {
50 super(serviceType, serviceId, actions, stateVariables);
51
52 this.descriptorURI = descriptorURI;
53 this.controlURI = controlURI;
54 this.eventSubscriptionURI = eventSubscriptionURI;
55
56 List<ValidationError> errors = validateThis();
57 if (errors.size() > 0) {
58 throw new ValidationException("Validation of device graph failed, call getErrors() on exception", errors);
59 }
60 }
61
62 @Override
63 public Action getQueryStateVariableAction() {
64 return new QueryStateVariableAction(this);
65 }
66
67 public URI getDescriptorURI() {
68 return descriptorURI;
69 }
70
71 public URI getControlURI() {
72 return controlURI;
73 }
74
75 public URI getEventSubscriptionURI() {
76 return eventSubscriptionURI;
77 }
78
79 public List<ValidationError> validateThis() {
80 List<ValidationError> errors = new ArrayList<>();
81
82 if (getDescriptorURI() == null) {
83 errors.add(new ValidationError(
84 getClass(),
85 "descriptorURI",
86 "Descriptor location (SCPDURL) is required"
87 ));
88 }
89
90 if (getControlURI() == null) {
91 errors.add(new ValidationError(
92 getClass(),
93 "controlURI",
94 "Control URL is required"
95 ));
96 }
97
98 if (getEventSubscriptionURI() == null) {
99 errors.add(new ValidationError(
100 getClass(),
101 "eventSubscriptionURI",
102 "Event subscription URL is required"
103 ));
104 }
105
106 return errors;
107 }
108
109 @Override
110 public String toString() {
111 return "(" + getClass().getSimpleName() + ") Descriptor: " + getDescriptorURI();
112 }
113
114 }