Back to index

plone3  3.1.7
Static Public Attributes | Private Member Functions | Static Private Attributes
GenericSetup.components.ComponentRegistryXMLAdapter Class Reference
Inheritance diagram for GenericSetup.components.ComponentRegistryXMLAdapter:
Inheritance graph
[legend]
Collaboration diagram for GenericSetup.components.ComponentRegistryXMLAdapter:
Collaboration graph
[legend]

List of all members.

Static Public Attributes

string name = 'componentregistry'

Private Member Functions

def _exportNode
def _importNode
def _purgeAdapters
def _purgeUtilities
def _initAdapters
def _getSite
def _initUtilities
def _extractAdapters
def _extractUtilities

Static Private Attributes

string _LOGGER_ID = 'componentregistry'

Detailed Description

XML im- and exporter for a local component registry.

Definition at line 35 of file components.py.


Member Function Documentation

Definition at line 46 of file components.py.

00046 
00047     def _exportNode(self):
00048         node = self._doc.createElement('componentregistry')
00049         fragment = self._doc.createDocumentFragment()
00050 
00051         child = self._doc.createElement('adapters')
00052         child.appendChild(self._extractAdapters())
00053         self._logger.info('Adapters exported.')
00054         fragment.appendChild(child)
00055 
00056         child = self._doc.createElement('utilities')
00057         child.appendChild(self._extractUtilities())
00058         self._logger.info('Utilities exported.')
00059         fragment.appendChild(child)
00060 
00061         node.appendChild(fragment)
00062 
00063         return node

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 171 of file components.py.

00171 
00172     def _extractAdapters(self):
00173         fragment = self._doc.createDocumentFragment()
00174 
00175         registrations = [ {'factory': _getDottedName(reg.factory),
00176                            'provided': _getDottedName(reg.provided),
00177                            'required': reg.required,
00178                            'name': reg.name}
00179                           for reg in self.context.registeredAdapters() ]
00180         registrations.sort(key=itemgetter('name'))
00181         registrations.sort(key=itemgetter('provided'))
00182 
00183         for reg_info in registrations:
00184             child = self._doc.createElement('adapter')
00185 
00186             for_ = u''
00187             for interface in reg_info['required']:
00188                 for_ = for_ + _getDottedName(interface) + u'\n           '
00189 
00190             child.setAttribute('factory', reg_info['factory'])
00191             child.setAttribute('provides', reg_info['provided'])
00192             child.setAttribute('for_', for_.strip())
00193             if reg_info['name']:
00194                 child.setAttribute('name', reg_info['name'])
00195 
00196             fragment.appendChild(child)
00197 
00198         return fragment

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 199 of file components.py.

00199 
00200     def _extractUtilities(self):
00201         fragment = self._doc.createDocumentFragment()
00202 
00203         registrations = [ {'component': reg.component,
00204                            'provided': _getDottedName(reg.provided),
00205                            'name': reg.name}
00206                           for reg in self.context.registeredUtilities() ]
00207         registrations.sort(key=itemgetter('name'))
00208         registrations.sort(key=itemgetter('provided'))
00209         site = aq_base(self._getSite())
00210 
00211         for reg_info in registrations:
00212             child = self._doc.createElement('utility')
00213 
00214             child.setAttribute('interface', reg_info['provided'])
00215 
00216             if reg_info['name']:
00217                 child.setAttribute('name', reg_info['name'])
00218 
00219             comp = reg_info['component']
00220             # check if the component is acquisition wrapped. If it is, export
00221             # an object reference instead of a factory reference
00222             if getattr(comp, 'aq_base', None) is not None:
00223                 if aq_base(comp) is site:
00224                     child.setAttribute('object', '')
00225                 elif hasattr(aq_base(comp), 'getId'):
00226                     child.setAttribute('object', comp.getId())
00227                 else:
00228                     # This is a five.localsitemanager wrapped utility
00229                     factory = _getDottedName(type(aq_base(comp)))
00230                     child.setAttribute('factory', factory)
00231             else:
00232                 factory = _getDottedName(type(comp))
00233                 child.setAttribute('factory', factory)
00234 
00235             fragment.appendChild(child)
00236 
00237         return fragment
00238 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 121 of file components.py.

00121 
00122     def _getSite(self):
00123         # Get the site by either __parent__ or Acquisition
00124         site = getattr(self.context, '__parent__', None)
00125         if site is None:
00126             site = aq_parent(self.context)
00127         return site

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 64 of file components.py.

00064 
00065     def _importNode(self, node):
00066         if self.environ.shouldPurge():
00067             self._purgeAdapters()
00068             self._logger.info('Adapters purged.')
00069             self._purgeUtilities()
00070             self._logger.info('Utilities purged.')
00071 
00072         for child in node.childNodes:
00073             if child.nodeName == 'adapters':
00074                 self._initAdapters(child)
00075                 self._logger.info('Adapters registered.')
00076             if child.nodeName == 'utilities':
00077                 self._initUtilities(child)
00078                 self._logger.info('Utilities registered.')

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 101 of file components.py.

00101 
00102     def _initAdapters(self, node):
00103         for child in node.childNodes:
00104             if child.nodeName != 'adapter':
00105                 continue
00106 
00107             factory = _resolveDottedName(child.getAttribute('factory'))
00108             provided = _resolveDottedName(child.getAttribute('provides'))
00109             name = unicode(str(child.getAttribute('name')))
00110 
00111             for_ = child.getAttribute('for_')
00112             required = []
00113             for interface in for_.split(u' '):
00114                 if interface:
00115                     required.append(_resolveDottedName(interface))
00116 
00117             self.context.registerAdapter(factory,
00118                                          required=required,
00119                                          provided=provided,
00120                                          name=name)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 128 of file components.py.

00128 
00129     def _initUtilities(self, node):
00130         site = self._getSite()
00131         for child in node.childNodes:
00132             if child.nodeName != 'utility':
00133                 continue
00134 
00135             provided = _resolveDottedName(child.getAttribute('interface'))
00136             name = unicode(str(child.getAttribute('name')))
00137 
00138             component = child.getAttribute('component')
00139             component = component and _resolveDottedName(component) or None
00140 
00141             factory = child.getAttribute('factory')
00142             factory = factory and _resolveDottedName(factory) or None
00143 
00144             obj_path = child.getAttribute('object')
00145             if not component and not factory and obj_path is not None:
00146                 # Support for registering the site itself
00147                 if obj_path in ('', '/'):
00148                     obj = site
00149                 else:
00150                     # BBB: filter out path segments, we did claim to support
00151                     # nested paths once
00152                     id_ = [p for p in obj_path.split('/') if p][0]
00153                     obj = getattr(site, id_, None)
00154 
00155                 if obj is not None:
00156                     self.context.registerUtility(aq_base(obj), provided, name)
00157                 else:
00158                     # Log an error, object not found
00159                     self._logger.warning("The object %s was not found, while "
00160                                          "trying to register an utility. The "
00161                                          "provided object definition was %s. "
00162                                          "The site used was: %s"
00163                                          % (repr(obj), obj_path, repr(site)))
00164             elif component:
00165                 self.context.registerUtility(component, provided, name)
00166             elif factory is not None:
00167                 self.context.registerUtility(factory(), provided, name)
00168             else:
00169                 self._logger.warning("Invalid utility registration for "
00170                                      "interface %s" % provided)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 79 of file components.py.

00079 
00080     def _purgeAdapters(self):
00081         registrations = tuple(self.context.registeredAdapters())
00082         
00083         for registration in registrations:
00084             factory = registration.factory
00085             required = registration.required
00086             provided = registration.provided
00087             name = registration.name
00088 
00089             self.context.unregisterAdapter(factory=factory,
00090                                            required=required,
00091                                            provided=provided,
00092                                            name=name)

Here is the caller graph for this function:

Definition at line 93 of file components.py.

00093 
00094     def _purgeUtilities(self):
00095         registrations = tuple(self.context.registeredUtilities())
00096         
00097         for registration in registrations:
00098             provided = registration.provided
00099             name = registration.name
00100             self.context.unregisterUtility(provided=provided, name=name)

Here is the caller graph for this function:


Member Data Documentation

string GenericSetup.components.ComponentRegistryXMLAdapter._LOGGER_ID = 'componentregistry' [static, private]

Definition at line 42 of file components.py.

string GenericSetup.components.ComponentRegistryXMLAdapter.name = 'componentregistry' [static]

Definition at line 44 of file components.py.


The documentation for this class was generated from the following file: