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