1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.geronimo.naming.reference;
22
23 import javax.naming.NameNotFoundException;
24
25 import org.apache.geronimo.gbean.AbstractName;
26 import org.apache.geronimo.gbean.AbstractNameQuery;
27 import org.apache.geronimo.kernel.GBeanNotFoundException;
28 import org.apache.geronimo.kernel.Kernel;
29 import org.apache.geronimo.kernel.repository.Artifact;
30
31 /**
32 * @version $Rev: 471685 $ $Date: 2006-11-06 02:35:00 -0800 (Mon, 06 Nov 2006) $
33 */
34 public class EntityManagerFactoryReference extends ConfigurationAwareReference {
35
36
37 public EntityManagerFactoryReference(Artifact configId, AbstractNameQuery abstractNameQuery) {
38 super(configId, abstractNameQuery);
39 }
40
41 public String getClassName() {
42 return "javax.persistence.EntityManagerFactory";
43 }
44
45 public Object getContent() throws NameNotFoundException {
46 Kernel kernel = getKernel();
47
48 AbstractName target;
49 try {
50 target = resolveTargetName();
51 } catch (GBeanNotFoundException e) {
52 throw (NameNotFoundException) new NameNotFoundException("Could not resolve name query: " + abstractNameQueries).initCause(e);
53 }
54
55 Object entityManagerFactory;
56 try {
57 entityManagerFactory = kernel.invoke(target, "getEntityManagerFactory");
58 } catch (Exception e) {
59 throw (IllegalStateException) new IllegalStateException("Could not get EntityManagerFactory").initCause(e);
60 }
61 if (entityManagerFactory == null) {
62 throw new IllegalStateException("entity manager not returned. Target " + target + " not started");
63 }
64 return entityManagerFactory;
65 }
66 }