⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 callback.js

📁 java开源的企业总线.xmlBlaster
💻 JS
📖 第 1 页 / 共 2 页
字号:
/*------------------------------------------------------------------------------Name:      callback.jsProject:   xmlBlaster.orgComment:   Implementing some Javascript callback objects for xmlBlasterAuthor:    konrad.krafft@doubleslash.de xmlBlaster@marcelruff.infoSee:       persistentWindow/index.html and demo/http/svg/systemInfo/northFrame.html------------------------------------------------------------------------------*/// First define the usual xmlBlaster access methods// @see <a href="http://www.xmlBlaster.org/xmlBlaster/src/java/org/xmlBlaster/protocol/corba/xmlBlaster.idl" target="others">CORBA xmlBlaster.idl</a>/** * Logout the nice way. */function xmlBlasterLogout(){   top.location.href = "/xmlBlaster/BlasterHttpProxyServlet?ActionType=logout";}/** * A message contains key/content/qos * See description of subscribe() */function publish(message){   if (Log.TRACE) Log.trace("Invoking publish request ...");   request("publish", message);   if (Log.TRACE) Log.trace("Publish request done");}/** * See description of subscribe() * Synchronous get() is currently not supported */function get(key, qos){   Log.error("Synchronous GET implementation to xmlBlaster is not supported");   if (Log.TRACE) Log.trace("Invoking get request for " + key.oid + " ...");   request("get", new MessageWrapperLiteral(key, "", qos));   if (Log.TRACE) Log.trace("Get request for " + key.oid + " done");}/** * @param key SubscribeKey object or literal as xml ASCII string "<key oid='' ...</key>" * @param qos QosWrapper object or a literal string like "<qos>...</qos>" */function subscribe(key, qos){   if (Log.TRACE) Log.trace("Invoking subscribe request for " + key.oid + " ...");   request("subscribe", new MessageWrapperLiteral(key, "", qos));   if (Log.TRACE) Log.trace("Subscribe request for " + key.oid + " done");}/** * See description of subscribe() */function unSubscribe(key, qos){   if (Log.TRACE) Log.trace("Invoking unSubscribe request for " + key.oid + " ...");   request("unSubscribe", new MessageWrapperLiteral(key, "", qos));   if (Log.TRACE) Log.trace("UnSubscribe request for " + key.oid + " done");}/** * See description of subscribe() */function erase(key, qos){   if (Log.TRACE) Log.trace("Invoking get erase for " + key.oid + " ...");   request("erase", new MessageWrapperLiteral(key, "", qos));   if (Log.TRACE) Log.trace("Get erase for " + key.oid + " done");}/** * This allows to send a request to the servlet. * We use a dedicated little frame 'requestFrame' for this, * the returned html from the servlet is ignored there. * * A request may look typically like this: *    /xmlBlaster/BlasterHttpProxyServlet?ActionType=subscribe&key=<key oid='cpuinfo' contentMime='text/plain'></key>"&qos=<qos></qos> * where the xml stuff is encoded. * * @param methodName "subscribe" etc. * @param msgWrapper A MessageWrapperLiteral - Object containing the key and qos, *        for publish() calls it contains a content as well. * * Note: The MessageWrapperLiteral may contain the key and qos as literal xml ASCII string *              or as one of the wrapper objects, e.g. QosWrapper() or SubscribeKey(glob, ) */function request(methodName, msgWrapper){   if (Log.TRACE) Log.trace("Sending request " + methodName + " to servlet");   if (isExplorer) {      self.frames["requestFrame"].location.reload(true);   }   req = "/xmlBlaster/BlasterHttpProxyServlet?ActionType="+methodName+"&";   //req += "key.oid=" + msgWrapper.key.oid;   if ((typeof msgWrapper.key) != "undefined" && msgWrapper.key!=null) {      if ((typeof msgWrapper.key) == "string") {         req += "key=" + escape(msgWrapper.key);      }      else if ((typeof msgWrapper.key) == "object") {         req += "key=" + escape(msgWrapper.key.toXml());      }      else {         Log.error("In request '" + methodName + "' the key is an unknown object, ignoring request!");         return;      }   }   if ((typeof msgWrapper.content) != "undefined" && msgWrapper.content!=null) {      req += "&content=" + escape(msgWrapper.content);   }   if ((typeof msgWrapper.qos) != "undefined" && msgWrapper.qos!=null) {      if ((typeof msgWrapper.qos) == "string") {         req += "&qos=" + escape(msgWrapper.qos);      }      else if ((typeof msgWrapper.qos) == "object") {         req += "&qos=" + escape(msgWrapper.qos.toXml());      }   }   self.frames["requestFrame"].location.href=req; // Invoke servlet.}/** * The Servlet is pinging the browser to keep connection alive. * This method is invoked from the callbackFrame. * @param state The string "refresh-73"<br /> *        When login is done successfully, state="loginSucceeded" is sent one time */function ping(state) {   if (state == "loginSucceeded") {      Log.info("Received ping for successful login");      self.opener.loginSucceeded(self); // callback my opener that the connection is established   }   else {      // Response to servlet that we are alive ...      if (Log.TRACE) Log.trace("Received ping '" + state + "', sending pong back to servlet");      if (isExplorer) {         // Force a reload, is necessary for MSIE5, otherwise its refreshed from the browser cache         self.frames["pingFrame"].location.reload(true);      }      // Sending the state is for debugging and for proxies to let it through (not a similar request)      self.frames["pingFrame"].location.href="/xmlBlaster/BlasterHttpProxyServlet?ActionType=pong&state=" + state;   }   if ((typeof pingTimeoutHandler) != "undefined")      window.clearTimeout(pingTimeoutHandler);   // Check for ping every 15 seconds, this value needs to   // be bigger than the HttpPushHandler.java  PING_INTERVAL value   pingTimeoutHandler = window.setTimeout( "cutConnection()", 35000);}/** * Timeout occurred, lost the server */function cutConnection() {   Log.info("Entering cutConnection() ...");   self.connectionTextFrame.document.location.href="notConnected.html";}/** * This allows to notify the servlet that the browser processed the * last request and is ready to receive the next message. */function browserReady(){   if (Log.TRACE) Log.trace("Sending browserReady() to servlet");   // add some dynamic data (milliseconds since 1970), that MSIE 5 resends it.   var date = new Date();   var millisec = Date.parse(date);   //if (isExplorer) {      self.frames["controlFrame"].location.reload(true);   //}   // This alone is not enough, sometimes the request does not reach the servlet (mozilla 0.91/tomcat 3.2.3):   // See http://developer.netscape.com/docs/manuals/communicator/jsref/wina1.htm   //self.frames["controlFrame"].location.href="/xmlBlaster/BlasterHttpProxyServlet?ActionType=browserReady&counter=" + millisec;   self.frames["controlFrame"].location.replace("/xmlBlaster/BlasterHttpProxyServlet?ActionType=browserReady&counter=" + millisec);}/** * Constructor for a XmlKey helper object. * If you have own meta data, add it with the method wrap: * Example: var key = new top.SubscribeKey(glob, null, "text/xml", null); *          key.wrap("<Name id='Joe' />"); * @param oid:String The unique message identifier, is optional and will be generated if null * @param contentMime:String The MIME type of the content e.g. "text/xml" or "image/gif" * @param contentMimeExtended:String Use it for whatever, e.g. the version number or parser *        infos for your content set to null if not needed */function SubscribeKey(glob, oid, contentMime, contentMimeExtended){   if (oid == null)      this.oid = '';   else      this.oid = oid;   if (contentMime == null)      this.contentMime = "text/plain";   else      this.contentMime = contentMime;   this.contentMimeExtended = contentMimeExtended;   this.wrap = SubscribeKeyWrap;   this.toXml = SubscribeKeyToXml;}function SubscribeKeyToXml(){   var str='';   str += "<key oid='" + this.oid + "'";   str += " contentMime='" + this.contentMime + "'";   if (this.contentMimeExtended != null)      str += " contentMimeExtended='" + this.contentMimeExtended + "'";   str += ">\n";   if ((typeof this.clientTags) != "undefined" && this.clientTags!=null)      str += this.clientTags;   str += "\n</key>";   if (Log.INFO) Log.info(str);   return str;}function SubscribeKeyWrap(tags){   if ((typeof tags) == "undefined" || tags == null)      this.tags = '';   else      this.tags = tags;}/** * Constructor for a XmlKey helper object. * If you have own meta data, add it with the method wrap: * Example: var key = new top.PublishKey(glob, null, "text/xml", null); *          key.wrap("<Name id='Joe' />"); * @param oid:String The unique message identifier, is optional and will be generated if null * @param contentMime:String The MIME type of the content e.g. "text/xml" or "image/gif" * @param contentMimeExtended:String Use it for whatever, e.g. the version number or parser *        infos for your content set to null if not needed */function PublishKey(glob, oid, contentMime, contentMimeExtended){   if (oid == null)      this.oid = '';   else      this.oid = oid;   if (contentMime == null)      this.contentMime = "text/plain";   else      this.contentMime = contentMime;   this.contentMimeExtended = contentMimeExtended;   this.wrap = PublishKeyWrap;   this.toXml = PublishKeyToXml;}function PublishKeyToXml(){   var str='';   str += "<key oid='" + this.oid + "'";   str += " contentMime='" + this.contentMime + "'";   if (this.contentMimeExtended != null)      str += " contentMimeExtended='" + this.contentMimeExtended + "'";   str += ">\n";   if ((typeof this.clientTags) != "undefined" && this.clientTags!=null)      str += this.clientTags;   str += "\n</key>";   if (Log.TRACE) Log.trace("PublishKey=" + str);   return str;}function PublishKeyWrap(tags){   if ((typeof tags) == "undefined" || tags == null)      this.tags = '';   else      this.tags = tags;}/** * Constructor for a Qos helper object. * If you have own meta data, add it with the method wrap: * * Example: *  var key = new top.xmlBlasterWindow.QosWrapper("<persistent />"); * * @param wrap:String Tags to embed into the <qos>...</qos> tags */function QosWrapper(wrapTags){   if (wrapTags == null)      this.tags = null;   else      this.tags = wrapTags;   this.contentMimeExtended = contentMimeExtended;   this.wrap = QosWrapperWrap;   this.toXml = QosWrapperToXml;}function QosWrapperToXml(){   var str='';   str += "<qos>";   if ((typeof this.tags) != "undefined" && this.tags!=null)      str += this.tags;   str += "\n</qos>";   if (Log.INFO) Log.info("QosWrapperToXml(): " + str);   return str;}function QosWrapperWrap(tags){   if ((typeof tags) == "undefined" || tags == null)      this.tags = null;   else      this.tags = tags;}/** * This class encapsulates the Message meta data and unique identifier of a received message. * A typical <b>update</b> key could look like this:<br /> * <pre> *     &lt;key oid='4711' contentMime='text/xml'> *        &lt;AGENT id='192.168.124.20' subId='1' type='generic'> *           &lt;DRIVER id='FileProof' pollingFreq='10'> *           &lt;/DRIVER> *        &lt;/AGENT> *     &lt;/key> * </pre> * Note that the AGENT and DRIVER tags are application know how, which you have to supply.<br /> * A well designed xml hierarchy of your problem domain is essential for a proper working xmlBlaster * This is exactly the key how it was published from the data source. * Call updateKey.init(key_literal); to start parsing the received key */function UpdateKey(xml){   this.oid = null;                 // value from attribute <key oid="...">   this.contentMime = null;         // value from attribute <key oid="" contentMime="...">   this.contentMimeExtended = "";   // value from attribute <key oid="" contentMimeExtended="...">   //  Analyzing e.g. <key oid='1234' contentMime='text/plain'>...</key>   this.root = top.Xparse(xml);     // The Javascript DOM tree   var keyNode = this.root.contents[0];   if (keyNode.name != "key") {      Log.warn('Key tag is missing in new arrvied message, received an unknown tag &lt;' + keyNode.name + '>');      return;   }   for(attrib in keyNode.attributes) {      // Log.trace('Processing ' + attrib + '="' + keyNode.attributes[attrib] + '" ...');      if (attrib == "oid")         this.oid = keyNode.attributes[attrib];      else if (attrib == "contentMime")         this.contentMime = keyNode.attributes[attrib];      else if (attrib == "contentMimeExtended")         this.contentMimeExtended = keyNode.attributes[attrib];   }}function UpdateQos(xml){   this.sender= null;               // Who sent the message (his login name)?   this.root = top.Xparse(xml);     // The Javascript DOM tree

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -