1 /*------------------------------------------------------------------------------
  2 Name:      GetQos.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.qos.QueryQosData;
 12 import org.xmlBlaster.util.qos.ClientProperty;
 13 import org.xmlBlaster.util.qos.QuerySpecQos;
 14 import org.xmlBlaster.engine.mime.Query;
 15 import org.xmlBlaster.util.qos.AccessFilterQos;
 16 import org.xmlBlaster.util.qos.HistoryQos;
 17 import org.xmlBlaster.util.def.MethodName;
 18 
 19 /**
 20  * This class encapsulates the QoS (quality of service) of a get() request. 
 21  * <p />
 22  * A full specified <b>get</b> qos could look like this:<br />
 23  * <pre>
 24  *&lt;qos>
 25  *   &lt;meta>false&lt;/meta>       &lt;!-- Don't return me the xmlKey meta data -->
 26  *   &lt;content>false&lt;/content> &lt;!-- Don't return me the content data (notify only) -->
 27  *   &lt;filter type='myPlugin' version='1.0'>a!=100&lt;/filter>
 28  *                                  &lt;!-- MIME access filters plugin -->
 29  *   &lt;history numEntries='20'/>  &lt;!-- Default is to deliver the current entry (numEntries='1'), '-1' deliver all -->
 30  *&lt;/qos>
 31  * </pre>
 32  * <p />
 33  * see xmlBlaster/src/dtd/XmlQoS.xml
 34  * @see org.xmlBlaster.util.qos.QueryQosData
 35  * @see org.xmlBlaster.util.qos.QueryQosSaxFactory
 36  * @see <a href="http://www.xmlblaster.org/xmlBlaster/doc/requirements/interface.get.html">get interface</a>
 37  * @see <a href="http://www.xmlblaster.org/xmlBlaster/doc/requirements/mime.plugin.accessfilter.html">MIME access filter requirement</a>
 38  */
 39 public final class GetQos
 40 {
 41    private String ME = "GetQos";
 42    private final Global glob;
 43    private final QueryQosData queryQosData;
 44 
 45    /**
 46     * Constructor for default qos (quality of service).
 47     */
 48    public GetQos(Global glob) {
 49       this(glob, null);
 50    }
 51 
 52    /**
 53     * Constructor for internal use. 
 54     * @param queryQosData The struct holding the data
 55     */
 56    public GetQos(Global glob, QueryQosData queryQosData) {
 57       this.glob = (glob==null) ? Global.instance() : glob;
 58       this.queryQosData = (queryQosData==null) ? new QueryQosData(this.glob, this.glob.getQueryQosFactory(), MethodName.GET) : queryQosData;
 59       this.queryQosData.setMethod(MethodName.GET);
 60    }
 61 
 62    /**
 63     * Access the wrapped data holder
 64     */
 65    public QueryQosData getData() {
 66       return this.queryQosData;
 67    }
 68 
 69    /*
 70     * Shall key meta information be delivered?
 71    public void setWantMeta(String meta) {
 72       this.queryQosData.setWantMeta(meta);
 73    }
 74     */
 75 
 76    /**
 77     * If false, the update contains not the content (it is a notify of change only)
 78     * <p />
 79     * This may be useful if you have huge contents, and you only want to be informed about a change
 80     * TODO: Implement in server!!!
 81     */
 82    public void setWantContent(boolean content) {
 83       this.queryQosData.setWantContent(content);
 84    }
 85 
 86    /**
 87     * Adds your supplied get filter. 
 88     * <a href="http://www.xmlblaster.org/xmlBlaster/doc/requirements/mime.plugin.accessfilter.html">The access filter plugin requirement</a>
 89     */
 90    public void addAccessFilter(AccessFilterQos filter) {
 91       this.queryQosData.addAccessFilter(filter);
 92    }
 93 
 94    /**
 95     * Adds your supplied get querySpec. 
 96     * <a href="http://www.xmlblaster.org/xmlBlaster/doc/requirements/query.plugin.html">The query plugin requirement</a>
 97     */
 98    public void addQuerySpec(QuerySpecQos querySpec) {
 99       this.queryQosData.addQuerySpec(querySpec);
100    }
101 
102    /**
103     * Query historical messages. 
104     */
105    public void setHistoryQos(HistoryQos historyQos) {
106       this.queryQosData.setHistoryQos(historyQos);
107    }
108 
109    /**
110     * Sets a client property (an application specific property) to the
111     * given value
112     * @param key
113     * @param value
114     */
115    public void addClientProperty(String key, Object value) {
116       this.queryQosData.addClientProperty(key, value);
117    }
118 
119    /**
120     * Read back a property. 
121     * @return The client property or null if not found
122     */
123    public ClientProperty getClientProperty(String key) {
124       return this.queryQosData.getClientProperty(key);
125    }
126 
127    /**
128     * Converts the data into a valid XML ASCII string.
129     * @return An XML ASCII string
130     */
131    public String toString() {
132       return this.queryQosData.toXml();
133    }
134 
135    public String toXml() {
136       return toXml((Properties)null);
137    }
138    
139    /**
140     * Converts the data into a valid XML ASCII string.
141     * @param props Formatting control, see Constants.TOXML_*
142     * @return An XML ASCII string
143     */
144    public String toXml(Properties props) {
145       return this.queryQosData.toXml((String)null, props);
146    }
147 
148    /** For testing: java org.xmlBlaster.client.qos.GetQos */
149    public static void main(String[] args) {
150       Global glob = new Global(args);
151       try {
152          GetQos qos = new GetQos(glob);
153          qos.setWantContent(false);
154          qos.addAccessFilter(new AccessFilterQos(glob, "ContentLenFilter", "1.0", new Query(glob, "800")));
155          qos.addAccessFilter(new AccessFilterQos(glob, "ContentLenFilter", "3.2", new Query(glob, "a<10")));
156          System.out.println(qos.toXml());
157       }
158       catch (Throwable e) {
159          System.out.println("Test failed: " + e.toString());
160       }
161    }
162 }


syntax highlighted by Code2HTML, v. 0.9.1