dynect: replace usage of UnsignedInteger with int and fixed serialized form of rdata classes

This commit is contained in:
adriancole 2013-03-11 14:55:10 -07:00
parent 12fd9bf581
commit aeee6ceb31
14 changed files with 192 additions and 220 deletions

View File

@ -26,12 +26,8 @@ import javax.inject.Singleton;
import org.jclouds.dynect.v3.domain.SessionCredentials; import org.jclouds.dynect.v3.domain.SessionCredentials;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.primitives.UnsignedInteger;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer; import com.google.gson.JsonSerializer;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
@ -51,7 +47,6 @@ public class DynECTParserModule extends AbstractModule {
public Map<Type, Object> provideCustomAdapterBindings() { public Map<Type, Object> provideCustomAdapterBindings() {
return new ImmutableMap.Builder<Type, Object>() return new ImmutableMap.Builder<Type, Object>()
.put(SessionCredentials.class, new SessionCredentialsTypeAdapter()) .put(SessionCredentials.class, new SessionCredentialsTypeAdapter())
.put(UnsignedInteger.class, new UnsignedIntegerAdapter())
.build(); .build();
} }
@ -64,11 +59,4 @@ public class DynECTParserModule extends AbstractModule {
return metadataObject; return metadataObject;
} }
} }
private static class UnsignedIntegerAdapter implements JsonDeserializer<UnsignedInteger> {
public UnsignedInteger deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context)
throws JsonParseException {
return UnsignedInteger.fromIntBits(jsonElement.getAsBigInteger().intValue());
}
}
} }

View File

@ -20,12 +20,12 @@ package org.jclouds.dynect.v3.domain;
import static com.google.common.base.Objects.equal; import static com.google.common.base.Objects.equal;
import static com.google.common.base.Objects.toStringHelper; import static com.google.common.base.Objects.toStringHelper;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map; import java.util.Map;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.primitives.UnsignedInteger;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -34,13 +34,14 @@ public class CreateRecord<D extends Map<String, Object>> {
private final String fqdn; private final String fqdn;
private final String type; private final String type;
private final UnsignedInteger ttl; private final int ttl;
private final D rdata; private final D rdata;
private CreateRecord(String fqdn, String type, UnsignedInteger ttl, D rdata) { private CreateRecord(String fqdn, String type, int ttl, D rdata) {
this.fqdn = checkNotNull(fqdn, "fqdn"); this.fqdn = checkNotNull(fqdn, "fqdn");
this.type = checkNotNull(type, "type of %s", fqdn); this.type = checkNotNull(type, "type of %s", fqdn);
this.ttl = checkNotNull(ttl, "ttl of %s", fqdn); checkArgument(ttl >= 0, "ttl of %s must be unsigned", fqdn);
this.ttl = ttl;
this.rdata = checkNotNull(rdata, "rdata of %s", fqdn); this.rdata = checkNotNull(rdata, "rdata of %s", fqdn);
} }
@ -63,7 +64,7 @@ public class CreateRecord<D extends Map<String, Object>> {
* *
* @see Record#getTTL() * @see Record#getTTL()
*/ */
public UnsignedInteger getTTL() { public int getTTL() {
return ttl; return ttl;
} }
@ -106,7 +107,8 @@ public class CreateRecord<D extends Map<String, Object>> {
public static class Builder<D extends Map<String, Object>> { public static class Builder<D extends Map<String, Object>> {
protected String fqdn; protected String fqdn;
protected String type; protected String type;
protected UnsignedInteger ttl = UnsignedInteger.ZERO; // default of zone is implied when ttl is set to zero
protected int ttl = 0;
protected D rdata; protected D rdata;
/** /**
@ -128,18 +130,11 @@ public class CreateRecord<D extends Map<String, Object>> {
/** /**
* @see CreateRecord#getTTL() * @see CreateRecord#getTTL()
*/ */
public Builder<D> ttl(UnsignedInteger ttl) { public Builder<D> ttl(int ttl) {
this.ttl = ttl; this.ttl = ttl;
return this; return this;
} }
/**
* @see CreateRecord#getTTL()
*/
public Builder<D> ttl(int ttl) {
return ttl(UnsignedInteger.fromIntBits(ttl));
}
/** /**
* @see CreateRecord#getRData() * @see CreateRecord#getRData()
*/ */

View File

@ -18,6 +18,7 @@
*/ */
package org.jclouds.dynect.v3.domain; package org.jclouds.dynect.v3.domain;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties; import java.beans.ConstructorProperties;
@ -26,28 +27,28 @@ import java.util.Map;
import javax.inject.Named; import javax.inject.Named;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.common.primitives.UnsignedInteger;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
public class Record<D extends Map<String, Object>> extends RecordId { public class Record<D extends Map<String, Object>> extends RecordId {
private final UnsignedInteger ttl; private final int ttl;
@Named("rdata") @Named("rdata")
private final D rdata; private final D rdata;
@ConstructorProperties({ "zone", "fqdn", "record_type", "record_id", "ttl", "rdata" }) @ConstructorProperties({ "zone", "fqdn", "record_type", "record_id", "ttl", "rdata" })
protected Record(String zone, String fqdn, String type, long id, UnsignedInteger ttl, D rdata) { protected Record(String zone, String fqdn, String type, long id, int ttl, D rdata) {
super(zone, fqdn, type, id); super(zone, fqdn, type, id);
this.ttl = checkNotNull(ttl, "ttl of %s", id); checkArgument(ttl >= 0, "ttl of %s must be unsigned", fqdn);
this.ttl = ttl;
this.rdata = checkNotNull(rdata, "rdata of %s", id); this.rdata = checkNotNull(rdata, "rdata of %s", id);
} }
/** /**
* The current ttl of the record or zero if default for the zone * The current ttl of the record or zero if default for the zone
*/ */
public UnsignedInteger getTTL() { public int getTTL() {
return ttl; return ttl;
} }
@ -74,24 +75,17 @@ public class Record<D extends Map<String, Object>> extends RecordId {
public abstract static class Builder<D extends Map<String, Object>, B extends Builder<D, B>> extends RecordId.Builder<B> { public abstract static class Builder<D extends Map<String, Object>, B extends Builder<D, B>> extends RecordId.Builder<B> {
protected UnsignedInteger ttl; protected int ttl = -1;
protected D rdata; protected D rdata;
/** /**
* @see Record#getTTL() * @see Record#getTTL()
*/ */
public B ttl(UnsignedInteger ttl) { public B ttl(int ttl) {
this.ttl = ttl; this.ttl = ttl;
return self(); return self();
} }
/**
* @see Record#getTTL()
*/
public B ttl(int ttl) {
return ttl(UnsignedInteger.fromIntBits(ttl));
}
/** /**
* @see Record#getRData() * @see Record#getRData()
*/ */

View File

@ -28,7 +28,6 @@ import org.jclouds.dynect.v3.domain.Zone.SerialStyle;
import org.jclouds.dynect.v3.domain.rdata.SOAData; import org.jclouds.dynect.v3.domain.rdata.SOAData;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.common.primitives.UnsignedInteger;
/** /**
* Start of Authority per RFC 1035 * Start of Authority per RFC 1035
@ -41,7 +40,7 @@ public final class SOARecord extends Record<SOAData> {
private final SerialStyle serialStyle; private final SerialStyle serialStyle;
@ConstructorProperties({ "zone", "fqdn", "record_type", "record_id", "ttl", "rdata", "serial_style" }) @ConstructorProperties({ "zone", "fqdn", "record_type", "record_id", "ttl", "rdata", "serial_style" })
private SOARecord(String zone, String fqdn, String type, long id, UnsignedInteger ttl, SOAData rdata, SerialStyle serialStyle) { private SOARecord(String zone, String fqdn, String type, long id, int ttl, SOAData rdata, SerialStyle serialStyle) {
super(zone, fqdn, type, id, ttl, rdata); super(zone, fqdn, type, id, ttl, rdata);
this.serialStyle = checkNotNull(serialStyle, "serialStyle of %s", id); this.serialStyle = checkNotNull(serialStyle, "serialStyle of %s", id);
} }

View File

@ -40,22 +40,25 @@ import com.google.common.collect.ImmutableMap;
* @see <aaaa href="http://www.ietf.org/rfc/rfc3596.txt">RFC 3596</aaaa> * @see <aaaa href="http://www.ietf.org/rfc/rfc3596.txt">RFC 3596</aaaa>
*/ */
public class AAAAData extends ForwardingMap<String, Object> { public class AAAAData extends ForwardingMap<String, Object> {
private final ImmutableMap<String, Object> delegate; private final String address;
@ConstructorProperties("address") @ConstructorProperties("address")
private AAAAData(String address) { private AAAAData(String address) {
this.delegate = ImmutableMap.<String, Object> of("address", checkNotNull(address, "address")); this.address = checkNotNull(address, "address");
} this.delegate = ImmutableMap.<String, Object> of("address", address);
protected Map<String, Object> delegate() {
return delegate;
} }
/** /**
* a 128 bit IPv6 address * a 128 bit IPv6 address
*/ */
public String getAddress() { public String getAddress() {
return get("address").toString(); return address;
}
private final transient ImmutableMap<String, Object> delegate;
protected Map<String, Object> delegate() {
return delegate;
} }
public static AAAAData aaaa(String address) { public static AAAAData aaaa(String address) {

View File

@ -40,22 +40,26 @@ import com.google.common.collect.ImmutableMap;
* @see <a href="http://www.ietf.org/rfc/rfc1035.txt">RFC 1035</a> * @see <a href="http://www.ietf.org/rfc/rfc1035.txt">RFC 1035</a>
*/ */
public class AData extends ForwardingMap<String, Object> { public class AData extends ForwardingMap<String, Object> {
private final ImmutableMap<String, Object> delegate;
private final String address;
@ConstructorProperties("address") @ConstructorProperties("address")
private AData(String address) { private AData(String address) {
this.address = checkNotNull(address, "address");
this.delegate = ImmutableMap.<String, Object> of("address", checkNotNull(address, "address")); this.delegate = ImmutableMap.<String, Object> of("address", checkNotNull(address, "address"));
} }
protected Map<String, Object> delegate() {
return delegate;
}
/** /**
* a 32-bit internet address * a 32-bit internet address
*/ */
public String getAddress() { public String getAddress() {
return get("address").toString(); return address;
}
private final transient ImmutableMap<String, Object> delegate;
protected Map<String, Object> delegate() {
return delegate;
} }
public static AData a(String address) { public static AData a(String address) {

View File

@ -40,15 +40,13 @@ import com.google.common.collect.ImmutableMap;
* @see <a href="http://www.ietf.org/rfc/rfc1035.txt">RFC 1035</a> * @see <a href="http://www.ietf.org/rfc/rfc1035.txt">RFC 1035</a>
*/ */
public class CNAMEData extends ForwardingMap<String, Object> { public class CNAMEData extends ForwardingMap<String, Object> {
private final ImmutableMap<String, Object> delegate;
private final String cname;
@ConstructorProperties("cname") @ConstructorProperties("cname")
private CNAMEData(String cname) { private CNAMEData(String cname) {
this.delegate = ImmutableMap.<String, Object> of("cname", checkNotNull(cname, "cname")); this.cname = checkNotNull(cname, "cname");
} this.delegate = ImmutableMap.<String, Object> of("cname", cname);
protected Map<String, Object> delegate() {
return delegate;
} }
/** /**
@ -56,7 +54,13 @@ public class CNAMEData extends ForwardingMap<String, Object> {
* The owner name is an alias. * The owner name is an alias.
*/ */
public String getCname() { public String getCname() {
return get("cname").toString(); return cname;
}
private final transient ImmutableMap<String, Object> delegate;
protected Map<String, Object> delegate() {
return delegate;
} }
public static CNAMEData cname(String cname) { public static CNAMEData cname(String cname) {

View File

@ -18,6 +18,7 @@
*/ */
package org.jclouds.dynect.v3.domain.rdata; package org.jclouds.dynect.v3.domain.rdata;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties; import java.beans.ConstructorProperties;
@ -25,7 +26,6 @@ import java.util.Map;
import com.google.common.collect.ForwardingMap; import com.google.common.collect.ForwardingMap;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.primitives.UnsignedInteger;
/** /**
* Corresponds to the binary representation of the {@code MX} (Mail Exchange) * Corresponds to the binary representation of the {@code MX} (Mail Exchange)
@ -43,24 +43,24 @@ import com.google.common.primitives.UnsignedInteger;
*/ */
public class MXData extends ForwardingMap<String, Object> { public class MXData extends ForwardingMap<String, Object> {
private final int preference;
private final String exchange;
@ConstructorProperties({ "preference", "exchange" }) @ConstructorProperties({ "preference", "exchange" })
private MXData(UnsignedInteger preference, String exchange) { private MXData(int preference, String exchange) {
this.delegate = ImmutableMap.<String, Object> builder().put("preference", checkNotNull(preference, "preference")) checkArgument(preference >= 0, "preference of %s must be unsigned", exchange);
.put("exchange", checkNotNull(exchange, "exchange")).build(); this.preference = preference;
} this.exchange = checkNotNull(exchange, "exchange");
this.delegate = ImmutableMap.<String, Object> builder().put("preference", preference).put("exchange", exchange)
private final ImmutableMap<String, Object> delegate; .build();
protected Map<String, Object> delegate() {
return delegate;
} }
/** /**
* specifies the preference given to this RR among others at the same owner. * specifies the preference given to this RR among others at the same owner.
* Lower values are preferred. * Lower values are preferred.
*/ */
public UnsignedInteger getPreference() { public int getPreference() {
return UnsignedInteger.class.cast(get("preference")); return preference;
} }
/** /**
@ -68,7 +68,13 @@ public class MXData extends ForwardingMap<String, Object> {
* the owner name. * the owner name.
*/ */
public String getExchange() { public String getExchange() {
return String.class.cast(get("exchange")); return exchange;
}
private final transient ImmutableMap<String, Object> delegate;
protected Map<String, Object> delegate() {
return delegate;
} }
public static MXData mx(int preference, String exchange) { public static MXData mx(int preference, String exchange) {
@ -84,20 +90,13 @@ public class MXData extends ForwardingMap<String, Object> {
} }
public final static class Builder { public final static class Builder {
private UnsignedInteger preference; private int preference = -1;
private String exchange; private String exchange;
/** /**
* @see MXData#getPreference() * @see MXData#getPreference()
*/ */
public MXData.Builder preference(int preference) { public MXData.Builder preference(int preference) {
return preference(UnsignedInteger.fromIntBits(preference));
}
/**
* @see MXData#getPreference()
*/
public MXData.Builder preference(UnsignedInteger preference) {
this.preference = preference; this.preference = preference;
return this; return this;
} }

View File

@ -40,15 +40,13 @@ import com.google.common.collect.ImmutableMap;
* @see <a href="http://www.ietf.org/rfc/rfc1035.txt">RFC 1035</a> * @see <a href="http://www.ietf.org/rfc/rfc1035.txt">RFC 1035</a>
*/ */
public class NSData extends ForwardingMap<String, Object> { public class NSData extends ForwardingMap<String, Object> {
private final ImmutableMap<String, Object> delegate;
private final String nsdname;
@ConstructorProperties("nsdname") @ConstructorProperties("nsdname")
private NSData(String nsdname) { private NSData(String nsdname) {
this.delegate = ImmutableMap.<String, Object> of("nsdname", checkNotNull(nsdname, "nsdname")); this.nsdname = checkNotNull(nsdname, "nsdname");
} this.delegate = ImmutableMap.<String, Object> of("nsdname", nsdname);
protected Map<String, Object> delegate() {
return delegate;
} }
/** /**
@ -56,7 +54,13 @@ public class NSData extends ForwardingMap<String, Object> {
* specified class and domain. * specified class and domain.
*/ */
public String getNsdname() { public String getNsdname() {
return get("nsdname").toString(); return nsdname;
}
private final transient ImmutableMap<String, Object> delegate;
protected Map<String, Object> delegate() {
return delegate;
} }
public static NSData ns(String nsdname) { public static NSData ns(String nsdname) {

View File

@ -40,22 +40,26 @@ import com.google.common.collect.ImmutableMap;
* @see <a href="http://www.ietf.org/rfc/rfc1035.txt">RFC 1035</a> * @see <a href="http://www.ietf.org/rfc/rfc1035.txt">RFC 1035</a>
*/ */
public class PTRData extends ForwardingMap<String, Object> { public class PTRData extends ForwardingMap<String, Object> {
private final ImmutableMap<String, Object> delegate;
private final String ptrdname;
@ConstructorProperties("ptrdname") @ConstructorProperties("ptrdname")
private PTRData(String ptrdname) { private PTRData(String ptrdname) {
this.delegate = ImmutableMap.<String, Object> of("ptrdname", checkNotNull(ptrdname, "ptrdname")); this.ptrdname = checkNotNull(ptrdname, "ptrdname");
} this.delegate = ImmutableMap.<String, Object> of("ptrdname", ptrdname);
protected Map<String, Object> delegate() {
return delegate;
} }
/** /**
* domain-name which points to some location in the domain name space. * domain-name which points to some location in the domain name space.
*/ */
public String getPtrdname() { public String getPtrdname() {
return get("ptrdname").toString(); return ptrdname;
}
private final transient ImmutableMap<String, Object> delegate;
protected Map<String, Object> delegate() {
return delegate;
} }
public static PTRData ptr(String ptrdname) { public static PTRData ptr(String ptrdname) {

View File

@ -18,6 +18,7 @@
*/ */
package org.jclouds.dynect.v3.domain.rdata; package org.jclouds.dynect.v3.domain.rdata;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties; import java.beans.ConstructorProperties;
@ -25,7 +26,6 @@ import java.util.Map;
import com.google.common.collect.ForwardingMap; import com.google.common.collect.ForwardingMap;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.primitives.UnsignedInteger;
/** /**
* Corresponds to the binary representation of the {@code SOA} (Start of Authority) RData * Corresponds to the binary representation of the {@code SOA} (Start of Authority) RData
@ -46,10 +46,29 @@ import com.google.common.primitives.UnsignedInteger;
* @see <a href="http://www.ietf.org/rfc/rfc1035.txt">RFC 1035</a> * @see <a href="http://www.ietf.org/rfc/rfc1035.txt">RFC 1035</a>
*/ */
public class SOAData extends ForwardingMap<String, Object> { public class SOAData extends ForwardingMap<String, Object> {
private final String mname;
private final String rname;
private final int serial;
private final int refresh;
private final int retry;
private final int expire;
private final int minimum;
@ConstructorProperties({ "mname", "rname", "serial", "refresh", "retry", "expire", "minimum" }) @ConstructorProperties({ "mname", "rname", "serial", "refresh", "retry", "expire", "minimum" })
private SOAData(String mname, String rname, UnsignedInteger serial, UnsignedInteger refresh, UnsignedInteger retry, private SOAData(String mname, String rname, int serial, int refresh, int retry,
UnsignedInteger expire, UnsignedInteger minimum) { int expire, int minimum) {
this.mname = checkNotNull(mname, "mname");
this.rname = checkNotNull(rname, "rname of %s", mname);
checkArgument(serial >= 0, "serial of %s must be unsigned", mname);
this.serial = serial;
checkArgument(refresh >= 0, "refresh of %s must be unsigned", mname);
this.refresh = refresh;
checkArgument(retry >= 0, "retry of %s must be unsigned", mname);
this.retry = retry;
checkArgument(expire >= 0, "expire of %s must be unsigned", mname);
this.expire = expire;
checkArgument(minimum >= 0, "minimum of %s must be unsigned", mname);
this.minimum = minimum;
this.delegate = ImmutableMap.<String, Object> builder() this.delegate = ImmutableMap.<String, Object> builder()
.put("mname", checkNotNull(mname, "mname")) .put("mname", checkNotNull(mname, "mname"))
.put("rname", checkNotNull(rname, "rname of %s", mname)) .put("rname", checkNotNull(rname, "rname of %s", mname))
@ -60,18 +79,12 @@ public class SOAData extends ForwardingMap<String, Object> {
.put("minimum", checkNotNull(minimum, "minimum of %s", mname)).build(); .put("minimum", checkNotNull(minimum, "minimum of %s", mname)).build();
} }
private final ImmutableMap<String, Object> delegate;
protected Map<String, Object> delegate() {
return delegate;
}
/** /**
* domain-name of the name server that was the original or primary source of * domain-name of the name server that was the original or primary source of
* data for this zone * data for this zone
*/ */
public String getMname() { public String getMname() {
return String.class.cast(get("mname")); return mname;
} }
/** /**
@ -79,43 +92,49 @@ public class SOAData extends ForwardingMap<String, Object> {
* zone. * zone.
*/ */
public String getRname() { public String getRname() {
return String.class.cast(get("rname")); return rname;
} }
/** /**
* version number of the original copy of the zone. * version number of the original copy of the zone.
*/ */
public UnsignedInteger getSerial() { public int getSerial() {
return UnsignedInteger.class.cast(get("serial")); return serial;
} }
/** /**
* time interval before the zone should be refreshed * time interval before the zone should be refreshed
*/ */
public UnsignedInteger getRefresh() { public int getRefresh() {
return UnsignedInteger.class.cast(get("refresh")); return refresh;
} }
/** /**
* time interval that should elapse before a failed refresh should be retried * time interval that should elapse before a failed refresh should be retried
*/ */
public UnsignedInteger getRetry() { public int getRetry() {
return UnsignedInteger.class.cast(get("retry")); return retry;
} }
/** /**
* time value that specifies the upper limit on the time interval that can * time value that specifies the upper limit on the time interval that can
* elapse before the zone is no longer authoritative. * elapse before the zone is no longer authoritative.
*/ */
public UnsignedInteger getExpire() { public int getExpire() {
return UnsignedInteger.class.cast(get("expire")); return expire;
} }
/** /**
* minimum TTL field that should be exported with any RR from this zone. * minimum TTL field that should be exported with any RR from this zone.
*/ */
public UnsignedInteger getMinimum() { public int getMinimum() {
return UnsignedInteger.class.cast(get("minimum")); return minimum;
}
private final transient ImmutableMap<String, Object> delegate;
protected Map<String, Object> delegate() {
return delegate;
} }
public static SOAData.Builder builder() { public static SOAData.Builder builder() {
@ -129,11 +148,11 @@ public class SOAData extends ForwardingMap<String, Object> {
public final static class Builder { public final static class Builder {
private String mname; private String mname;
private String rname; private String rname;
private UnsignedInteger serial; private int serial = -1;
private UnsignedInteger refresh; private int refresh = -1;
private UnsignedInteger retry; private int retry = -1;
private UnsignedInteger expire; private int expire = -1;
private UnsignedInteger minimum; private int minimum = -1;
/** /**
* @see SOAData#getMname() * @see SOAData#getMname()
@ -151,26 +170,11 @@ public class SOAData extends ForwardingMap<String, Object> {
return this; return this;
} }
/**
* @see SOAData#getSerial()
*/
public SOAData.Builder serial(UnsignedInteger serial) {
this.serial = serial;
return this;
}
/** /**
* @see SOAData#getSerial() * @see SOAData#getSerial()
*/ */
public SOAData.Builder serial(int serial) { public SOAData.Builder serial(int serial) {
return serial(UnsignedInteger.fromIntBits(serial)); this.serial = serial;
}
/**
* @see SOAData#getRefresh()
*/
public SOAData.Builder refresh(UnsignedInteger refresh) {
this.refresh = refresh;
return this; return this;
} }
@ -178,14 +182,7 @@ public class SOAData extends ForwardingMap<String, Object> {
* @see SOAData#getRefresh() * @see SOAData#getRefresh()
*/ */
public SOAData.Builder refresh(int refresh) { public SOAData.Builder refresh(int refresh) {
return refresh(UnsignedInteger.fromIntBits(refresh)); this.refresh = refresh;
}
/**
* @see SOAData#getRetry()
*/
public SOAData.Builder retry(UnsignedInteger retry) {
this.retry = retry;
return this; return this;
} }
@ -193,14 +190,7 @@ public class SOAData extends ForwardingMap<String, Object> {
* @see SOAData#getRetry() * @see SOAData#getRetry()
*/ */
public SOAData.Builder retry(int retry) { public SOAData.Builder retry(int retry) {
return retry(UnsignedInteger.fromIntBits(retry)); this.retry = retry;
}
/**
* @see SOAData#getExpire()
*/
public SOAData.Builder expire(UnsignedInteger expire) {
this.expire = expire;
return this; return this;
} }
@ -208,14 +198,7 @@ public class SOAData extends ForwardingMap<String, Object> {
* @see SOAData#getExpire() * @see SOAData#getExpire()
*/ */
public SOAData.Builder expire(int expire) { public SOAData.Builder expire(int expire) {
return expire(UnsignedInteger.fromIntBits(expire)); this.expire = expire;
}
/**
* @see SOAData#getMinimum()
*/
public SOAData.Builder minimum(UnsignedInteger minimum) {
this.minimum = minimum;
return this; return this;
} }
@ -223,7 +206,8 @@ public class SOAData extends ForwardingMap<String, Object> {
* @see SOAData#getMinimum() * @see SOAData#getMinimum()
*/ */
public SOAData.Builder minimum(int minimum) { public SOAData.Builder minimum(int minimum) {
return minimum(UnsignedInteger.fromIntBits(minimum)); this.minimum = minimum;
return this;
} }
public SOAData build() { public SOAData build() {

View File

@ -18,6 +18,7 @@
*/ */
package org.jclouds.dynect.v3.domain.rdata; package org.jclouds.dynect.v3.domain.rdata;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties; import java.beans.ConstructorProperties;
@ -25,7 +26,6 @@ import java.util.Map;
import com.google.common.collect.ForwardingMap; import com.google.common.collect.ForwardingMap;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.primitives.UnsignedInteger;
/** /**
* Corresponds to the binary representation of the {@code SRV} (Service) RData * Corresponds to the binary representation of the {@code SRV} (Service) RData
@ -43,31 +43,36 @@ import com.google.common.primitives.UnsignedInteger;
* @see <a href="http://www.ietf.org/rfc/rfc2782.txt">RFC 2782</a> * @see <a href="http://www.ietf.org/rfc/rfc2782.txt">RFC 2782</a>
*/ */
public class SRVData extends ForwardingMap<String, Object> { public class SRVData extends ForwardingMap<String, Object> {
private final int priority;
private final int weight;
private final int port;
private final String target;
@ConstructorProperties({ "priority", "weight", "port", "target" }) @ConstructorProperties({ "priority", "weight", "port", "target" })
private SRVData(UnsignedInteger priority, UnsignedInteger weight, UnsignedInteger port, String target) { private SRVData(int priority, int weight, int port, String target) {
checkArgument(checkNotNull(priority, "priority of %s", target).intValue() <= 0xFFFF, "priority must be 0-65535");
this.priority = priority;
checkArgument(checkNotNull(weight, "weight of %s", target).intValue() <= 0xFFFF, "weight must be 0-65535");
this.weight = weight;
checkArgument(checkNotNull(port, "port of %s", target).intValue() <= 0xFFFF, "port must be 0-65535");
this.port = port;
this.target = checkNotNull(target, "target");
this.delegate = ImmutableMap.<String, Object> builder() this.delegate = ImmutableMap.<String, Object> builder()
.put("priority", checkNotNull(priority, "priority of %s", target)) .put("priority", priority)
.put("weight", checkNotNull(weight, "weight of %s", target)) .put("weight", weight)
.put("port", checkNotNull(port, "port of %s", target)) .put("port", weight)
.put("target", checkNotNull(target, "target")) .put("target", weight)
.build(); .build();
} }
private final ImmutableMap<String, Object> delegate;
protected Map<String, Object> delegate() {
return delegate;
}
/** /**
* The priority of this target host. A client MUST attempt to contact the * The priority of this target host. A client MUST attempt to contact the
* target host with the lowest-numbered priority it can reach; target hosts * target host with the lowest-numbered priority it can reach; target hosts
* with the same priority SHOULD be tried in an order defined by the weight * with the same priority SHOULD be tried in an order defined by the weight
* field. * field.
*/ */
public UnsignedInteger getPriority() { public int getPriority() {
return UnsignedInteger.class.cast(get("priority")); return priority;
} }
/** /**
@ -75,15 +80,15 @@ public class SRVData extends ForwardingMap<String, Object> {
* priority. Larger weights SHOULD be given a proportionately higher * priority. Larger weights SHOULD be given a proportionately higher
* probability of being selected. * probability of being selected.
*/ */
public UnsignedInteger getWeight() { public int getWeight() {
return UnsignedInteger.class.cast(get("weight")); return weight;
} }
/** /**
* The port on this target host of this service. * The port on this target host of this service.
*/ */
public UnsignedInteger getPort() { public int getPort() {
return UnsignedInteger.class.cast(get("port")); return port;
} }
/** /**
@ -91,7 +96,13 @@ public class SRVData extends ForwardingMap<String, Object> {
* records for this name, the name MUST NOT be an alias. * records for this name, the name MUST NOT be an alias.
*/ */
public String getTarget() { public String getTarget() {
return String.class.cast(get("target")); return target;
}
private final transient ImmutableMap<String, Object> delegate;
protected Map<String, Object> delegate() {
return delegate;
} }
public static SRVData.Builder builder() { public static SRVData.Builder builder() {
@ -103,31 +114,16 @@ public class SRVData extends ForwardingMap<String, Object> {
} }
public final static class Builder { public final static class Builder {
private UnsignedInteger priority; private int priority = -1;
private UnsignedInteger weight; private int weight = -1;
private UnsignedInteger port; private int port = -1;
private String target; private String target;
/**
* @see SRVData#getPriority()
*/
public SRVData.Builder priority(UnsignedInteger priority) {
this.priority = priority;
return this;
}
/** /**
* @see SRVData#getPriority() * @see SRVData#getPriority()
*/ */
public SRVData.Builder priority(int priority) { public SRVData.Builder priority(int priority) {
return priority(UnsignedInteger.fromIntBits(priority)); this.priority = priority;
}
/**
* @see SRVData#getWeight()
*/
public SRVData.Builder weight(UnsignedInteger weight) {
this.weight = weight;
return this; return this;
} }
@ -135,14 +131,7 @@ public class SRVData extends ForwardingMap<String, Object> {
* @see SRVData#getWeight() * @see SRVData#getWeight()
*/ */
public SRVData.Builder weight(int weight) { public SRVData.Builder weight(int weight) {
return weight(UnsignedInteger.fromIntBits(weight)); this.weight = weight;
}
/**
* @see SRVData#getPort()
*/
public SRVData.Builder port(UnsignedInteger port) {
this.port = port;
return this; return this;
} }
@ -150,7 +139,8 @@ public class SRVData extends ForwardingMap<String, Object> {
* @see SRVData#getPort() * @see SRVData#getPort()
*/ */
public SRVData.Builder port(int port) { public SRVData.Builder port(int port) {
return port(UnsignedInteger.fromIntBits(port)); this.port = port;
return this;
} }
/** /**

View File

@ -40,22 +40,26 @@ import com.google.common.collect.ImmutableMap;
* @see <a href="http://www.ietf.org/rfc/rfc1035.txt">RFC 1035</a> * @see <a href="http://www.ietf.org/rfc/rfc1035.txt">RFC 1035</a>
*/ */
public class TXTData extends ForwardingMap<String, Object> { public class TXTData extends ForwardingMap<String, Object> {
private final ImmutableMap<String, Object> delegate;
private final String txtdata;
@ConstructorProperties("txtdata") @ConstructorProperties("txtdata")
private TXTData(String txtdata) { private TXTData(String txtdata) {
this.delegate = ImmutableMap.<String, Object> of("txtdata", checkNotNull(txtdata, "txtdata")); this.txtdata = checkNotNull(txtdata, "txtdata");
} this.delegate = ImmutableMap.<String, Object> of("txtdata", txtdata);
protected Map<String, Object> delegate() {
return delegate;
} }
/** /**
* One or more character-strings. * One or more character-strings.
*/ */
public String getTxtdata() { public String getTxtdata() {
return get("txtdata").toString(); return txtdata;
}
private final transient ImmutableMap<String, Object> delegate;
protected Map<String, Object> delegate() {
return delegate;
} }
public static TXTData txt(String txtdata) { public static TXTData txt(String txtdata) {

View File

@ -128,7 +128,7 @@ public interface RecordAsyncApi {
.put("fqdn", in.getFQDN()).build()); .put("fqdn", in.getFQDN()).build());
return (R) request.toBuilder() return (R) request.toBuilder()
.endpoint(path) .endpoint(path)
.payload(json.toJson(ImmutableMap.of("rdata", ImmutableMap.copyOf(in.getRData()), "ttl", in.getTTL().intValue()))).build(); .payload(json.toJson(ImmutableMap.of("rdata", in.getRData(), "ttl", in.getTTL()))).build();
} }
} }