1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.model;
17
18 import org.fourthline.cling.model.types.ServiceId;
19 import org.fourthline.cling.model.types.UDN;
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 public class ServiceReference {
37
38 public static final String DELIMITER = "/";
39
40 final private UDN udn;
41 final private ServiceId serviceId;
42
43 public ServiceReference(String s) {
44 String[] split = s.split("/");
45 if (split.length == 2) {
46 this.udn = UDN.valueOf(split[0]);
47 this.serviceId = ServiceId.valueOf(split[1]);
48 } else {
49 this.udn = null;
50 this.serviceId = null;
51 }
52 }
53
54 public ServiceReference(UDN udn, ServiceId serviceId) {
55 this.udn = udn;
56 this.serviceId = serviceId;
57 }
58
59 public UDN getUdn() {
60 return udn;
61 }
62
63 public ServiceId getServiceId() {
64 return serviceId;
65 }
66
67 @Override
68 public boolean equals(Object o) {
69 if (this == o) return true;
70 if (o == null || getClass() != o.getClass()) return false;
71
72 ServiceReference that = (ServiceReference) o;
73
74 if (!serviceId.equals(that.serviceId)) return false;
75 if (!udn.equals(that.udn)) return false;
76
77 return true;
78 }
79
80 @Override
81 public int hashCode() {
82 int result = udn.hashCode();
83 result = 31 * result + serviceId.hashCode();
84 return result;
85 }
86
87 @Override
88 public String toString() {
89 return udn == null || serviceId == null ? "" : udn.toString() + DELIMITER + serviceId.toString();
90 }
91
92 }