本文整理汇总了Java中org.apache.webbeans.config.WebBeansContext类的典型用法代码示例。如果您正苦于以下问题:Java WebBeansContext类的具体用法?Java WebBeansContext怎么用?Java WebBeansContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WebBeansContext类属于org.apache.webbeans.config包,在下文中一共展示了WebBeansContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: run
import org.apache.webbeans.config.WebBeansContext; //导入依赖的package包/类
@Test
public void run() {
WebBeansFinder.clearInstances(WebBeansUtil.getCurrentClassLoader());
final OpenWebBeansTestLifeCycle testLifecycle = new OpenWebBeansTestLifeCycle();
final WebBeansContext ctx = WebBeansContext.currentInstance();
final OpenWebBeansTestMetaDataDiscoveryService discoveryService = OpenWebBeansTestMetaDataDiscoveryService.class.cast(ctx.getScannerService());
discoveryService.deployClasses(asList(Service.class, ModelAdapter.class));
testLifecycle.startApplication(null);
try {
Jsonb jsonb = JsonbBuilder.create();
assertEquals("{\"model\":\"5\"}", jsonb.toJson(new Root(new Model(5))));
try {
AutoCloseable.class.cast(jsonb).close();
} catch (final Exception e) {
fail(e.getMessage());
}
} finally {
testLifecycle.stopApplication(null);
}
}
开发者ID:apache,项目名称:johnzon,代码行数:21,代码来源:CdiAdapterTest.java
示例2: startContainer
import org.apache.webbeans.config.WebBeansContext; //导入依赖的package包/类
protected void startContainer()
{
WebBeansFinder.clearInstances(WebBeansUtil.getCurrentClassLoader());
//Creates a new container
testLifecycle = new HAOpenWebBeansTestLifeCycle();
webBeansContext = WebBeansContext.getInstance();
//Start application
try
{
testLifecycle.startApplication(null);
}
catch (Exception e)
{
throw new WebBeansConfigurationException(e);
}
}
开发者ID:HotswapProjects,项目名称:HotswapAgent,代码行数:19,代码来源:HAAbstractUnitTest.java
示例3: beforeStopApplication
import org.apache.webbeans.config.WebBeansContext; //导入依赖的package包/类
public void beforeStopApplication(Object endObject)
{
WebBeansContext webBeansContext = getWebBeansContext();
ContextsService contextsService = webBeansContext.getContextsService();
contextsService.endContext(Singleton.class, null);
contextsService.endContext(ApplicationScoped.class, null);
contextsService.endContext(RequestScoped.class, null);
contextsService.endContext(SessionScoped.class, mockHttpSession);
ELContextStore elStore = ELContextStore.getInstance(false);
if (elStore == null)
{
return;
}
elStore.destroyELContextStore();
}
开发者ID:HotswapProjects,项目名称:HotswapAgent,代码行数:17,代码来源:HAOpenWebBeansTestLifeCycle.java
示例4: deployPojo
import org.apache.webbeans.config.WebBeansContext; //导入依赖的package包/类
private void deployPojo(final String appId, final String web, final String contextRoot, final Class<?> loadedClazz, final Application app,
final ClassLoader classLoader, final Collection<Injection> injections,
final Context context, final WebBeansContext owbCtx, final Collection<Object> additionalProviders, final ServiceConfiguration config) {
if (loadedClazz.isInterface()) {
return;
}
final String nopath = getAddress(contextRoot, loadedClazz);
final RsHttpListener listener = createHttpListener();
final RsRegistry.AddressInfo address = rsRegistry.createRsHttpListener(appId, web, listener, classLoader, nopath.substring(NOPATH_PREFIX.length() - 1), virtualHost, auth, realm);
services.add(new DeployedService(address.complete, contextRoot, loadedClazz.getName(), appId));
listener.deployPojo(classLoader, contextRoot, getFullContext(address.base, contextRoot), loadedClazz, app, injections, context, owbCtx,
additionalProviders, config);
LOGGER.info("REST Service: " + address.complete + " -> Pojo " + loadedClazz.getName());
}
开发者ID:apache,项目名称:tomee,代码行数:18,代码来源:RESTService.java
示例5: findBeanManager
import org.apache.webbeans.config.WebBeansContext; //导入依赖的package包/类
private static BeanManagerImpl findBeanManager(final AppContext ctx) {
if (ctx != null) {
if (ctx.getWebBeansContext() == null) {
return null;
}
return ctx.getWebBeansContext().getBeanManagerImpl();
}
try { // else try to find it from tccl through our SingletonService
return WebBeansContext.currentInstance().getBeanManagerImpl();
} catch (final Exception e) { // if not found IllegalStateException or a NPE can be thrown
// no-op
}
return null;
}
开发者ID:apache,项目名称:tomee,代码行数:17,代码来源:OpenEJBEnricher.java
示例6: boot
import org.apache.webbeans.config.WebBeansContext; //导入依赖的package包/类
@Override
public synchronized void boot(Map<?, ?> properties)
{
if (context == null)
{
// this immediately boots the container
final Properties p = new Properties();
p.putAll(PROPERTIES);
if (properties != null) // override with user config
{
p.putAll(properties);
}
try
{
context = new InitialContext(p);
}
catch (final NamingException e)
{
throw new RuntimeException(e);
}
beanManager = WebBeansContext.currentInstance().getBeanManagerImpl();
}
}
开发者ID:apache,项目名称:deltaspike,代码行数:26,代码来源:OpenEjbContainerControl.java
示例7: ensureRequestContextCanBeRestarted
import org.apache.webbeans.config.WebBeansContext; //导入依赖的package包/类
@Test
public void ensureRequestContextCanBeRestarted() throws Exception {
final ApplicationComposers composers = new ApplicationComposers(EnsureRequestScopeThreadLocalIsCleanUpTest.class);
composers.before(this);
final CdiAppContextsService contextsService = CdiAppContextsService.class.cast(WebBeansContext.currentInstance().getService(ContextsService.class));
final Context req1 = contextsService.getCurrentContext(RequestScoped.class);
assertNotNull(req1);
final Context session1 = contextsService.getCurrentContext(SessionScoped.class);
assertNotNull(session1);
contextsService.endContext(RequestScoped.class, null);
contextsService.startContext(RequestScoped.class, null);
final Context req2 = contextsService.getCurrentContext(RequestScoped.class);
assertNotSame(req1, req2);
final Context session2 = contextsService.getCurrentContext(SessionScoped.class);
assertSame(session1, session2);
composers.after();
assertNull(contextsService.getCurrentContext(RequestScoped.class));
assertNull(contextsService.getCurrentContext(SessionScoped.class));
}
开发者ID:apache,项目名称:tomee,代码行数:20,代码来源:EnsureRequestScopeThreadLocalIsCleanUpTest.java
示例8: newInstance
import org.apache.webbeans.config.WebBeansContext; //导入依赖的package包/类
private static <T> T newInstance(final OpenEjbConfig config, final Class<T> clazz) throws Exception {
final WebBeansContext webBeansContext = AppFinder.findAppContextOrWeb(
Thread.currentThread().getContextClassLoader(), AppFinder.WebBeansContextTransformer.INSTANCE);
if (webBeansContext == null) {
return clazz.newInstance();
}
final BeanManagerImpl beanManager = webBeansContext.getBeanManagerImpl();
if (!beanManager.isInUse()) {
return clazz.newInstance();
}
final AnnotatedType<T> annotatedType = beanManager.createAnnotatedType(clazz);
final InjectionTarget<T> it = beanManager.createInjectionTarget(annotatedType);
final CreationalContext<T> context = beanManager.createCreationalContext(null);
final T instance = it.produce(context);
it.inject(instance, context);
it.postConstruct(instance);
config.releasables.add(new Releasable<T>(context, it, instance));
return instance;
}
开发者ID:apache,项目名称:tomee,代码行数:24,代码来源:ValidatorBuilder.java
示例9: getOwbELResolver
import org.apache.webbeans.config.WebBeansContext; //导入依赖的package包/类
@Override
public ELResolver getOwbELResolver() {
WebBeansContext old = null;
boolean exit = false;
try { // just some safety around this but should be very very rare
WebBeansContext.currentInstance();
} catch (final IllegalStateException ise) {
old = ThreadSingletonServiceImpl.enter(appContext.getWebBeansContext());
exit = true;
}
try {
return new WebBeansELResolver();
} finally {
if (exit) {
ThreadSingletonServiceImpl.exit(old);
}
}
}
开发者ID:apache,项目名称:tomee,代码行数:19,代码来源:CustomELAdapter.java
示例10: contextEntered
import org.apache.webbeans.config.WebBeansContext; //导入依赖的package包/类
@Override
public void contextEntered(final ThreadContext oldContext, final ThreadContext newContext) {
final BeanContext beanContext = newContext.getBeanContext();
if (beanContext == null) { // OWBContextHolder will be null so calling contextExited will throw a NPE
return;
}
final ModuleContext moduleContext = beanContext.getModuleContext();
//TODO its not clear what the scope for one of these context should be: ejb, module, or app
//For now, go with the attachment of the BeanManager to AppContext
final AppContext appContext = moduleContext.getAppContext();
final WebBeansContext owbContext = appContext.getWebBeansContext();
final Object oldOWBContext;
if (owbContext != null) {
oldOWBContext = singletonService.contextEntered(owbContext);
} else {
oldOWBContext = null;
}
final OWBContextHolder holder = new OWBContextHolder(oldOWBContext);
newContext.set(OWBContextHolder.class, holder);
}
开发者ID:apache,项目名称:tomee,代码行数:21,代码来源:OWBContextThreadListener.java
示例11: contextEntered
import org.apache.webbeans.config.WebBeansContext; //导入依赖的package包/类
@Override
public void contextEntered(final ThreadContext oldContext, final ThreadContext newContext) {
final BeanContext beanContext = newContext.getBeanContext();
final WebBeansContext webBeansContext = beanContext.getModuleContext().getAppContext().getWebBeansContext();
if (webBeansContext == null) {
return;
}
final ContextsService contextsService = webBeansContext.getContextsService();
final Context requestContext = CdiAppContextsService.class.cast(contextsService).getRequestContext(false);
if (requestContext == null) {
contextsService.startContext(RequestScoped.class, CdiAppContextsService.EJB_REQUEST_EVENT);
newContext.set(DestroyContext.class, new DestroyContext(contextsService, newContext));
}
}
开发者ID:apache,项目名称:tomee,代码行数:20,代码来源:RequestScopedThreadContextListener.java
示例12: setWebBeansContext
import org.apache.webbeans.config.WebBeansContext; //导入依赖的package包/类
public void setWebBeansContext(final WebBeansContext webBeansContext) {
this.webBeansContext = webBeansContext;
if (webBeansContext == null) {
return;
}
if (!WebappWebBeansContext.class.isInstance(webBeansContext)) {
cacheProxies = new ConcurrentHashMap<Contextual<?>, Object>();
} else { // share cache of proxies between the whole app otherwise hard to share an EJB between a webapp and the lib part of the app
final WebBeansContext parent = WebappWebBeansContext.class.cast(webBeansContext).getParent();
if (parent != null) {
cacheProxies = CdiPlugin.class.cast(parent.getPluginLoader().getEjbPlugin()).cacheProxies;
} else {
cacheProxies = new ConcurrentHashMap<Contextual<?>, Object>();
}
}
}
开发者ID:apache,项目名称:tomee,代码行数:17,代码来源:CdiPlugin.java
示例13: get
import org.apache.webbeans.config.WebBeansContext; //导入依赖的package包/类
/**
* Generally contexts.get() is enough since we set the current context from a request (see webbeanslistener)
* but sometimes matching the classloader is better (manager webapps of tomcat deploys for instance)
* so here the algorithm:
* 1) try to match with the classloader
* 2) if not matched try to use the threadlocal
* 3) (shouldn't happen) simply return the biggest webbeancontext
*
* @param cl the key (generally TCCL)
* @return the webbeancontext matching the current context
*/
public static WebBeansContext get(final ClassLoader cl) {
WebBeansContext context = contextByClassLoader.get(cl);
if (context != null) {
return context;
}
context = AppFinder.findAppContextOrWeb(cl, AppFinder.WebBeansContextTransformer.INSTANCE);
if (context == null) {
context = contexts.get();
if (context == null) { // any "guess" algortithm there would break prod apps cause AppFinder failed already, let's try to not try to be more clever than we can
throw new IllegalStateException("On a thread without an initialized context nor a classloader mapping a deployed app");
}
} else { // some cache to avoid to browse each app each time
contextByClassLoader.put(cl, context);
}
return context;
}
开发者ID:apache,项目名称:tomee,代码行数:30,代码来源:ThreadSingletonServiceImpl.java
示例14: shouldInjectAlternative
import org.apache.webbeans.config.WebBeansContext; //导入依赖的package包/类
@Test
public void shouldInjectAlternative() {
System.out.printf("java.class.path=%s\n", System.getProperty("java.class.path"));
System.out.printf("java.home=%s\n", System.getProperty("java.home"));
System.out.printf("user.dir=%s\n", System.getProperty("user.dir"));
final ContainerLifecycle lifecycle = WebBeansContext.getInstance().getService(ContainerLifecycle.class);
lifecycle.startApplication(this);
final BeanManager beanManager = lifecycle.getBeanManager();
final Bean<?> bean = beanManager.getBeans(FoodProcessor.class).iterator().next();
foodProcessor = (FoodProcessor) beanManager.getReference(bean, FoodProcessor.class, beanManager.createCreationalContext(bean));
assertNotNull(foodProcessor);
assertEquals("Xenonique", foodProcessor.sayBrand());
lifecycle.stopApplication(this);
}
开发者ID:peterpilgrim,项目名称:javaee7-developer-handbook,代码行数:21,代码来源:AlternativesFoodProcessorOWBTest.java
示例15: getConstructorInjectionBean
import org.apache.webbeans.config.WebBeansContext; //导入依赖的package包/类
private ConstructorInjectionBean<Object> getConstructorInjectionBean(final Class beanClass, final WebBeansContext webBeansContext) {
if (webBeansContext == null) {
return null;
}
ConstructorInjectionBean<Object> beanDefinition = constructorInjectionBeanCache.get(beanClass);
if (beanDefinition == null) {
synchronized (this) {
beanDefinition = constructorInjectionBeanCache.get(beanClass);
if (beanDefinition == null) {
final AnnotatedType annotatedType = webBeansContext.getAnnotatedElementFactory().newAnnotatedType(beanClass);
if (isWeb(beanClass)) {
beanDefinition = new ConstructorInjectionBean<>(webBeansContext, beanClass, annotatedType, false);
} else {
beanDefinition = new ConstructorInjectionBean<>(webBeansContext, beanClass, annotatedType);
}
constructorInjectionBeanCache.put(beanClass, beanDefinition);
}
}
}
return beanDefinition;
}
开发者ID:apache,项目名称:tomee,代码行数:24,代码来源:WebContext.java
示例16: createTest
import org.apache.webbeans.config.WebBeansContext; //导入依赖的package包/类
@Override
protected Object createTest() throws Exception {
SLF4JBridgeHandler.install();
final WebBeansContext context = WebBeansContext.currentInstance();
final ContainerLifecycle lifecycle = context.getService(ContainerLifecycle.class);
lifecycle.startApplication(null);
return CDI.current().select(getTestClass().getJavaClass()).get();
}
开发者ID:Microbule,项目名称:microbule,代码行数:9,代码来源:CdiTestRunner.java
示例17: doRecreateProxy
import org.apache.webbeans.config.WebBeansContext; //导入依赖的package包/类
private static void doRecreateProxy(ClassLoader appClassLoader, Class<?> beanClass) {
ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
try {
ProxyClassLoadingDelegate.beginProxyRegeneration();
Thread.currentThread().setContextClassLoader(appClassLoader);
WebBeansContext wbc = WebBeansContext.currentInstance();
NormalScopeProxyFactory proxyFactory = wbc.getNormalScopeProxyFactory();
// Clear proxy class cache
Map cachedProxyClasses = (Map) ReflectionHelper.get(proxyFactory, "cachedProxyClasses");
Set<Bean<?>> beans = wbc.getBeanManagerImpl().getBeans(beanClass);
if (beans != null) {
boolean recreateIt = false;
for (Bean<?> bean : beans) {
if (cachedProxyClasses.containsKey(bean)) {
cachedProxyClasses.remove(bean);
recreateIt = true;
}
}
if (recreateIt) {
proxyFactory.createProxyClass(appClassLoader, beanClass);
}
}
} catch (Exception e) {
LOGGER.error("Proxy redefinition failed {}.", e, e.getMessage());
} finally {
Thread.currentThread().setContextClassLoader(oldContextClassLoader);
ProxyClassLoadingDelegate.endProxyRegeneration();
}
}
开发者ID:HotswapProjects,项目名称:HotswapAgent,代码行数:35,代码来源:ProxyRefreshAgent.java
示例18: beforeStartApplication
import org.apache.webbeans.config.WebBeansContext; //导入依赖的package包/类
public void beforeStartApplication(Object object)
{
WebBeansContext webBeansContext = getWebBeansContext();
ContextsService contextsService = webBeansContext.getContextsService();
contextsService.startContext(Singleton.class, null);
contextsService.startContext(ApplicationScoped.class, null);
}
开发者ID:HotswapProjects,项目名称:HotswapAgent,代码行数:8,代码来源:HAOpenWebBeansTestLifeCycle.java
示例19: beanManager
import org.apache.webbeans.config.WebBeansContext; //导入依赖的package包/类
private BeanManager beanManager() {
final WebBeansContext webBeansContext = WebBeansContext.currentInstance();
if (webBeansContext == null) {
return null; // too early to have a cdi bean
}
return webBeansContext.getBeanManagerImpl();
}
开发者ID:apache,项目名称:tomee,代码行数:8,代码来源:CdiEventRealm.java
示例20: getWebBeansContext
import org.apache.webbeans.config.WebBeansContext; //导入依赖的package包/类
private WebBeansContext getWebBeansContext(final ContextInfo contextInfo) {
final AppContext appContext = getContainerSystem().getAppContext(contextInfo.appInfo.appId);
if (appContext == null) {
return null;
}
WebBeansContext webBeansContext = appContext.getWebBeansContext();
if (webBeansContext == null) {
return null;
}
for (final WebContext web : appContext.getWebContexts()) {
final String stdName = removeFirstSlashAndWar(contextInfo.standardContext.getName());
if (stdName == null) {
continue;
}
final String name = removeFirstSlashAndWar(web.getContextRoot());
if (stdName.equals(name)) {
webBeansContext = web.getWebbeansContext();
if (Contexts.getHostname(contextInfo.standardContext).equals(web.getHost())) {
break;
} // else loop hoping to find a better matching
}
}
if (webBeansContext == null) {
webBeansContext = appContext.getWebBeansContext();
}
return webBeansContext;
}
开发者ID:apache,项目名称:tomee,代码行数:35,代码来源:TomcatWebAppBuilder.java
注:本文中的org.apache.webbeans.config.WebBeansContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论