16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# ***** BEGIN LICENSE BLOCK *****
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# Version: MPL 1.1/GPL 2.0/LGPL 2.1
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync#
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# The contents of this file are subject to the Mozilla Public License Version
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# 1.1 (the "License"); you may not use this file except in compliance with
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# the License. You may obtain a copy of the License at
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# http://www.mozilla.org/MPL/
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync#
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# Software distributed under the License is distributed on an "AS IS" basis,
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# for the specific language governing rights and limitations under the
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# License.
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync#
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# The Original Code is the Python XPCOM language bindings.
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync#
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# The Initial Developer of the Original Code is ActiveState Tool Corp.
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# Portions created by ActiveState Tool Corp. are Copyright (C) 2000, 2001
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# ActiveState Tool Corp. All Rights Reserved.
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync#
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# Contributor(s):
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# Mark Hammond <MarkH@ActiveState.com> (original author)
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync#
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# Alternatively, the contents of this file may be used under the terms of
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# either the GNU General Public License Version 2 or later (the "GPL"), or
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# in which case the provisions of the GPL or the LGPL are applicable instead
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# of those above. If you wish to allow use of your version of this file only
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# under the terms of either the GPL or the LGPL, and not to allow others to
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# use your version of this file under the terms of the MPL, indicate your
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# decision by deleting the provisions above and replace them with the notice
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# and other provisions required by the GPL or the LGPL. If you do not delete
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# the provisions above, a recipient may use your version of this file under
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# the terms of any one of the MPL, the GPL or the LGPL.
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync#
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync# ***** END LICENSE BLOCK *****
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsyncfrom xpcom import components
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsyncfrom xpcom import ServerException, Exception
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsyncfrom xpcom import nsError
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsyncimport factory
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsyncimport types
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsyncimport os
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsyncclass Module:
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync _com_interfaces_ = components.interfaces.nsIModule
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync def __init__(self, comps):
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync # Build a map of classes we can provide factories for.
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync c = self.components = {}
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync for klass in comps:
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync c[components.ID(klass._reg_clsid_)] = klass
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync self.klassFactory = factory.Factory
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync def getClassObject(self, compMgr, clsid, iid):
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync # Single retval result.
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync try:
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync klass = self.components[clsid]
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync except KeyError:
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync raise ServerException(nsError.NS_ERROR_FACTORY_NOT_REGISTERED)
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync # We can ignore the IID - the auto-wrap process will automatically QI us.
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync return self.klassFactory(klass)
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync def registerSelf(self, compMgr, location, loaderStr, componentType):
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync # void function.
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync fname = os.path.basename(location.path)
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync for klass in self.components.values():
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync reg_contractid = klass._reg_contractid_
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync print "Registering '%s' (%s)" % (reg_contractid, fname)
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync reg_desc = getattr(klass, "_reg_desc_", reg_contractid)
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync compMgr = compMgr.queryInterface(components.interfaces.nsIComponentRegistrar)
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync compMgr.registerFactoryLocation(klass._reg_clsid_,
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync reg_desc,
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync reg_contractid,
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync location,
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync loaderStr,
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync componentType)
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync # See if this class nominates custom register_self
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync extra_func = getattr(klass, "_reg_registrar_", (None,None))[0]
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync if extra_func is not None:
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync extra_func(klass, compMgr, location, loaderStr, componentType)
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync def unregisterSelf(self, compMgr, location, loaderStr):
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync # void function.
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync for klass in self.components.values():
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync ok = 1
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync try:
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync compMgr.unregisterComponentSpec(klass._reg_clsid_, location)
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync except Exception:
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync ok = 0
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync # Give the class a bash even if we failed!
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync extra_func = getattr(klass, "_reg_registrar_", (None,None))[1]
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync if extra_func is not None:
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync try:
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync extra_func(klass, compMgr, location, loaderStr)
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync except Exception:
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync ok = 0
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync if ok:
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync print "Successfully unregistered", klass.__name__
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync else:
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync print "Unregistration of", klass.__name__, "failed. (probably just not already registered)"
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync def canUnload(self, compMgr):
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync # single bool result
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync return 0 # we can never unload!
16a8d09569a2ebd598cef72fa605be6fb4563607vboxsync