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;
}
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);
}
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;
}
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);
}
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();
}
Aggregations