HttpOverXmppResp.java

  1. /**
  2.  *
  3.  * Copyright 2014 Andriy Tsykholyas
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smackx.hoxt.packet;

  18. import org.jivesoftware.smack.util.Objects;

  19. /**
  20.  * Represents Resp IQ packet.
  21.  *
  22.  * @author Andriy Tsykholyas
  23.  * @see <a href="http://xmpp.org/extensions/xep-0332.html">XEP-0332: HTTP over XMPP transport</a>
  24.  */
  25. public final class HttpOverXmppResp extends AbstractHttpOverXmpp {

  26.     public static final String ELEMENT = "resp";

  27.     private HttpOverXmppResp(Builder builder) {
  28.         super(ELEMENT, builder);
  29.         this.statusCode = Objects.requireNonNull(builder.statusCode, "statusCode must not be null");
  30.         this.statusMessage = builder.statusMessage;
  31.     }

  32.     private final int statusCode;
  33.     private final String statusMessage;

  34.     @Override
  35.     protected IQChildElementXmlStringBuilder getIQHoxtChildElementBuilder(IQChildElementXmlStringBuilder builder) {
  36.         builder.attribute("version", getVersion());
  37.         builder.attribute("statusCode", statusCode);
  38.         builder.optAttribute("statusMessage", statusMessage);
  39.         builder.rightAngleBracket();
  40.         return builder;
  41.     }

  42.     /**
  43.      * Returns statusCode attribute.
  44.      *
  45.      * @return statusCode attribute
  46.      */
  47.     public int getStatusCode() {
  48.         return statusCode;
  49.     }

  50.     /**
  51.      * Returns statusMessage attribute.
  52.      *
  53.      * @return statusMessage attribute
  54.      */
  55.     public String getStatusMessage() {
  56.         return statusMessage;
  57.     }

  58.     public static Builder builder() {
  59.         return new Builder();
  60.     }

  61.     /**
  62.      * A configuration builder for HttpOverXmppReq. Use {@link HttpOverXmppResp#builder()} to obtain a new instance and
  63.      * {@link #build} to build the configuration.
  64.      */
  65.     public static final class Builder extends AbstractHttpOverXmpp.Builder<Builder, HttpOverXmppResp> {

  66.         private int statusCode = 200;
  67.         private String statusMessage = null;

  68.         private Builder() {
  69.         }

  70.         /**
  71.          * Sets statusCode attribute.
  72.          *
  73.          * @param statusCode statusCode attribute
  74.          *
  75.          * @return the builder
  76.          */
  77.         public Builder setStatusCode(int statusCode) {
  78.             this.statusCode = statusCode;
  79.             return this;
  80.         }

  81.         /**
  82.          * Sets statusMessage attribute.
  83.          *
  84.          * @param statusMessage statusMessage attribute
  85.          *
  86.          * @return the builder
  87.          */
  88.         public Builder setStatusMessage(String statusMessage) {
  89.             this.statusMessage = statusMessage;
  90.             return this;

  91.         }

  92.         @Override
  93.         public HttpOverXmppResp build() {
  94.             return new HttpOverXmppResp(this);
  95.         }

  96.         @Override
  97.         protected Builder getThis() {
  98.             return this;
  99.         }
  100.     }

  101. }