1 17 package org.apache.geronimo.naming.reference; 18 19 import javax.naming.NameNotFoundException ; 20 21 import org.apache.geronimo.gbean.AbstractName; 22 import org.apache.geronimo.gbean.AbstractNameQuery; 23 import org.apache.geronimo.kernel.GBeanNotFoundException; 24 import org.apache.geronimo.kernel.Kernel; 25 import org.apache.geronimo.kernel.repository.Artifact; 26 27 30 public class EntityManagerFactoryReference extends ConfigurationAwareReference { 31 32 33 public EntityManagerFactoryReference(Artifact configId, AbstractNameQuery abstractNameQuery) { 34 super(configId, abstractNameQuery); 35 } 36 37 public String getClassName() { 38 return "javax.persistence.EntityManagerFactory"; 39 } 40 41 public Object getContent() throws NameNotFoundException { 42 Kernel kernel = getKernel(); 43 44 AbstractName target; 45 try { 46 target = resolveTargetName(); 47 } catch (GBeanNotFoundException e) { 48 throw (NameNotFoundException ) new NameNotFoundException ("Could not resolve name query: " + abstractNameQueries).initCause(e); 49 } 50 51 Object entityManagerFactory; 52 try { 53 entityManagerFactory = kernel.invoke(target, "getEntityManagerFactory"); 54 } catch (Exception e) { 55 throw (IllegalStateException ) new IllegalStateException ("Could not get EntityManagerFactory").initCause(e); 56 } 57 if (entityManagerFactory == null) { 58 throw new IllegalStateException ("entity manager not returned. Target " + target + " not started"); 59 } 60 return entityManagerFactory; 61 } 62 } 63 | Popular Tags |