home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 May / PCWorld_2008-05_cd.bin / komunikace / sameplace / sameplace-suite-release.xpi / xmpp4moz-0.6.1.xpi / components / XMPPClientService.js < prev    next >
Text File  |  2008-02-11  |  3KB  |  81 lines

  1. /* ---------------------------------------------------------------------- */
  2. /*                      Component specific code                           */
  3.  
  4. const CLASS_ID = Components.ID('{93fa793c-2bda-4a4c-90c6-7db2c52de9f5}');
  5. const CLASS_NAME = 'XMPP Service';
  6. const CONTRACT_ID = '@hyperstruct.net/xmpp4moz/xmppservice;1';
  7. const SOURCE = 'chrome://xmpp4moz/content/service/client_service.js';
  8. const INTERFACE = Components.interfaces.nsIXMPPClientService;
  9.  
  10. /* ---------------------------------------------------------------------- */
  11. /*                           Template code                                */
  12.  
  13. const Cc = Components.classes;
  14. const Ci = Components.interfaces;
  15. const Cr = Components.results;
  16. const Cu = Components.utils;
  17. const loader = Cc['@mozilla.org/moz/jssubscript-loader;1']
  18.     .getService(Ci.mozIJSSubScriptLoader);
  19.  
  20. function Component() {
  21.     this.wrappedJSObject = this;
  22. }
  23.  
  24. Component.prototype = {
  25.     reload: function() {
  26.         loader.loadSubScript(SOURCE, this.__proto__);
  27.     },
  28.     
  29.     QueryInterface: function(aIID) {
  30.         if(!aIID.equals(INTERFACE) &&
  31.            !aIID.equals(Ci.nsISupports))
  32.             throw Cr.NS_ERROR_NO_INTERFACE;
  33.         return this;
  34.     }
  35. };
  36. loader.loadSubScript(SOURCE, Component.prototype);
  37.  
  38. var Factory = {
  39.     createInstance: function(aOuter, aIID) {
  40.         if(aOuter != null)
  41.             throw Cr.NS_ERROR_NO_AGGREGATION;
  42.         var component = new Component();
  43.         if(typeof(component.init) == 'function')
  44.             component.init();
  45.  
  46.         return component.QueryInterface(aIID);
  47.     }
  48. };
  49.  
  50. var Module = {
  51.     _firstTime: true,
  52.  
  53.     registerSelf: function(aCompMgr, aFileSpec, aLocation, aType) {
  54.         if (this._firstTime) {
  55.             this._firstTime = false;
  56.             throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
  57.         };
  58.         aCompMgr = aCompMgr.QueryInterface(Ci.nsIComponentRegistrar);
  59.         aCompMgr.registerFactoryLocation(
  60.             CLASS_ID, CLASS_NAME, CONTRACT_ID, aFileSpec, aLocation, aType);
  61.     },
  62.  
  63.     unregisterSelf: function(aCompMgr, aLocation, aType) {
  64.         aCompMgr = aCompMgr.QueryInterface(Ci.nsIComponentRegistrar);
  65.         aCompMgr.unregisterFactoryLocation(CLASS_ID, aLocation);
  66.     },
  67.  
  68.     getClassObject: function(aCompMgr, aCID, aIID) {
  69.         if (!aIID.equals(Ci.nsIFactory))
  70.             throw Cr.NS_ERROR_NOT_IMPLEMENTED;
  71.  
  72.         if (aCID.equals(CLASS_ID))
  73.             return Factory;
  74.  
  75.         throw Cr.NS_ERROR_NO_INTERFACE;        
  76.     },
  77.  
  78.     canUnload: function(aCompMgr) { return true; }
  79. };
  80.  
  81. function NSGetModule(aCompMgr, aFileSpec) { return Module; }