private ComponentFactory buildComponentFactory(DefaultPicoContainer container, final ComponentFactory lastCaf) {
Object componentFactory = componentFactories.pop();
DefaultPicoContainer tmpContainer = new TransientPicoContainer(container);
tmpContainer.addComponent("componentFactory", componentFactory);
if (lastCaf != null) {
tmpContainer.addComponent(ComponentFactory.class, lastCaf);
}
ComponentFactory newlastCaf = (ComponentFactory) tmpContainer.getComponent("componentFactory");
if (newlastCaf instanceof BehaviorFactory) {
((BehaviorFactory) newlastCaf).wrap(lastCaf);
}