KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > naming > factory > OpenEjbFactory


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
18
19 package org.apache.naming.factory;
20
21 import org.apache.naming.EjbRef;
22
23 import javax.naming.Context JavaDoc;
24 import javax.naming.InitialContext JavaDoc;
25 import javax.naming.Name JavaDoc;
26 import javax.naming.Reference JavaDoc;
27 import javax.naming.RefAddr JavaDoc;
28 import javax.naming.spi.ObjectFactory JavaDoc;
29 import java.util.Hashtable JavaDoc;
30 import java.util.Properties JavaDoc;
31
32 /**
33  * Object factory for EJBs.
34  *
35  * @author Jacek Laskowski
36  * @author Remy Maucherat
37  * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
38  */

39 public class OpenEjbFactory implements ObjectFactory JavaDoc {
40
41
42     // -------------------------------------------------------------- Constants
43

44
45     protected static final String JavaDoc DEFAULT_OPENEJB_FACTORY =
46         "org.openejb.client.LocalInitialContextFactory";
47
48
49     // -------------------------------------------------- ObjectFactory Methods
50

51
52     /**
53      * Crete a new EJB instance using OpenEJB.
54      *
55      * @param obj The reference object describing the DataSource
56      */

57     public Object JavaDoc getObjectInstance(Object JavaDoc obj, Name JavaDoc name, Context JavaDoc nameCtx,
58                                     Hashtable JavaDoc environment)
59         throws Exception JavaDoc {
60
61         Object JavaDoc beanObj = null;
62
63         if (obj instanceof EjbRef) {
64
65             Reference JavaDoc ref = (Reference JavaDoc) obj;
66
67             String JavaDoc factory = DEFAULT_OPENEJB_FACTORY;
68             RefAddr JavaDoc factoryRefAddr = ref.get("openejb.factory");
69             if (factoryRefAddr != null) {
70                 // Retrieving the OpenEJB factory
71
factory = factoryRefAddr.getContent().toString();
72             }
73
74             Properties JavaDoc env = new Properties JavaDoc();
75             env.put(Context.INITIAL_CONTEXT_FACTORY, factory);
76
77             RefAddr JavaDoc linkRefAddr = ref.get("openejb.link");
78             if (linkRefAddr != null) {
79                 String JavaDoc ejbLink = linkRefAddr.getContent().toString();
80                 beanObj = (new InitialContext JavaDoc(env)).lookup(ejbLink);
81             }
82
83         }
84
85         return beanObj;
86
87     }
88
89
90 }
91
Popular Tags