ManagedObject managedObject = ((ManagedObjectAddedEvent) event).getManagedObject();
if (managedObject instanceof ManagedPortletContainer) {
ManagedPortletContainer managedPortletContainer = (ManagedPortletContainer) managedObject;
PortletApplication portletApp = managedPortletContainer.getManagedPortletApplication().getPortletApplication();
createMetaData(managedPortletContainer.getId(), portletApp);
} else if (managedObject instanceof ManagedPortletFilter) {
ManagedPortletFilter managedPortletFilter = (ManagedPortletFilter) managedObject;
PortletApplication portletApp = managedPortletFilter.getManagedPortletApplication().getPortletApplication();
createMetaData(managedPortletFilter.getId(), portletApp);
}
} else if (event instanceof ManagedObjectLifeCycleEvent) {
ManagedObjectLifeCycleEvent lifeCycleEvent = (ManagedObjectLifeCycleEvent) event;
ManagedObject managedObject = lifeCycleEvent.getManagedObject();
LifeCycleStatus status = lifeCycleEvent.getStatus();
if (managedObject instanceof ManagedPortletContainer) {
if (LifeCycleStatus.STARTED == status || LifeCycleStatus.INITIALIZED == status) {
return;
}
ManagedPortletContainer managedPortletContainer = (ManagedPortletContainer) managedObject;
CDIMetaData cdiMetaData = cdiMetaDataMap.get(managedPortletContainer.getId());
if (!cdiMetaData.cdiInjectionEnabled) {
return;
}
Portlet portlet = managedPortletContainer.getPortletInstance();
if (null != portlet) {
if (null != portlet.getClass() && "javax.portlet.faces.GenericFacesPortlet".equals(portlet.getClass().getName())) {
// Only perform injection on non JSF portlets
cdiMetaData.cdiInjectionEnabled = false;
cdiMetaDataMap.put(cdiMetaData.key, cdiMetaData);
return;
}
PortletApplication portletApp = managedPortletContainer.getManagedPortletApplication().getPortletApplication();
if (!cdiMetaData.injectionPerformed) {
performInjection(portlet, cdiMetaData, portletApp.getContext().getServletContext());
} else {
performCleanup(portlet, cdiMetaData, portletApp.getContext().getServletContext());
}
}
} else if (managedObject instanceof ManagedPortletFilter) {
if (LifeCycleStatus.INITIALIZED == status) {
return;
}
ManagedPortletFilter managedPortletFilter = (ManagedPortletFilter) managedObject;
CDIMetaData cdiMetaData = cdiMetaDataMap.get(managedPortletFilter.getId());
if (!cdiMetaData.cdiInjectionEnabled) {
return;
}
PortletFilterImpl portletFilterImpl = (PortletFilterImpl) managedPortletFilter.getPortletFilter();
PortletFilter portletFilterInstance;
for (Class type : filterClasses) {
portletFilterInstance = (PortletFilter) portletFilterImpl.instance(type);
if (null != portletFilterInstance) {
PortletApplication portletApp = managedPortletFilter.getManagedPortletApplication().getPortletApplication();
if (LifeCycleStatus.STARTED == status && !cdiMetaData.injectionPerformed) {
performInjection(portletFilterInstance, cdiMetaData, portletApp.getContext().getServletContext());
} else if (LifeCycleStatus.CREATED == status && cdiMetaData.injectionPerformed) {
performCleanup(portletFilterInstance, cdiMetaData, portletApp.getContext().getServletContext());
}
break;
}
}