1 | # ***** BEGIN LICENSE BLOCK *****
|
---|
2 | # Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
3 | #
|
---|
4 | # The contents of this file are subject to the Mozilla Public License Version
|
---|
5 | # 1.1 (the "License"); you may not use this file except in compliance with
|
---|
6 | # the License. You may obtain a copy of the License at
|
---|
7 | # http://www.mozilla.org/MPL/
|
---|
8 | #
|
---|
9 | # Software distributed under the License is distributed on an "AS IS" basis,
|
---|
10 | # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
11 | # for the specific language governing rights and limitations under the
|
---|
12 | # License.
|
---|
13 | #
|
---|
14 | # The Original Code is the Python XPCOM language bindings.
|
---|
15 | #
|
---|
16 | # The Initial Developer of the Original Code is ActiveState Tool Corp.
|
---|
17 | # Portions created by ActiveState Tool Corp. are Copyright (C) 2000, 2001
|
---|
18 | # ActiveState Tool Corp. All Rights Reserved.
|
---|
19 | #
|
---|
20 | # Contributor(s):
|
---|
21 | # Mark Hammond <[email protected]> (original author)
|
---|
22 | #
|
---|
23 | # Alternatively, the contents of this file may be used under the terms of
|
---|
24 | # either the GNU General Public License Version 2 or later (the "GPL"), or
|
---|
25 | # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
26 | # in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
27 | # of those above. If you wish to allow use of your version of this file only
|
---|
28 | # under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
29 | # use your version of this file under the terms of the MPL, indicate your
|
---|
30 | # decision by deleting the provisions above and replace them with the notice
|
---|
31 | # and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
32 | # the provisions above, a recipient may use your version of this file under
|
---|
33 | # the terms of any one of the MPL, the GPL or the LGPL.
|
---|
34 | #
|
---|
35 | # ***** END LICENSE BLOCK *****
|
---|
36 |
|
---|
37 | from xpcom import components
|
---|
38 | from xpcom import ServerException, Exception
|
---|
39 | from xpcom import nsError
|
---|
40 |
|
---|
41 | import factory
|
---|
42 |
|
---|
43 | import types
|
---|
44 | import os
|
---|
45 |
|
---|
46 | class Module:
|
---|
47 | _com_interfaces_ = components.interfaces.nsIModule
|
---|
48 | def __init__(self, comps):
|
---|
49 | # Build a map of classes we can provide factories for.
|
---|
50 | c = self.components = {}
|
---|
51 | for klass in comps:
|
---|
52 | c[components.ID(klass._reg_clsid_)] = klass
|
---|
53 | self.klassFactory = factory.Factory
|
---|
54 |
|
---|
55 | def getClassObject(self, compMgr, clsid, iid):
|
---|
56 | # Single retval result.
|
---|
57 | try:
|
---|
58 | klass = self.components[clsid]
|
---|
59 | except KeyError:
|
---|
60 | raise ServerException(nsError.NS_ERROR_FACTORY_NOT_REGISTERED)
|
---|
61 |
|
---|
62 | # We can ignore the IID - the auto-wrap process will automatically QI us.
|
---|
63 | return self.klassFactory(klass)
|
---|
64 |
|
---|
65 | def registerSelf(self, compMgr, location, loaderStr, componentType):
|
---|
66 | # void function.
|
---|
67 | fname = os.path.basename(location.path)
|
---|
68 | for klass in self.components.values():
|
---|
69 | reg_contractid = klass._reg_contractid_
|
---|
70 | print "Registering '%s' (%s)" % (reg_contractid, fname)
|
---|
71 | reg_desc = getattr(klass, "_reg_desc_", reg_contractid)
|
---|
72 | compMgr = compMgr.queryInterface(components.interfaces.nsIComponentRegistrar)
|
---|
73 | compMgr.registerFactoryLocation(klass._reg_clsid_,
|
---|
74 | reg_desc,
|
---|
75 | reg_contractid,
|
---|
76 | location,
|
---|
77 | loaderStr,
|
---|
78 | componentType)
|
---|
79 |
|
---|
80 | # See if this class nominates custom register_self
|
---|
81 | extra_func = getattr(klass, "_reg_registrar_", (None,None))[0]
|
---|
82 | if extra_func is not None:
|
---|
83 | extra_func(klass, compMgr, location, loaderStr, componentType)
|
---|
84 |
|
---|
85 | def unregisterSelf(self, compMgr, location, loaderStr):
|
---|
86 | # void function.
|
---|
87 | for klass in self.components.values():
|
---|
88 | ok = 1
|
---|
89 | try:
|
---|
90 | compMgr.unregisterComponentSpec(klass._reg_clsid_, location)
|
---|
91 | except Exception:
|
---|
92 | ok = 0
|
---|
93 | # Give the class a bash even if we failed!
|
---|
94 | extra_func = getattr(klass, "_reg_registrar_", (None,None))[1]
|
---|
95 | if extra_func is not None:
|
---|
96 | try:
|
---|
97 | extra_func(klass, compMgr, location, loaderStr)
|
---|
98 | except Exception:
|
---|
99 | ok = 0
|
---|
100 | if ok:
|
---|
101 | print "Successfully unregistered", klass.__name__
|
---|
102 | else:
|
---|
103 | print "Unregistration of", klass.__name__, "failed. (probably just not already registered)"
|
---|
104 |
|
---|
105 | def canUnload(self, compMgr):
|
---|
106 | # single bool result
|
---|
107 | return 0 # we can never unload!
|
---|
108 |
|
---|