Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.codehaus.waffle.testing.registrar;
 
Registrar helper class. Retrieves controller instances registered in a Registrar and allows the registration of all the components in a given context level.

Author(s):
Mauro Talevi
public class RegistrarHelper {

    
Returns the registered controller

Parameters:
registrarType the Class representing the registrar type
level the ContextLevel
path the path under which the controller is registered
Returns:
The controller instance or null if not found
    public Object controllerFor(Class<?> registrarTypeContextLevel levelString path) {
        DefaultPicoContainer registrarContainer = new DefaultPicoContainer();
        registerComponentsFor(registrarTypelevelregistrarContainer);
        return registrarContainer.getComponentInstance(path);
    }

    
Registers the components for the given registrar and level

Parameters:
registrarType the Class representing the registrar type
level the ContextLevel
    public void componentsFor(Class<?> registrarTypeContextLevel level) {
        registerComponentsFor(registrarTypelevelnew DefaultPicoContainer());
    }
    private void registerComponentsFor(Class<?> registrarTypeContextLevel level,
            DefaultPicoContainer registrarContainer) {
        Registrar registrar = createRegistrar(registrarContainerregistrarType);
        switch (level) {
            case :
                registrar.application();
                break;
            case :
                registrar.session();
                break;
            case :
                registrar.request();
                break;
        }
    }
    private Registrar createRegistrar(DefaultPicoContainer containerClass<?> type) {
        String name = type.getName();
        try {
            DefaultPicoContainer initContainer = new DefaultPicoContainer();
            initContainer.registerComponentInstance(container);
            initContainer.registerComponentImplementation(NullComponentMonitor.class);
            initContainer.registerComponentImplementation(PicoLifecycleStrategy.class);
            initContainer.registerComponentImplementation(SilentMonitor.class);
            initContainer.registerComponentImplementation(PicoRegistrar.class);
            initContainer.registerComponentImplementation(DefaultParameterResolver.class);
            initContainer.registerComponentImplementation(DefaultStringTransmuter.class);
            initContainer.registerComponentImplementation(OgnlValueConverterFinder.class);
            initContainer.registerComponentImplementation(name, Class.forName(name));
            return (RegistrarinitContainer.getComponentInstance(name);
        } catch (Exception e) {
            throw new RuntimeException("Failed to create Registrar for " + namee);
        }
    }
New to GrepCode? Check out our FAQ X