📄 queryqossaxfactory.java
字号:
/*------------------------------------------------------------------------------Name: QueryQosSaxFactory.javaProject: xmlBlaster.orgCopyright: xmlBlaster.org, see xmlBlaster-LICENSE file------------------------------------------------------------------------------*/package org.xmlBlaster.util.qos;import java.util.Properties;import java.util.logging.Logger;import org.xmlBlaster.util.Global;import org.xmlBlaster.util.XmlBlasterException;import org.xmlBlaster.util.def.Constants;import org.xmlBlaster.util.def.MethodName;import org.xml.sax.*;/** * Parsing xml QoS (quality of service) of return query. * <p /> * <pre> *<qos> * <subscribe id='_subId:1'/> <!-- Force a subscription ID from client side --> * <erase forceDestroy='true'/> <!-- Kill a MsgUnit even if there are pending updates or subscriptions --> * <meta>false</meta> <!-- Don't send me the xmlKey meta data on updates --> * <content>false</content> <!-- Don't send me the content data on updates (notify only) --> * <multiSubscribe>false</multiSubscribe> <!-- Ignore a second subscribe on same oid or XPATH --> * <local>false</local> <!-- Inhibit the delivery of messages to myself if i have published it --> * <initialUpdate>false</initialUpdate> <!-- don't send an initial message after subscribe --> * <updateOneway>false</updateOneway> <!-- use the acknowledged update() or updateOneway() for callbacks --> * <notify>false</notify> <!-- Suppress erase event to subcribers --> * <filter type='myPlugin' version='1.0'>a!=100</filter> * <!-- Filters messages i have subscribed as implemented in your plugin --> * <history numEntries='20'/> <!-- Default is to deliver the current entry (numEntries='1'), '-1' deliver all --> *</qos> * </pre> * @see org.xmlBlaster.util.qos.QueryQosData * @see org.xmlBlaster.test.classtest.qos.QueryQosFactoryTest * @author xmlBlaster@marcelruff.info */public class QueryQosSaxFactory extends org.xmlBlaster.util.XmlQoSBase implements I_QueryQosFactory{ private final Global glob; private static Logger log = Logger.getLogger(QueryQosSaxFactory.class.getName()); private QueryQosData queryQosData; /** helper flag for SAX parsing: parsing inside <state> ? */ /* private boolean inSubscribe = false; private boolean inErase = false; private boolean inMeta = false; private boolean inContent = false; private boolean inMultiSubscribe = false; private boolean inLocal = false; private boolean inInitialUpdate = false; private boolean inUpdateOneway = false; private boolean inNotify = false; private boolean inFilter = false; private boolean inQuerySpec = false; private boolean inHistory = false; private boolean inIsPersistent = false; */ private AccessFilterQos tmpFilter = null; private QuerySpecQos tmpQuerySpec = null; private HistoryQos tmpHistory = null; /** * Can be used as singleton. */ public QueryQosSaxFactory(Global glob) { super(glob); this.glob = glob; } /** * Parses the given xml Qos and returns a QueryQosData holding the data. * Parsing of update() and publish() QoS is supported here. * @param the XML based ASCII string */ public synchronized QueryQosData readObject(String xmlQos) throws XmlBlasterException { if (xmlQos == null) { xmlQos = "<qos/>"; } this.tmpFilter = null; this.tmpQuerySpec = null; this.tmpHistory = null; queryQosData = new QueryQosData(glob, this, xmlQos, MethodName.UNKNOWN); if (!isEmpty(xmlQos)) // if possible avoid expensive SAX parsing init(xmlQos); // use SAX parser to parse it (is slow) return queryQosData; } /** * Start element, event from SAX parser. * <p /> * @param name Tag name * @param attrs the attributes of the tag */ public final void startElement(String uri, String localName, String name, Attributes attrs) { if (super.startElementBase(uri, localName, name, attrs) == true) return; if (name.equalsIgnoreCase(MethodName.SUBSCRIBE.getMethodName())) { // "subscribe" if (!inQos) return; //this.inSubscribe = true; if (attrs != null) { queryQosData.setSubscriptionId(attrs.getValue("id")); } return; } if (name.equalsIgnoreCase(MethodName.ERASE.getMethodName())) { // "erase" if (!inQos) return;// this.inErase = true; if (attrs != null) { queryQosData.setForceDestroy(new Boolean(attrs.getValue("forceDestroy")).booleanValue()); } return; } if (name.equalsIgnoreCase("meta")) { if (!inQos) return;// this.inMeta = true; queryQosData.setWantMeta(true); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { log.warning("Ignoring sent <meta> attribute " + attrs.getQName(i) + "=" + attrs.getValue(i).trim()); } } return; } if (name.equalsIgnoreCase("content")) { if (!inQos) return;// this.inContent = true; queryQosData.setWantContent(true); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { log.warning("Ignoring sent <content> attribute " + attrs.getQName(i) + "=" + attrs.getValue(i).trim()); } } return; } if (name.equalsIgnoreCase("multiSubscribe")) { if (!inQos) return;// this.inMultiSubscribe = true; queryQosData.setMultiSubscribe(true); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { log.warning("Ignoring sent <multiSubscribe> attribute " + attrs.getQName(i) + "=" + attrs.getValue(i).trim()); } } return; } if (name.equalsIgnoreCase("local")) { if (!inQos) return;// this.inLocal = true; queryQosData.setWantLocal(true); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { log.warning("Ignoring sent <local> attribute " + attrs.getQName(i) + "=" + attrs.getValue(i).trim()); } } return; } if (name.equalsIgnoreCase("initialUpdate")) { if (!inQos) return;// this.inInitialUpdate = true; queryQosData.setWantInitialUpdate(true); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { log.warning("Ignoring sent <initialUpdate> attribute " + attrs.getQName(i) + "=" + attrs.getValue(i).trim()); } } return; } if (name.equalsIgnoreCase("updateOneway")) { if (!inQos) return;// this.inUpdateOneway = true; queryQosData.setWantUpdateOneway(true); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { log.warning("Ignoring sent <updateOneway> attribute " + attrs.getQName(i) + "=" + attrs.getValue(i).trim()); } } return; } if (name.equalsIgnoreCase("notify")) { if (!inQos) return;// this.inNotify = true; queryQosData.setWantNotify(true); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { log.warning("Ignoring sent <notify> attribute " + attrs.getQName(i) + "=" + attrs.getValue(i).trim()); } } return; } if (name.equalsIgnoreCase("filter")) {// this.inFilter = true; tmpFilter = new AccessFilterQos(glob); boolean ok = tmpFilter.startElement(uri, localName, name, character, attrs); if (ok) { queryQosData.addAccessFilter(tmpFilter); } else tmpFilter = null; return; } if (name.equalsIgnoreCase("querySpec")) {// this.this.inQuerySpec = true; this.tmpQuerySpec = new QuerySpecQos(glob); boolean ok = this.tmpQuerySpec.startElement(uri, localName, name, character, attrs); if (ok) { this.queryQosData.addQuerySpec(this.tmpQuerySpec); } else this.tmpQuerySpec = null; return; } if (name.equalsIgnoreCase("history")) {// this.inHistory = true; tmpHistory = new HistoryQos(glob); boolean ok = tmpHistory.startElement(uri, localName, name, character, attrs); if (ok) { queryQosData.setHistoryQos(tmpHistory); } else tmpHistory = null; return; } if (name.equalsIgnoreCase("isErase")) { if (!inQos) return; queryQosData.setMethod(MethodName.ERASE); return; } if (name.equalsIgnoreCase("isGet")) { if (!inQos) return; queryQosData.setMethod(MethodName.GET); return; } if (name.equalsIgnoreCase("isSubscribe")) { if (!inQos) return; queryQosData.setMethod(MethodName.SUBSCRIBE); return; } if (name.equalsIgnoreCase("isUnSubscribe")) { if (!inQos)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -