def get_factory_context(cls): """ Retrieves the factory context object associated to a factory. Creates it if needed :param cls: The factory class :return: The factory class context """ context = getattr(cls, constants.IPOPO_FACTORY_CONTEXT, None) if context is None: # Class not yet manipulated context = FactoryContext() elif is_from_parent(cls, constants.IPOPO_FACTORY_CONTEXT): # Create a copy the context context = context.copy(True) # * Manipulation has not been applied yet context.completed = False else: # Nothing special to do return context # Context has been created or copied, inject the new bean setattr(cls, constants.IPOPO_FACTORY_CONTEXT, context) return context