package com.ausregistry.jtoolkit2.se.fee; import javax.xml.xpath.XPathExpressionException; import java.math.BigDecimal; import com.ausregistry.jtoolkit2.se.ExtendedObjectType; import com.ausregistry.jtoolkit2.se.ResponseExtension; import com.ausregistry.jtoolkit2.xml.XMLDocument; /** * <p>Extension for the EPP Domain Create response, representing the Fee * extension.</p> * * <p>Use this to acknowledge the price associated with this domain name as part of an EPP Domain Create * command compliant with RFC5730 and RFC5731. The "currency" and "registrationFee" * values supplied, should match the fees that are set for the domain name for the requested period. * The response expected from a server should be handled by a Domain Create Response.</p> * * @see com.ausregistry.jtoolkit2.se.DomainCreateCommand * @see com.ausregistry.jtoolkit2.se.DomainCreateResponse * @see <a href="https://tools.ietf.org/html/draft-brown-epp-fees-03">Domain Name Fee Extension * Mapping for the Extensible Provisioning Protocol (EPP)</a> */ public final class DomainCreateFeeResponseExtension extends ResponseExtension { private static final long serialVersionUID = -6007874008986690757L; private static final String FEE_PREFIX = ExtendedObjectType.FEE.getName(); private static final String FEE_XPATH_PREFIX = ResponseExtension.EXTENSION_EXPR + "/" + FEE_PREFIX + ":RESPONSE_TYPE/" + FEE_PREFIX; private static final String CURRENCY_EXPR = FEE_XPATH_PREFIX + ":currency/text()"; private static final String FEE_EXPR = FEE_XPATH_PREFIX + ":fee/text()"; private String responseType; private boolean initialised = false; private String currency; private BigDecimal registrationFee; public DomainCreateFeeResponseExtension(String responseType) { this.responseType = responseType; } @Override public void fromXML(XMLDocument xmlDoc) throws XPathExpressionException { currency = xmlDoc.getNodeValue(replaceResponseType(CURRENCY_EXPR, responseType)); String feeNodeValue = xmlDoc.getNodeValue(replaceResponseType(FEE_EXPR, responseType)); if (feeNodeValue != null) { registrationFee = new BigDecimal(feeNodeValue); } initialised = (currency != null && registrationFee != null); } @Override public boolean isInitialised() { return initialised; } public String getCurrency() { return currency; } public BigDecimal getRegistrationFee() { return registrationFee; } }