1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.support.model;
17
18 import org.fourthline.cling.model.types.InvalidValueException;
19 import org.seamless.util.MimeType;
20
21
22
23
24
25
26 public class ProtocolInfo {
27
28 public static final String WILDCARD = "*";
29
30 protected Protocol protocol = Protocol.ALL;
31 protected String network = WILDCARD;
32 protected String contentFormat = WILDCARD;
33 protected String additionalInfo = WILDCARD;
34
35 public ProtocolInfo(String s) throws InvalidValueException {
36 if (s == null) throw new NullPointerException();
37 s = s.trim();
38 String[] split = s.split(":");
39 if (split.length != 4) {
40 throw new InvalidValueException("Can't parse ProtocolInfo string: " + s);
41 }
42 this.protocol = Protocol.value(split[0]);
43 this.network = split[1];
44 this.contentFormat = split[2];
45 this.additionalInfo = split[3];
46 }
47
48 public ProtocolInfo(MimeType contentFormatMimeType) {
49 this.protocol = Protocol.HTTP_GET;
50 this.contentFormat = contentFormatMimeType.toString();
51 }
52
53 public ProtocolInfo(Protocol protocol, String network, String contentFormat, String additionalInfo) {
54 this.protocol = protocol;
55 this.network = network;
56 this.contentFormat = contentFormat;
57 this.additionalInfo = additionalInfo;
58 }
59
60 public Protocol getProtocol() {
61 return protocol;
62 }
63
64 public String getNetwork() {
65 return network;
66 }
67
68 public String getContentFormat() {
69 return contentFormat;
70 }
71
72 public MimeType getContentFormatMimeType() throws IllegalArgumentException {
73 return MimeType.valueOf(contentFormat);
74 }
75
76 public String getAdditionalInfo() {
77 return additionalInfo;
78 }
79
80 @Override
81 public boolean equals(Object o) {
82 if (this == o) return true;
83 if (o == null || getClass() != o.getClass()) return false;
84
85 ProtocolInfo that = (ProtocolInfo) o;
86
87 if (!additionalInfo.equals(that.additionalInfo)) return false;
88 if (!contentFormat.equals(that.contentFormat)) return false;
89 if (!network.equals(that.network)) return false;
90 if (protocol != that.protocol) return false;
91
92 return true;
93 }
94
95 @Override
96 public int hashCode() {
97 int result = protocol.hashCode();
98 result = 31 * result + network.hashCode();
99 result = 31 * result + contentFormat.hashCode();
100 result = 31 * result + additionalInfo.hashCode();
101 return result;
102 }
103
104 @Override
105 public String toString() {
106 return protocol.toString() + ":" +
107 network + ":" +
108 contentFormat + ":" +
109 additionalInfo;
110
111 }
112 }