BeanFactoryLocator bfl = ContextSingletonBeanFactoryLocator
.getInstance("red5.xml");
BeanFactoryReference bfr = bfl.useBeanFactory("red5.common");
// Create WebScope dynamically
WebScope scope = new WebScope();
IServer server = (IServer) bfr.getFactory().getBean(IServer.ID);
scope.setServer(server);
scope.setGlobalScope(server.getGlobal("default"));
// Get default Red5 context from context loader that is JettyLoader in this case
ApplicationContext appCtx = JettyLoader.getApplicationContext();
ContextLoader loader = (ContextLoader) appCtx
.getBean("context.loader");
appCtx = loader.getContext("default.context");
// Create context for the WebScope and initialize
Context scopeContext = new Context();
scopeContext.setContextPath("/");
scopeContext.setClientRegistry((IClientRegistry) appCtx
.getBean("global.clientRegistry"));
scopeContext.setMappingStrategy((IMappingStrategy) appCtx
.getBean("global.mappingStrategy"));
scopeContext.setServiceInvoker((IServiceInvoker) appCtx
.getBean("global.serviceInvoker"));
scopeContext.setScopeResolver((IScopeResolver) appCtx
.getBean("red5.scopeResolver"));
// The context needs an ApplicationContext so resources can be
// resolved
GenericWebApplicationContext webCtx = new GenericWebApplicationContext();
webCtx.setDisplayName("Automatic generated WebAppContext");
webCtx.setParent(appCtx);
webCtx.setServletContext(ContextHandler.getCurrentContext());
scopeContext.setApplicationContext(webCtx);
// Store context in scope
scope.setContext(scopeContext);
// Use default ApplicationAdapter as handler
scope.setHandler(new ApplicationAdapter());
// Make available as "/<directoryName>" and allow access from all
// hosts
scope.setContextPath(context.getContextPath());
scope.setVirtualHosts("*");
LoaderBase.setRed5ApplicationContext(context.getContextPath(), new JettyApplicationContext(context));
// Register WebScope in server
scope.register();
}
}