public static EntityManagerFactory lookupEntityManagerFactory(int invType,
String emfUnitName, Object descriptor) {
Application app = null;
BundleDescriptor module = null;
EntityManagerFactory emf = null;
switch (invType) {
case ComponentInvocation.EJB_INVOCATION:
EjbDescriptor ejbDesc = (EjbDescriptor) descriptor;
module = ejbDesc.getEjbBundleDescriptor();
app = module.getApplication();
break;
case ComponentInvocation.SERVLET_INVOCATION:
module = (WebBundleDescriptor) descriptor;
app = module.getApplication();
break;
case ComponentInvocation.APP_CLIENT_INVOCATION:
module = (ApplicationClientDescriptor) descriptor;
app = module.getApplication();
break;
default:
break;
}
// First check module-level for a match.
if (module != null) {
if (emfUnitName != null) {
emf = module.getEntityManagerFactory(emfUnitName);
} else {
Set<EntityManagerFactory> emFactories = module
.getEntityManagerFactories();
if (emFactories.size() == 1) {
emf = emFactories.iterator().next();
}
}