1 | package geniusweb.references;
|
---|
2 |
|
---|
3 | import java.net.URI;
|
---|
4 | import java.net.URISyntaxException;
|
---|
5 |
|
---|
6 | import com.fasterxml.jackson.annotation.JsonCreator;
|
---|
7 | import com.fasterxml.jackson.annotation.JsonValue;
|
---|
8 |
|
---|
9 | /**
|
---|
10 | * A URI reference to create a new instance of a protocol on a party server.
|
---|
11 | * There is currently no real protocol server, instead the protocol is created
|
---|
12 | * locally on the party server and used only there. Refer to the PartyServer for
|
---|
13 | * the available protocols.
|
---|
14 | */
|
---|
15 | public class ProtocolRef implements Reference {
|
---|
16 | @JsonValue // serializes nicely but requires custom deserializer.
|
---|
17 | private URI protocol;
|
---|
18 |
|
---|
19 | @JsonCreator // special: we need URI so no @JsonProperty
|
---|
20 | public ProtocolRef(String uri) {
|
---|
21 | if (uri == null) {
|
---|
22 | throw new IllegalArgumentException("uri=null");
|
---|
23 | }
|
---|
24 | try {
|
---|
25 | this.protocol = new URI(uri);
|
---|
26 | } catch (URISyntaxException e) {
|
---|
27 | throw new IllegalArgumentException("Illegal string for URI", e);
|
---|
28 | }
|
---|
29 | }
|
---|
30 |
|
---|
31 | public ProtocolRef(URI uri) {
|
---|
32 | if (uri == null) {
|
---|
33 | throw new IllegalArgumentException("uri=null");
|
---|
34 | }
|
---|
35 | this.protocol = uri;
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Override
|
---|
39 | public URI getURI() {
|
---|
40 | return protocol;
|
---|
41 | }
|
---|
42 |
|
---|
43 | @Override
|
---|
44 | public String toString() {
|
---|
45 | return "ProtocolRef[" + protocol + "]";
|
---|
46 | }
|
---|
47 |
|
---|
48 | @Override
|
---|
49 | public int hashCode() {
|
---|
50 | final int prime = 31;
|
---|
51 | int result = 1;
|
---|
52 | result = prime * result
|
---|
53 | + ((protocol == null) ? 0 : protocol.hashCode());
|
---|
54 | return result;
|
---|
55 | }
|
---|
56 |
|
---|
57 | @Override
|
---|
58 | public boolean equals(Object obj) {
|
---|
59 | if (this == obj)
|
---|
60 | return true;
|
---|
61 | if (obj == null)
|
---|
62 | return false;
|
---|
63 | if (getClass() != obj.getClass())
|
---|
64 | return false;
|
---|
65 | ProtocolRef other = (ProtocolRef) obj;
|
---|
66 | if (protocol == null) {
|
---|
67 | if (other.protocol != null)
|
---|
68 | return false;
|
---|
69 | } else if (!protocol.equals(other.protocol))
|
---|
70 | return false;
|
---|
71 | return true;
|
---|
72 | }
|
---|
73 | }
|
---|