I wanted to run this by Jband.

I am working on some xpconnect utilities.
One in particular returns an interface name from a ProgID argument.

I'd like to know is this a good way to implement it?

test output:

js> getInterface('@mozilla.org/network/local-file-channel;1');
nsIChannel
js> getInterface('@mozilla.org/network/file-transport-service;1');
nsIFileTransportService
js> getInterface('@mozilla.org/file/local;1');
nsILocalFile
js>


function getInterface(aProgID)
{

  var C=Components;
  var i=C.interfaces;
  var c=C.classes;
  var list;

  if(!aProgID)
  {
    throw C.results.NS_ERROR_XPC_NOT_ENOUGH_ARGS;
    return null;
  }

  for(list in i)
  {
    try
    {
      if(typeof(i[list])!='undefined')
        if(typeof(c[aProgID].getService(i[list]))=='object')
          return list;
    }

    catch(e){}
  }

}



Reply via email to