org.apache.deltaspike.core.api.provider.BeanManagerProvider Java Examples
The following examples show how to use
org.apache.deltaspike.core.api.provider.BeanManagerProvider.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OutboundParameterValueRedefiner.java From deltaspike with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public Object redefineParameterValue(ParameterValue value) { CreationalContext<?> ctx = BeanManagerProvider.getInstance().getBeanManager() .createCreationalContext(declaringBean); try { if (value.getPosition() == handlerMethod.getHandlerParameter().getPosition()) { return event; } return value.getDefaultValue(ctx); } finally { if (ctx != null) { ctx.release(); } } }
Example #2
Source File: CdiTestRunner.java From deltaspike with Apache License 2.0 | 6 votes |
@Override protected Object createTest() throws Exception { BeanManager beanManager = BeanManagerProvider.getInstance().getBeanManager(); Class<?> type = getTestClass().getJavaClass(); Set<Bean<?>> beans = beanManager.getBeans(type); Object result; if (!USE_TEST_CLASS_AS_CDI_BEAN || beans == null || beans.isEmpty()) { result = super.createTest(); BeanProvider.injectFields(result); //fallback to simple injection } else { Bean<Object> bean = (Bean<Object>) beanManager.resolve(beans); CreationalContext<Object> creationalContext = beanManager.createCreationalContext(bean); result = beanManager.getReference(bean, type, creationalContext); } return result; }
Example #3
Source File: EntityManagerRefLookup.java From deltaspike with Apache License 2.0 | 6 votes |
private synchronized void initGlobalEntityManager() { // switch into paranoia mode if (this.globalEntityManagerInitialized == null) { BeanManager beanManager = BeanManagerProvider.getInstance().getBeanManager(); Set<Bean<?>> beans = beanManager.getBeans(EntityManager.class); Bean<?> bean = beanManager.resolve(beans); if (bean == null) { throw new IllegalStateException("Could not find EntityManager with default qualifier."); } globalEntityManagerIsNormalScope = beanManager.isNormalScope(bean.getScope()); if (globalEntityManagerIsNormalScope) { globalEntityManager = (EntityManager) beanManager.getReference(bean, EntityManager.class, beanManager.createCreationalContext(bean)); } this.globalEntityManagerInitialized = true; } }
Example #4
Source File: ManagedArtifactResolver.java From deltaspike with Apache License 2.0 | 5 votes |
public static Converter resolveManagedConverter(Class<? extends Converter> converterClass) { if (JAVAX_FACES_CONVERT_PACKAGE_NAME.equals(converterClass.getPackage().getName())) { return null; } return getContextualReference(BeanManagerProvider.getInstance().getBeanManager(), converterClass); }
Example #5
Source File: BeanManagerProviderTest.java From deltaspike with Apache License 2.0 | 5 votes |
@Test public void testBeanManagerProvider() throws Exception { BeanManagerProvider bmp = BeanManagerProvider.getInstance(); Assert.assertNotNull(bmp); BeanManager bm = bmp.getBeanManager(); Assert.assertNotNull(bm); }
Example #6
Source File: DynamicMBeanWrapper.java From deltaspike with Apache License 2.0 | 5 votes |
private synchronized Object instance() { final ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(classloader); try { if (instance != null) { return instance; } if (normalScope) { instance = BeanProvider.getContextualReference(clazz, qualifiers); } else { final BeanManager bm = BeanManagerProvider.getInstance().getBeanManager(); final Set<Bean<?>> beans = bm.getBeans(clazz, qualifiers); if (beans == null || beans.isEmpty()) { throw new IllegalStateException("Could not find beans for Type=" + clazz + " and qualifiers:" + Arrays.toString(qualifiers)); } final Bean<?> resolvedBean = bm.resolve(beans); final CreationalContext<?> creationalContext = bm.createCreationalContext(resolvedBean); instance = bm.getReference(resolvedBean, clazz, creationalContext); creationalContext.release(); } return instance; } finally { Thread.currentThread().setContextClassLoader(oldCl); } }
Example #7
Source File: DeltaSpikeProxyInterceptorLookup.java From deltaspike with Apache License 2.0 | 5 votes |
private List<Interceptor<?>> resolveInterceptors(Object instance, Method method) { BeanManager beanManager = BeanManagerProvider.getInstance().getBeanManager(); Annotation[] interceptorBindings = extractInterceptorBindings(beanManager, instance, method); if (interceptorBindings.length > 0) { return beanManager.resolveInterceptors(InterceptionType.AROUND_INVOKE, interceptorBindings); } return new ArrayList<>(); }
Example #8
Source File: ViewConfigAwareNavigationHandler.java From deltaspike with Apache License 2.0 | 5 votes |
private synchronized void init() { if (this.beanManager == null) { this.navigationParameterContext = BeanProvider.getContextualReference(NavigationParameterContext.class); this.viewConfigResolver = BeanProvider.getContextualReference(ViewConfigResolver.class); this.beanManager = BeanManagerProvider.getInstance().getBeanManager(); } }
Example #9
Source File: JsfSystemEventBroadcaster.java From deltaspike with Apache License 2.0 | 5 votes |
@Override public void processEvent(SystemEvent e) throws AbortProcessingException { if (!this.isActivated) { return; } BeanManager beanManager = BeanManagerProvider.getInstance().getBeanManager(); beanManager.fireEvent(e); }
Example #10
Source File: ManagedArtifactResolver.java From deltaspike with Apache License 2.0 | 5 votes |
public static Validator resolveManagedValidator(Class<? extends Validator> validatorClass) { if (JAVAX_FACES_VALIDATOR_PACKAGE_NAME.equals(validatorClass.getPackage().getName())) { return null; } return getContextualReference(BeanManagerProvider.getInstance().getBeanManager(), validatorClass); }
Example #11
Source File: DolphinContextListenerCdi.java From dolphin-platform with Apache License 2.0 | 5 votes |
@Override public void sessionDestroyed(ClientSession dolphinSession) { Assert.requireNonNull(dolphinSession, "dolphinSession"); BeanManager bm = BeanManagerProvider.getInstance().getBeanManager(); ClientScopeContext clientContext = (ClientScopeContext) bm.getContext(ClientScoped.class); clientContext.destroy(); }
Example #12
Source File: PersistenceConfigurationProviderTest.java From deltaspike with Apache License 2.0 | 5 votes |
@Test public void testPersistenceConfigurationProvider() { Properties myUnitConfig = persistenceConfigurationProvider.getEntityManagerFactoryConfiguration("MyUnit"); Assert.assertEquals(4, myUnitConfig.size()); Assert.assertEquals(BeanManagerProvider.getInstance().getBeanManager(), myUnitConfig.get("javax.persistence.bean.manager")); Assert.assertEquals("blub", myUnitConfig.get("javax.persistence.jdbc.password")); Assert.assertEquals("sa", myUnitConfig.get("javax.persistence.jdbc.user")); Assert.assertEquals("some.jdbc.Driver", myUnitConfig.get("javax.persistence.jdbc.driver")); }
Example #13
Source File: AuditEntityListener.java From deltaspike with Apache License 2.0 | 5 votes |
@PreUpdate public void update(Object entity) { BeanManager beanManager = BeanManagerProvider.getInstance().getBeanManager(); Set<Bean<?>> beans = beanManager.getBeans(PreUpdateAuditListener.class); for (Bean<?> bean : beans) { PreUpdateAuditListener result = (PreUpdateAuditListener) beanManager.getReference( bean, PreUpdateAuditListener.class, beanManager.createCreationalContext(bean)); result.preUpdate(entity); } }
Example #14
Source File: AuditEntityListener.java From deltaspike with Apache License 2.0 | 5 votes |
@PrePersist public void persist(Object entity) { BeanManager beanManager = BeanManagerProvider.getInstance().getBeanManager(); Set<Bean<?>> beans = beanManager.getBeans(PrePersistAuditListener.class); for (Bean<?> bean : beans) { PrePersistAuditListener result = (PrePersistAuditListener) beanManager.getReference( bean, PrePersistAuditListener.class, beanManager.createCreationalContext(bean)); result.prePersist(entity); } }
Example #15
Source File: EventBroadcaster.java From deltaspike with Apache License 2.0 | 5 votes |
protected BeanManager getBeanManager() { if (beanManager == null) { synchronized (this) { if (beanManager == null) { beanManager = BeanManagerProvider.getInstance().getBeanManager(); } } } return beanManager; }
Example #16
Source File: CdiTestRunner.java From deltaspike with Apache License 2.0 | 5 votes |
@Override public void evaluate() throws Throwable { BeanManager beanManager = BeanManagerProvider.getInstance().getBeanManager(); Class<?> type = this.method.getMethod().getDeclaringClass(); Set<Bean<?>> beans = beanManager.getBeans(type); if (!USE_TEST_CLASS_AS_CDI_BEAN || beans == null || beans.isEmpty()) { if (!ALLOW_INJECTION_POINT_MANIPULATION) { BeanProvider.injectFields(this.originalTarget); //fallback to simple injection } invokeMethod(this.originalTarget); } else { Bean<Object> bean = (Bean<Object>) beanManager.resolve(beans); CreationalContext<Object> creationalContext = beanManager.createCreationalContext(bean); Object target = beanManager.getReference(bean, type, creationalContext); try { invokeMethod(target); } finally { if (bean.getScope().equals(Dependent.class)) { bean.destroy(target, creationalContext); } } } }
Example #17
Source File: InfoBean.java From tomee with Apache License 2.0 | 5 votes |
public String getCdiVersion() { try { return ClassUtils.getJarVersion(BeanManagerProvider.getInstance().getBeanManager().getClass()); } catch (Exception e) { e.printStackTrace(); return "Failed to get CDI Version: " + e.getMessage(); } }
Example #18
Source File: DeltaSpikeFacesContextWrapper.java From deltaspike with Apache License 2.0 | 4 votes |
private synchronized void init() { // switch into paranoia mode if (this.initialized == null) { this.beanManager = BeanManagerProvider.getInstance().getBeanManager(); this.jsfModuleConfig = BeanProvider.getContextualReference(this.beanManager, JsfModuleConfig.class, false); if (ClassDeactivationUtils.isActivated(JsfRequestBroadcaster.class)) { this.jsfRequestBroadcaster = BeanProvider.getContextualReference(JsfRequestBroadcaster.class, true); } ViewConfigResolver viewConfigResolver = BeanProvider.getContextualReference(ViewConfigResolver.class); //deactivate it, if there is no default-error-view available this.defaultErrorViewExceptionHandlerActivated = viewConfigResolver.getDefaultErrorViewConfigDescriptor() != null && ClassDeactivationUtils.isActivated(DefaultErrorViewAwareExceptionHandlerWrapper.class); this.bridgeExceptionHandlerActivated = ClassDeactivationUtils.isActivated(BridgeExceptionHandlerWrapper.class); this.bridgeExceptionQualifier = AnnotationInstanceProvider.of(jsfModuleConfig.getExceptionQualifier()); this.preDestroyViewMapEventFilterMode = ClassDeactivationUtils.isActivated(SecurityAwareViewHandler.class); this.isNavigationAwareApplicationWrapperActivated = ClassDeactivationUtils.isActivated(NavigationHandlerAwareApplication.class); org.apache.deltaspike.core.api.projectstage.ProjectStage dsProjectStage = ProjectStageProducer.getInstance().getProjectStage(); for (ProjectStage ps : ProjectStage.values()) { if (ps.name().equals(dsProjectStage.getClass().getSimpleName())) { this.projectStage = ps; break; } } if (this.projectStage == null && dsProjectStage instanceof TestStage) { this.projectStage = ProjectStage.Development; } if (this.projectStage == ProjectStage.Production) { this.projectStage = null; //reset it to force the delegation to the default handling } this.initialized = true; } }
Example #19
Source File: InfoBean.java From tomee with Apache License 2.0 | 4 votes |
public String getDeltaSpikeVersion() { return ClassUtils.getJarVersion(BeanManagerProvider.class); }
Example #20
Source File: ContextUtils.java From deltaspike with Apache License 2.0 | 2 votes |
/** * Checks if the context for the given scope annotation is active. * * @param scopeAnnotationClass The scope annotation (e.g. @RequestScoped.class) * @return If the context is active. */ public static boolean isContextActive(Class<? extends Annotation> scopeAnnotationClass) { return isContextActive(scopeAnnotationClass, BeanManagerProvider.getInstance().getBeanManager()); }