2020-08-16 15:14:19 +02:00
|
|
|
package org.jivesoftware.smackx.ikey.element;
|
|
|
|
|
|
|
|
import org.jivesoftware.smack.packet.NamedElement;
|
|
|
|
import org.jivesoftware.smack.packet.XmlEnvironment;
|
2020-09-11 14:41:48 +02:00
|
|
|
import org.jivesoftware.smack.util.EqualsUtil;
|
|
|
|
import org.jivesoftware.smack.util.HashCode;
|
2020-08-28 14:33:53 +02:00
|
|
|
import org.jivesoftware.smack.util.Objects;
|
2020-08-16 15:14:19 +02:00
|
|
|
import org.jivesoftware.smack.util.StringUtils;
|
|
|
|
import org.jivesoftware.smack.util.XmlStringBuilder;
|
|
|
|
|
2020-08-28 14:33:53 +02:00
|
|
|
import java.net.URI;
|
|
|
|
|
2020-08-16 15:14:19 +02:00
|
|
|
public class SubordinateElement implements NamedElement {
|
|
|
|
|
|
|
|
public static final String ELEMENT = "sub";
|
|
|
|
public static final String ATTR_SUB_URI = "uri";
|
2020-08-28 14:33:53 +02:00
|
|
|
public static final String ATTR_SUB_FINGERPRINT = "fpr";
|
2020-08-16 15:14:19 +02:00
|
|
|
|
2020-08-28 14:33:53 +02:00
|
|
|
private final URI subUri;
|
2020-08-16 15:14:19 +02:00
|
|
|
private final String subFingerprint;
|
|
|
|
|
2020-08-28 14:33:53 +02:00
|
|
|
public SubordinateElement(URI subKeyItemUri, String subKeyFingerprint) {
|
|
|
|
this.subUri = Objects.requireNonNull(subKeyItemUri, "uri MUST NOT be null nor empty.");
|
|
|
|
this.subFingerprint = StringUtils.requireNotNullNorEmpty(subKeyFingerprint, "fpr MUST NOT be null nor empty.");
|
2020-08-16 15:14:19 +02:00
|
|
|
}
|
|
|
|
|
2020-08-28 14:33:53 +02:00
|
|
|
public URI getUri() {
|
2020-08-16 15:14:19 +02:00
|
|
|
return subUri;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getFingerprint() {
|
|
|
|
return subFingerprint;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getElementName() {
|
|
|
|
return ELEMENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
|
2020-09-25 13:10:02 +02:00
|
|
|
return new XmlStringBuilder(this)
|
2020-08-28 14:33:53 +02:00
|
|
|
.attribute(ATTR_SUB_URI, getUri().toString())
|
2020-08-16 15:14:19 +02:00
|
|
|
.attribute(ATTR_SUB_FINGERPRINT, getFingerprint())
|
|
|
|
.closeEmptyElement();
|
|
|
|
}
|
2020-09-11 14:41:48 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
return HashCode.builder()
|
|
|
|
.append(getElementName())
|
|
|
|
.append(getFingerprint())
|
|
|
|
.append(getUri())
|
|
|
|
.build();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object other) {
|
|
|
|
return EqualsUtil.equals(this, other, (e, o) -> e
|
|
|
|
.append(getElementName(), o.getElementName())
|
|
|
|
.append(getFingerprint(), o.getFingerprint())
|
|
|
|
.append(getUri(), o.getUri()));
|
|
|
|
}
|
2020-08-16 15:14:19 +02:00
|
|
|
}
|