1 /*------------------------------------------------------------------------------
  2 Name:      UpdateKey.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.MsgKeyData;
 10 import org.xmlBlaster.util.XmlBlasterException;
 11 
 12 /**
 13  * Parses the key of returned MsgUnit of update(). 
 14  * <p>
 15  * See MsgKeySaxFactory for a syntax description of the allowed xml structure
 16  * </p>
 17  * A typical key could look like this:<br />
 18  * <pre>
 19  *     &lt;key oid='4711' contentMime='text/xml'>
 20  *        &lt;AGENT id='192.168.124.20' subId='1' type='generic'>
 21  *           &lt;DRIVER id='FileProof' pollingFreq='10'>
 22  *           &lt;/DRIVER>
 23  *        &lt;/AGENT>
 24  *     &lt;/key>
 25  * </pre>
 26  * <p>
 27  * NOTE: The key attributes like <i>oid</i> or <i>contentMime</i> are parsed already
 28  * and available with the getter methods in this class and the superclass.
 29  * <br />
 30  * The application specific tags and their attributes (like AGENT or DRIVER in the above example)
 31  * are received as a 'raw' XML ASCII string with the <i>getClientTags()</i> or <i>toXml()</i> methods.
 32  * If you want to look at them you need to parse them yourself, usually by using an XML parser (DOM or SAX parser).
 33  * </p>
 34  * @see org.xmlBlaster.util.key.MsgKeySaxFactory
 35  * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/interface.update.html" target="others">the interface.update requirement</a>
 36  */
 37 public class UpdateKey
 38 {
 39    private final Global glob;
 40    private final MsgKeyData msgKeyData;
 41 
 42    public UpdateKey(MsgKeyData keyData) {
 43       this.glob = keyData.getGlobal();
 44       this.msgKeyData = keyData;
 45    }
 46 
 47    /**
 48     * Parse the given xml data. 
 49     */
 50    public UpdateKey(Global glob, String xmlKey) throws XmlBlasterException {
 51       this.glob = glob;
 52       this.msgKeyData = glob.getMsgKeyFactory().readObject(xmlKey);
 53    }
 54 
 55    public MsgKeyData getData() {
 56       return this.msgKeyData;
 57    }
 58 
 59    public Global getGlobal() {
 60       return this.glob;
 61    }
 62 
 63    /**
 64     * Access the &lt;key oid="...">.
 65     * @return The unique key oid
 66     */
 67    public String getOid() {
 68       return this.msgKeyData.getOid();
 69    }
 70 
 71    /**
 72     * Dead letters are unrecoverable lost messages, usually an administrator
 73     * should subscribe to those messages.
 74     * <p>
 75     * This is an internal message (isInternal() returns true)
 76     * </p>
 77     */
 78    public boolean isDeadMessage() {
 79       return this.msgKeyData.isDeadMessage();
 80    }
 81 
 82    /**
 83     * Messages starting with "_" are reserved for usage in plugins
 84     */
 85    public final boolean isPluginInternal() {
 86       return this.msgKeyData.isPluginInternal();
 87    }
 88 
 89    /**
 90     * Messages starting with "__" are reserved for internal usage
 91     */
 92    public final boolean isInternal() {
 93       return this.msgKeyData.isInternal();
 94    }
 95 
 96    /**
 97     * A MIME type like "image/gif"
 98     */
 99    public String getContentMime() {
100       return this.msgKeyData.getContentMime();
101    }
102 
103    /**
104     * For example a version number of the mime type
105     */
106    public String getContentMimeExtended() {
107       return this.msgKeyData.getContentMimeExtended();
108    }
109 
110    /**
111     * Access the domain setting
112     * @return A domain string or null
113     */
114    public String getDomain() {
115       return this.msgKeyData.getDomain();
116    }
117 
118    /**
119     * Your specific application tags.
120     */
121    public String getClientTags() {
122       return this.msgKeyData.getClientTags();
123    }
124 
125    /**
126     * Converts the data in XML ASCII string.
127     * @return An XML ASCII string
128     */
129    public String toXml(String extraOffset) {
130       return this.msgKeyData.toXml(extraOffset);
131    }
132 
133    /**
134     * Converts the data in XML ASCII string.
135     * @return An XML ASCII string
136     */
137    public String toXml() {
138       return this.msgKeyData.toXml();
139    }
140 
141    public String toString() {
142       return toXml().trim();
143    }
144 }


syntax highlighted by Code2HTML, v. 0.9.1