1 /*------------------------------------------------------------------------------
  2 Name:      SubscribeReturnQos.java
  3 Project:   xmlBlaster.org
  4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
  5 ------------------------------------------------------------------------------*/
  6 package org.xmlBlaster.client.qos;
  7 
  8 import java.util.Properties;
  9 
 10 import org.xmlBlaster.util.Global;
 11 import org.xmlBlaster.util.XmlBlasterException;
 12 import org.xmlBlaster.util.qos.StatusQosData;
 13 import org.xmlBlaster.util.def.MethodName;
 14 
 15 /**
 16  * Handling the returned QoS (quality of service) of a subscribe() call.
 17  * <p />
 18  * If you are a Java client and use the I_XmlBlasterAccess interface
 19  * you get this object as the subscribe() return value.
 20  * <p />
 21  * Example:
 22  * <pre>
 23  *   &lt;qos>
 24  *     &lt;state id='OK' info='QUEUED[bilbo]'/>
 25  *     &lt;subscribe id='_subId:1/>
 26  *  &lt;/qos>
 27  * </pre>
 28  * @see org.xmlBlaster.test.classtest.qos.StatusQosFactoryTest
 29  * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/interface.subscribe.html" target="others">the interface.subscribe requirement</a>
 30  */
 31 public final class SubscribeReturnQos
 32 {
 33    private final StatusQosData statusQosData;
 34    private final boolean isFakedReturn;
 35 
 36    /**
 37     * Constructor which parses XML string.
 38     * Use this for real returns from a server (-> isFakedReturn=false).
 39     */
 40    public SubscribeReturnQos(Global glob, String xmlQos) throws XmlBlasterException {
 41       this(glob, xmlQos, false);
 42    }
 43 
 44    /**
 45     * Constructor which parses XML string.
 46     * @param isFakedReturn true if the return value is faked from the client (on missing server connection)
 47     */
 48    public SubscribeReturnQos(Global glob, String xmlQos, boolean isFakedReturn) throws XmlBlasterException {
 49       this.isFakedReturn = isFakedReturn;
 50       this.statusQosData = glob.getStatusQosFactory().readObject(xmlQos);
 51       this.statusQosData.setMethod(MethodName.SUBSCRIBE);
 52    }
 53 
 54    /**
 55     * Constructor which reuses a StatusQosData object.
 56     */
 57    public SubscribeReturnQos(Global glob, StatusQosData statusQosData) {
 58       this(glob, statusQosData, false);
 59    }
 60 
 61    /**
 62     * Constructor which reuses a StatusQosData object.
 63     * @param isFakedReturn true if the return value is faked from the client (on missing server connection)
 64     */
 65    public SubscribeReturnQos(Global glob, StatusQosData statusQosData, boolean isFakedReturn) {
 66       this.isFakedReturn = isFakedReturn;
 67       this.statusQosData = statusQosData;
 68       this.statusQosData.setMethod(MethodName.SUBSCRIBE);
 69    }
 70 
 71    /**
 72     * Access the raw data object, usually you shouldn't do it.
 73     * @return The raw data object
 74     */
 75    public StatusQosData getData() {
 76       return statusQosData;
 77    }
 78 
 79    /**
 80     * Check if the subscription is queued on client side. 
 81     * <p>
 82     * This happens if the connection is polling.
 83     * </p>
 84     * <p>
 85     * The getStateInfo() is set to "QUEUED..." in such a case
 86     * </p>
 87     * @return true if the subscribe return value is faked from the client library (on missing server connection)
 88     */
 89    public boolean isFakedReturn() {
 90       return this.isFakedReturn;
 91    }
 92 
 93    /**
 94     * Access the state of message.
 95     * @return OK (Other values are not yet supported)
 96     */
 97    public final String getState() {
 98       return this.statusQosData.getState();
 99    }
100 
101    /**
102     * Additional structured information about a state.
103     * @return "QUEUED" or "QUEUED[bilbo]"
104     * @see org.xmlBlaster.util.def.Constants
105     */
106    public final String getStateInfo() {
107       return this.statusQosData.getStateInfo();
108    }
109 
110    /**
111     * Get the identifier (unique handle) for this subscription.
112     */
113    public final String getSubscriptionId() {
114       return this.statusQosData.getSubscriptionId();
115    }
116 
117    /**
118     * @see #toXml(String)
119     */
120    public final String toXml() {
121       return toXml((String)null);
122    }
123 
124    /**
125     * Dump state of this object into a XML ASCII string.
126     * @param extraOffset indenting of tags for nice output
127     * @return The XML representation
128     */
129    public final String toXml(String extraOffset) {
130       return this.statusQosData.toXml(extraOffset, (Properties)null);
131    }
132 
133    public final String toString() {
134       return toXml(null);
135    }
136 }


syntax highlighted by Code2HTML, v. 0.9.1