KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > naming > reference > EntityManagerFactoryReference


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.naming.reference;
18
19 import javax.naming.NameNotFoundException JavaDoc;
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 /**
28  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
29  */

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