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

  1. /* ---------------------------------------------------------------------- */
  2. /*                      Component specific code                           */
  3.  
  4. const CLASS_ID    = Components.ID('{45bb23c9-eb7b-4510-ae42-8b2e9e67d29f}');
  5. const CLASS_NAME  = 'XMPP Connector (Twitter)';
  6. const CONTRACT_ID = '@hyperstruct.net/xmpp4moz/connector;1?type=twitter';
  7. const SOURCE      = 'chrome://sameplace/content/connectors/connector-twitter.js';
  8. const INTERFACE   = Components.interfaces.nsIXMPPConnector;
  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.         return component.QueryInterface(aIID);
  44.     }
  45. };
  46.  
  47. var Module = {
  48.     _firstTime: true,
  49.  
  50.     registerSelf: function(aCompMgr, aFileSpec, aLocation, aType) {
  51.         if (this._firstTime) {
  52.             this._firstTime = false;
  53.             throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
  54.         };
  55.         aCompMgr = aCompMgr.QueryInterface(Ci.nsIComponentRegistrar);
  56.         aCompMgr.registerFactoryLocation(
  57.             CLASS_ID, CLASS_NAME, CONTRACT_ID, aFileSpec, aLocation, aType);
  58.     },
  59.  
  60.     unregisterSelf: function(aCompMgr, aLocation, aType) {
  61.         aCompMgr = aCompMgr.QueryInterface(Ci.nsIComponentRegistrar);
  62.         aCompMgr.unregisterFactoryLocation(CLASS_ID, aLocation);
  63.     },
  64.  
  65.     getClassObject: function(aCompMgr, aCID, aIID) {
  66.         if (!aIID.equals(Ci.nsIFactory))
  67.             throw Cr.NS_ERROR_NOT_IMPLEMENTED;
  68.  
  69.         if (aCID.equals(CLASS_ID))
  70.             return Factory;
  71.  
  72.         throw Cr.NS_ERROR_NO_INTERFACE;        
  73.     },
  74.  
  75.     canUnload: function(aCompMgr) { return true; }
  76. };
  77.  
  78. function NSGetModule(aCompMgr, aFileSpec) { return Module; }