source: references/src/main/java/geniusweb/references/ProtocolRef.java@ 52

Last change on this file since 52 was 52, checked in by ruud, 14 months ago

Fixed small issues in domaineditor.

File size: 1.7 KB
Line 
1package geniusweb.references;
2
3import java.net.URI;
4import java.net.URISyntaxException;
5
6import com.fasterxml.jackson.annotation.JsonCreator;
7import 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 */
15public 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}
Note: See TracBrowser for help on using the repository browser.