package geniusweb.references; import java.net.URI; import java.net.URISyntaxException; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; /** * A URI reference to create a new instance of a protocol on a party server. * There is currently no real protocol server, instead the protocol is created * locally on the party server and used only there. Refer to the PartyServer for * the available protocols. */ public class ProtocolRef implements Reference { @JsonValue // serializes nicely but requires custom deserializer. private URI protocol; @JsonCreator // special: we need URI so no @JsonProperty public ProtocolRef(String uri) { if (uri == null) { throw new IllegalArgumentException("uri=null"); } try { this.protocol = new URI(uri); } catch (URISyntaxException e) { throw new IllegalArgumentException("Illegal string for URI", e); } } public ProtocolRef(URI uri) { if (uri == null) { throw new IllegalArgumentException("uri=null"); } this.protocol = uri; } @Override public URI getURI() { return protocol; } @Override public String toString() { return "ProtocolRef[" + protocol + "]"; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((protocol == null) ? 0 : protocol.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; ProtocolRef other = (ProtocolRef) obj; if (protocol == null) { if (other.protocol != null) return false; } else if (!protocol.equals(other.protocol)) return false; return true; } }