1 /*------------------------------------------------------------------------------
  2 Name:      UnSubscribeKey.java
  3 Project:   xmlBlaster.org
  4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
  5 ------------------------------------------------------------------------------*/
  6 package org.xmlBlaster.client.key;
  7 
  8 import org.xmlBlaster.util.Global;
  9 import org.xmlBlaster.util.key.QueryKeyData;
 10 import org.xmlBlaster.util.XmlBlasterException;
 11 
 12 /**
 13  * Wrap a XML key for an unSubscribe() invocation. 
 14  * <p>
 15  * See QueryKeySaxFactory for a syntax description of the allowed xml structure
 16  * </p>
 17  * @see org.xmlBlaster.util.key.QueryKeySaxFactory
 18  * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/interface.unSubscribe.html" target="others">the interface.unSubscribe requirement</a>
 19  */
 20 public class UnSubscribeKey
 21 {
 22    private final static String ME = "UnSubscribeKey";
 23    private final QueryKeyData queryKeyData;
 24 
 25    /**
 26     * UnSubscribe to a well known message oid/subscriptionId or url. 
 27     * @param query The query string
 28     *        For example a topic oid like "Hello" or "oid:Hello"
 29     *        or a query like "xpath://key", "domain:CLUSTER"
 30     *        or an explicit "subscriptionId:__subId:heron-34560459046"
 31     */
 32    public UnSubscribeKey(Global glob, String query) {
 33       this.queryKeyData = new QueryKeyData(glob, query);
 34    }
 35 
 36    /**
 37     * Constructor with query parameters. 
 38     * @param queryString  The String with e.g. XPath syntax
 39     * @param queryType    The query syntax, e.g. Constants.XPATH
 40     * @param XmlBlasterException for invalid queryType
 41     */
 42    public UnSubscribeKey(Global glob, String queryString, String queryType) throws XmlBlasterException {
 43       this.queryKeyData = new QueryKeyData(glob, queryString, queryType);
 44    }
 45 
 46    /**
 47     * Constructor for internal use. 
 48     * @param queryKeyData The struct holding the data
 49     */
 50    public UnSubscribeKey(Global glob, QueryKeyData queryKeyData) {
 51       this.queryKeyData = queryKeyData;
 52    }
 53 
 54    public QueryKeyData getData() {
 55       return this.queryKeyData;
 56    }
 57 
 58    /**
 59     * Set the $lt;key oid="...">.
 60     * @param The unique key oid
 61     */
 62    public final void setOid(String oid) {
 63       this.queryKeyData.setOid(oid);
 64    }
 65 
 66    /**
 67     * Access the &lt;key oid="...">.
 68     * @return The unique key oid
 69     */
 70    public final String getOid() {
 71       return this.queryKeyData.getOid();
 72    }
 73 
 74    /**
 75     * Access the query type "XPATH" or "EXACT"
 76     * @return A queryType string or null
 77     */
 78    public String getQueryType() {
 79       return this.queryKeyData.getQueryType();
 80    }
 81 
 82    /**
 83     * Your XPath query string. 
 84     * @param str Your tags in ASCII XML syntax
 85     */
 86    public void setQueryString(String tags) {
 87       this.queryKeyData.setQueryString(tags);
 88    }
 89 
 90    public String getQueryString() {
 91       return this.queryKeyData.getQueryString();
 92    }
 93 
 94    /**
 95     * Give a hint to which cluster domain this Key belongs.
 96     */
 97    public void setDomain(String domain) {
 98       this.queryKeyData.setDomain(domain);
 99    }
100 
101    /**
102     * Access the domain setting
103     * @return A domain string or null
104     */
105    public String getDomain() {
106       return this.queryKeyData.getDomain();
107    }
108 
109    /**
110     * Converts the data in XML ASCII string.
111     * @return An XML ASCII string
112     */
113    public String toString() {
114       return this.queryKeyData.toString();
115    }
116 
117    /**
118     * Converts the data in XML ASCII string.
119     * @return An XML ASCII string
120     */
121    public String toXml() {
122       return this.queryKeyData.toXml();
123    }
124 
125    /**
126     * May be used to integrate your application tags.
127     * @param str Your tags
128     * @return The ASCII XML key containing the key tag and your tags
129     */
130    public String wrap(String str) {
131       this.queryKeyData.setQueryString(str);
132       return this.queryKeyData.toXml();
133    }
134 }


syntax highlighted by Code2HTML, v. 0.9.1