1 /*------------------------------------------------------------------------------
  2 Name:      GetKey.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  * Wraps an XML key for a get() 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.get.html" target="others">the interface.get requirement</a>
 19  */
 20 public class GetKey
 21 {
 22    private final static String ME = "GetKey";
 23    private final QueryKeyData queryKeyData;
 24 
 25    /**
 26     * Create a key data holder to access message(s). 
 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     */
 31    public GetKey(Global glob, String query) {
 32       this.queryKeyData = new QueryKeyData(glob, query);
 33    }
 34 
 35    /**
 36     * Constructor for XPath query. 
 37     * @param queryString  The String with e.g. XPath syntax
 38     * @param queryType    The query syntax, e.g. Constants.XPATH
 39     * @param XmlBlasterException for invalid queryType
 40     */
 41    public GetKey(Global glob, String queryString, String queryType) throws XmlBlasterException {
 42       this.queryKeyData = new QueryKeyData(glob, queryString, queryType);
 43    }
 44 
 45    /**
 46     * Constructor for internal use. 
 47     * @param queryKeyData The struct holding the data
 48     */
 49    public GetKey(Global glob, QueryKeyData queryKeyData) {
 50       this.queryKeyData = queryKeyData;
 51    }
 52 
 53    public QueryKeyData getData() {
 54       return this.queryKeyData;
 55    }
 56 
 57    /**
 58     * Set the $lt;key oid="...">.
 59     * @param The unique key oid
 60     */
 61    public final void setOid(String oid) {
 62       this.queryKeyData.setOid(oid);
 63    }
 64 
 65    /**
 66     * Access the &lt;key oid="...">.
 67     * @return The unique key oid
 68     */
 69    public final String getOid() {
 70       return this.queryKeyData.getOid();
 71    }
 72 
 73    /**
 74     * Access the query type "XPATH" or "EXACT"
 75     * @return A queryType string or null
 76     */
 77    public String getQueryType() {
 78       return this.queryKeyData.getQueryType();
 79    }
 80 
 81    /**
 82     * Your XPath query string. 
 83     * @param str Your tags in ASCII XML syntax
 84     */
 85    public void setQueryString(String tags) {
 86       this.queryKeyData.setQueryString(tags);
 87    }
 88 
 89    public String getQueryString() {
 90       return this.queryKeyData.getQueryString();
 91    }
 92 
 93    /**
 94     * Give a hint to which cluster domain this Key belongs. 
 95     */
 96    public void setDomain(String domain) {
 97       this.queryKeyData.setDomain(domain);
 98    }
 99 
100    /**
101     * Access the domain setting
102     * @return A domain string or null
103     */
104    public String getDomain() {
105       return this.queryKeyData.getDomain();
106    }
107 
108    /**
109     * Converts the data in XML ASCII string.
110     * @return An XML ASCII string
111     */
112    public String toString() {
113       return this.queryKeyData.toString();
114    }
115 
116    /**
117     * Converts the data in XML ASCII string.
118     * @return An XML ASCII string
119     */
120    public String toXml() {
121       return this.queryKeyData.toXml();
122    }
123 
124    /**
125     * May be used to integrate your application tags.
126     * @param str Your tags
127     * @return The ASCII XML key containing the key tag and your tags
128     */
129    public String wrap(String str) {
130       this.queryKeyData.setQueryString(str);
131       return this.queryKeyData.toXml();
132    }
133 }


syntax highlighted by Code2HTML, v. 0.9.1