Search in sources :

Example 1 with RegistryBuilder

use of org.apache.tapestry5.ioc.RegistryBuilder in project tapestry-5 by apache.

the class TestRegistryManager method getOrCreateRegistry.

/**
 * Get the existing registry or create one if required.
 * @return The test Registry
 * @throws Exception
 */
public org.apache.tapestry5.ioc.Registry getOrCreateRegistry() throws Exception {
    if (registry == null) {
        RegistryBuilder builder = new RegistryBuilder();
        if (annotation.modules() != null) {
            builder.add(annotation.modules());
        }
        for (Method moduleDefFactory : moduleDefFactories) {
            try {
                org.apache.tapestry5.ioc.def.ModuleDef moduleDef = (org.apache.tapestry5.ioc.def.ModuleDef) moduleDefFactory.invoke(null);
                builder.add(moduleDef);
            } catch (InvocationTargetException e) {
                if (e.getTargetException() instanceof Exception) {
                    throw (Exception) e.getTargetException();
                }
                throw e;
            }
        }
        registry = builder.build();
        registry.performRegistryStartup();
    }
    return registry;
}
Also used : RegistryBuilder(org.apache.tapestry5.ioc.RegistryBuilder) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with RegistryBuilder

use of org.apache.tapestry5.ioc.RegistryBuilder in project tapestry-5 by apache.

the class JpaTest method setupRegistry.

// @BeforeSuite
public final void setupRegistry() {
    RegistryBuilder builder = new RegistryBuilder();
    builder.add(TapestryModule.class);
    builder.add(JpaModule.class);
    builder.add(JpaTestModule.class);
    registry = builder.build();
    // set PageTesterContext, otherwise T5 tries to load classpath assets
    ApplicationGlobals globals = registry.getObject(ApplicationGlobals.class, null);
    globals.storeContext(new PageTesterContext(""));
    registry.performRegistryStartup();
    entityManagerManager = registry.getService(EntityManagerManager.class);
    topLevelService = registry.getService(TopLevelService.class);
}
Also used : PageTesterContext(org.apache.tapestry5.internal.test.PageTesterContext) EntityManagerManager(org.apache.tapestry5.jpa.EntityManagerManager) RegistryBuilder(org.apache.tapestry5.ioc.RegistryBuilder) ApplicationGlobals(org.apache.tapestry5.http.services.ApplicationGlobals)

Example 3 with RegistryBuilder

use of org.apache.tapestry5.ioc.RegistryBuilder in project tapestry-5 by apache.

the class RegistryBuilder method add.

/**
 * Adds a number of modules (as module classes) to the registry, returning the builder for further configuration.
 *
 * @see org.apache.tapestry5.ioc.annotations.ImportModule
 */
public RegistryBuilder add(Class... moduleClasses) {
    lock.check();
    List<Class> queue = CollectionFactory.newList(Arrays.asList(moduleClasses));
    while (!queue.isEmpty()) {
        Class c = queue.remove(0);
        if (addedModuleClasses.contains(c))
            continue;
        addedModuleClasses.add(c);
        logger.info("Adding module definition for " + c);
        ModuleDef def = new DefaultModuleDefImpl(c, logger, proxyFactory);
        add(def);
        @SuppressWarnings("RedundantCast") AnnotatedElement element = (AnnotatedElement) c;
        SubModule subModule = element.getAnnotation(SubModule.class);
        if (subModule != null) {
            queue.addAll(Arrays.asList(subModule.value()));
        }
        ImportModule importModule = element.getAnnotation(ImportModule.class);
        if (importModule != null) {
            queue.addAll(Arrays.asList(importModule.value()));
        }
    }
    return this;
}
Also used : SubModule(org.apache.tapestry5.ioc.annotations.SubModule) DefaultModuleDefImpl(org.apache.tapestry5.ioc.internal.DefaultModuleDefImpl) ModuleDef(org.apache.tapestry5.ioc.def.ModuleDef) AnnotatedElement(java.lang.reflect.AnnotatedElement) ImportModule(org.apache.tapestry5.ioc.annotations.ImportModule)

Example 4 with RegistryBuilder

use of org.apache.tapestry5.ioc.RegistryBuilder in project tapestry-5 by apache.

the class ComponentInstantiatorSourceImplTest method setup_tests.

@BeforeClass
public void setup_tests() throws Exception {
    helper = new ClassCreationHelper();
    File extraClasspath = new File(helper.tempDir);
    extraClasspath.mkdirs();
    URL url = extraClasspath.toURL();
    URLClassLoader extraLoader = new URLClassLoader(new URL[] { url }, Thread.currentThread().getContextClassLoader());
    RegistryBuilder builder = new RegistryBuilder(extraLoader);
    builder.add(TapestryModule.class, ForceDevelopmentModeModule.class, AddTransformPagesToCISModule.class);
    registry = builder.build();
    source = registry.getService(ComponentInstantiatorSource.class);
}
Also used : URLClassLoader(java.net.URLClassLoader) RegistryBuilder(org.apache.tapestry5.ioc.RegistryBuilder) File(java.io.File) URL(java.net.URL) BeforeClass(org.testng.annotations.BeforeClass)

Example 5 with RegistryBuilder

use of org.apache.tapestry5.ioc.RegistryBuilder in project spock by spockframework.

the class TapestryInterceptor method createAndStartupRegistry.

private void createAndStartupRegistry() {
    if (registry != null)
        return;
    RegistryBuilder builder = new RegistryBuilder();
    builder.add(ExtensionModule.class);
    for (Class<?> module : modules) builder.add(module);
    registry = builder.build();
    registry.performRegistryStartup();
}
Also used : RegistryBuilder(org.apache.tapestry5.ioc.RegistryBuilder)

Aggregations

RegistryBuilder (org.apache.tapestry5.ioc.RegistryBuilder)7 File (java.io.File)1 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 ApplicationGlobals (org.apache.tapestry5.http.services.ApplicationGlobals)1 PageTesterContext (org.apache.tapestry5.internal.test.PageTesterContext)1 ImportModule (org.apache.tapestry5.ioc.annotations.ImportModule)1 SubModule (org.apache.tapestry5.ioc.annotations.SubModule)1 ModuleDef (org.apache.tapestry5.ioc.def.ModuleDef)1 DefaultModuleDefImpl (org.apache.tapestry5.ioc.internal.DefaultModuleDefImpl)1 EntityManagerManager (org.apache.tapestry5.jpa.EntityManagerManager)1 BeforeClass (org.testng.annotations.BeforeClass)1 BeforeSuite (org.testng.annotations.BeforeSuite)1