use of com.sun.enterprise.deployment.BundleDescriptor in project Payara by payara.
the class ValidationNamingProxy method obtainBeanManager.
/**
* Obtain the BeanManagerNamingProxy from hk2, so the BeanManager can be looked up
*
* @throws NamingException
*/
private synchronized BeanManager obtainBeanManager() throws NamingException {
BeanManager beanManager = null;
// Use invocation context to find applicable BeanDeploymentArchive.
ComponentInvocation inv = invocationManager.getCurrentInvocation();
if (inv != null) {
JndiNameEnvironment componentEnv = compEnvManager.getJndiNameEnvironment(inv.getComponentId());
if (componentEnv != null) {
BundleDescriptor bundle = null;
if (componentEnv instanceof EjbDescriptor) {
bundle = (BundleDescriptor) ((EjbDescriptor) componentEnv).getEjbBundleDescriptor().getModuleDescriptor().getDescriptor();
} else if (componentEnv instanceof WebBundleDescriptor) {
bundle = (BundleDescriptor) componentEnv;
}
if (bundle != null) {
BeanDeploymentArchive bda = weldDeployer.getBeanDeploymentArchiveForBundle(bundle);
if (bda != null) {
WeldBootstrap bootstrap = weldDeployer.getBootstrapForApp(bundle.getApplication());
beanManager = bootstrap.getManager(bda);
}
}
}
}
return beanManager;
}
use of com.sun.enterprise.deployment.BundleDescriptor in project Payara by payara.
the class JCDIServiceImpl method isCurrentModuleJCDIEnabled.
@Override
public boolean isCurrentModuleJCDIEnabled() {
BundleDescriptor bundle = null;
ComponentInvocation inv = invocationManager.getCurrentInvocation();
if (inv == null) {
return false;
}
JndiNameEnvironment componentEnv = compEnvManager.getJndiNameEnvironment(inv.getComponentId());
if (componentEnv != null) {
if (componentEnv instanceof BundleDescriptor) {
bundle = (BundleDescriptor) componentEnv;
} else if (componentEnv instanceof EjbDescriptor) {
bundle = ((EjbDescriptor) componentEnv).getEjbBundleDescriptor();
}
}
return (bundle != null) ? isJCDIEnabled(bundle) : false;
}
use of com.sun.enterprise.deployment.BundleDescriptor in project Payara by payara.
the class JCDIServiceImpl method createInterceptorInstance.
/**
* @param <T> interceptor type
* @param interceptorClass The interceptor class.
* @param ejb The ejb descriptor.
* @param ejbContext The ejb jcdi context. This context is only used to store any contexts for interceptors
* not bound to the ejb. Nothing else in this context will be used in this method as they are
* most likely null.
* @param ejbInterceptors All of the ejb interceptors for the ejb.
*
* @return The interceptor instance.
*/
@Override
@SuppressWarnings("unchecked")
public <T> T createInterceptorInstance(Class<T> interceptorClass, EjbDescriptor ejb, JCDIService.JCDIInjectionContext<T> ejbContext, Set<EjbInterceptor> ejbInterceptors) {
BundleDescriptor topLevelBundleDesc = (BundleDescriptor) ejb.getEjbBundleDescriptor().getModuleDescriptor().getDescriptor();
// First get BeanDeploymentArchive for this ejb
BeanDeploymentArchive bda = getBDAForBeanClass(topLevelBundleDesc, ejb.getEjbClassName());
WeldBootstrap bootstrap = weldDeployer.getBootstrapForApp(ejb.getEjbBundleDescriptor().getApplication());
WeldManager beanManager = bootstrap.getManager(bda);
org.jboss.weld.ejb.spi.EjbDescriptor<T> ejbDesc = beanManager.getEjbDescriptor(ejb.getName());
// get or create the ejb's creational context
CreationalContext<T> creationalContext = ejbContext.getCreationalContext();
if (creationalContext == null) {
// We have to do this because interceptors are created before the ejb but in certain cases we must associate
// the interceptors with the ejb so that they are cleaned up correctly.
// And we only want to create the ejb's creational context once or we will have a memory
// leak there too.
Bean<T> bean = beanManager.getBean(ejbDesc);
creationalContext = beanManager.createCreationalContext(bean);
ejbContext.setCreationalContext(creationalContext);
}
// first see if there's an Interceptor object defined for the interceptorClass
// This happens when @Interceptor or @InterceptorBinding is used.
Interceptor<T> interceptor = findEjbInterceptor(interceptorClass, ejbInterceptors);
if (interceptor != null) {
// using the ejb's creationalContext so we don't have to do any cleanup.
// the cleanup will be handled by weld when it clean's up the ejb.
Object instance = beanManager.getReference(interceptor, interceptorClass, creationalContext);
return (T) instance;
}
// Check to see if the interceptor was defined as a Bean.
// This can happen when using @Interceptors to define the interceptors.
Set<Bean<?>> availableBeans = beanManager.getBeans(interceptorClass);
if (availableBeans != null && !availableBeans.isEmpty()) {
// using the ejb's creationalContext so we don't have to do any cleanup.
// the cleanup will be handled by weld when it clean's up the ejb.
Bean<?> interceptorBean = beanManager.resolve(availableBeans);
Object instance = beanManager.getReference(interceptorBean, interceptorClass, creationalContext);
return (T) instance;
}
// There are other interceptors like SessionBeanInterceptor that are
// defined via code and they are not beans.
// Cannot use the ejb's creationalContext.
creationalContext = beanManager.createCreationalContext(null);
AnnotatedType<T> annotatedType = beanManager.createAnnotatedType(interceptorClass);
InjectionTarget<T> it = beanManager.getInjectionTargetFactory(annotatedType).createInterceptorInjectionTarget();
T interceptorInstance = it.produce(creationalContext);
it.inject(interceptorInstance, creationalContext);
// make sure the interceptor's cdi objects get cleaned up when the ejb is cleaned up.
ejbContext.addDependentContext(new JCDIInjectionContextImpl<>(it, creationalContext, interceptorInstance));
return interceptorInstance;
}
use of com.sun.enterprise.deployment.BundleDescriptor in project Payara by payara.
the class ManagedBeanManagerImpl method createManagedBean.
public <T> T createManagedBean(Class<T> managedBeanClass, boolean invokePostConstruct) throws Exception {
ManagedBeanDescriptor managedBeanDesc = null;
try {
BundleDescriptor bundle = getBundle();
managedBeanDesc = bundle.getManagedBeanByBeanClass(managedBeanClass.getName());
} catch (Exception e) {
// OK. Can mean that it's not annotated with @ManagedBean but 299 can handle it.
}
return createManagedBean(managedBeanDesc, managedBeanClass, invokePostConstruct);
}
use of com.sun.enterprise.deployment.BundleDescriptor in project Payara by payara.
the class ManagedBeanManagerImpl method createManagedBean.
/**
* @param desc can be null if JCDI enabled bundle.
* @param managedBeanClass
* @param invokePostConstruct
* @return
* @throws Exception
*/
public <T> T createManagedBean(ManagedBeanDescriptor desc, Class<T> managedBeanClass, boolean invokePostConstruct) throws Exception {
JCDIService jcdiService = habitat.getService(JCDIService.class);
BundleDescriptor bundleDescriptor = null;
if (desc == null) {
bundleDescriptor = getBundle();
} else {
bundleDescriptor = desc.getBundleDescriptor();
}
if (bundleDescriptor == null) {
throw new IllegalStateException("Class " + managedBeanClass + " is not a valid EE ManagedBean class");
}
T callerObject = null;
if ((jcdiService != null) && jcdiService.isJCDIEnabled(bundleDescriptor)) {
// Have 299 create, inject, and call PostConstruct (if desired) on managed bean
JCDIService.JCDIInjectionContext jcdiContext = jcdiService.createManagedObject(managedBeanClass, bundleDescriptor, invokePostConstruct);
callerObject = (T) jcdiContext.getInstance();
// Need to keep track of context in order to destroy properly
Map<Object, JCDIService.JCDIInjectionContext> bundleNonManagedObjs = jcdiManagedBeanInstanceMap.get(bundleDescriptor);
bundleNonManagedObjs.put(callerObject, jcdiContext);
} else {
JavaEEInterceptorBuilder interceptorBuilder = (JavaEEInterceptorBuilder) desc.getInterceptorBuilder();
// This is the managed bean class instance
T managedBean = managedBeanClass.newInstance();
InterceptorInvoker interceptorInvoker = interceptorBuilder.createInvoker(managedBean);
// This is the object passed back to the caller.
callerObject = (T) interceptorInvoker.getProxy();
Object[] interceptorInstances = interceptorInvoker.getInterceptorInstances();
inject(managedBean, desc);
// Inject interceptor instances
for (int i = 0; i < interceptorInstances.length; i++) {
inject(interceptorInstances[i], desc);
}
interceptorInvoker.invokePostConstruct();
desc.addBeanInstanceInfo(managedBean, interceptorInvoker);
}
return callerObject;
}
Aggregations