* @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);