KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > j2ee > appclient > ClientEjbRef


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.j2ee.appclient;
31
32 import com.caucho.config.ConfigException;
33 import com.caucho.naming.Jndi;
34 import com.caucho.naming.ObjectProxy;
35 import com.caucho.util.L10N;
36
37 import javax.annotation.PostConstruct;
38 import javax.naming.Context JavaDoc;
39 import javax.naming.NamingException JavaDoc;
40 import java.util.Hashtable JavaDoc;
41 import java.util.logging.Logger JavaDoc;
42
43 /**
44  * Configuration for the ejb-ref.
45  *
46  * An ejb-ref is used to make an ejb available within the environment
47  * in which the ejb-ref is declared.
48  */

49 public class ClientEjbRef implements ObjectProxy {
50   private static final L10N L = new L10N(ClientEjbRef.class);
51   private static final Logger JavaDoc log
52     = Logger.getLogger(ClientEjbRef.class.getName());
53
54   private Context JavaDoc _ic;
55   
56   private String JavaDoc _ejbRefName;
57   private String JavaDoc _type;
58   private Class JavaDoc _home;
59   private Class JavaDoc _remote;
60   private String JavaDoc _jndiName;
61   private String JavaDoc _ejbLink;
62
63   public ClientEjbRef(Context JavaDoc ic)
64   {
65     _ic = ic;
66   }
67
68   public void setId(String JavaDoc id)
69   {
70   }
71
72   public void setDescription(String JavaDoc description)
73   {
74   }
75
76   /**
77    * Sets the name to use in the local jndi context.
78    * This is the jndi lookup name that code uses to obtain the home for
79    * the bean when doing a jndi lookup.
80    *
81    * <pre>
82    * <ejb-ref-name>ejb/Gryffindor</ejb-ref-name>
83    * ...
84    * (new InitialContext()).lookup("java:comp/env/ejb/Gryffindor");
85    * </pre>
86    */

87   public void setEjbRefName(String JavaDoc name)
88   {
89     _ejbRefName = name;
90   }
91
92   /**
93    * Returns the ejb name.
94    */

95   public String JavaDoc getEjbRefName()
96   {
97     return _ejbRefName;
98   }
99
100   public void setEjbRefType(String JavaDoc type)
101   {
102     _type = type;
103   }
104
105   public void setHome(Class JavaDoc home)
106   {
107     _home = home;
108   }
109
110   /**
111    * Returns the home class.
112    */

113   public Class JavaDoc getHome()
114   {
115     return _home;
116   }
117
118   public void setRemote(Class JavaDoc remote)
119   {
120     _remote = remote;
121   }
122
123   /**
124    * Returns the remote class.
125    */

126   public Class JavaDoc getRemote()
127   {
128     return _remote;
129   }
130
131   /**
132    * Sets the canonical jndi name to use to find the bean that
133    * is the target of the reference.
134    * For remote beans, a &lt;jndi-link> {@link com.caucho.naming.LinkProxy} is
135    * used to link the local jndi context referred to in this name to
136    * a remote context.
137    */

138   public void setJndiName(String JavaDoc jndiName)
139   {
140     _jndiName = jndiName;
141   }
142
143   /**
144    * Set the target of the reference, an alternative to {@link #setJndiName(String)}.
145    * The format of the ejbLink is "bean", or "jarname#bean", where <i>bean</i> is the
146    * ejb-name of a bean within the same enterprise application, and <i>jarname</i>
147    * further qualifies the identity of the target.
148    */

149   public void setEjbLink(String JavaDoc ejbLink)
150   {
151     _ejbLink = ejbLink;
152   }
153
154   @PostConstruct
155   public void init()
156     throws Exception JavaDoc
157   {
158     if (_ejbRefName == null)
159       throw new ConfigException(L.l("{0} is required", "<ejb-ref-name>"));
160
161     _ejbRefName = Jndi.getFullName(_ejbRefName);
162   }
163
164   /**
165    * Creates the object from the proxy.
166    *
167    * @return the object named by the proxy.
168    */

169   public Object JavaDoc createObject(Hashtable JavaDoc env)
170     throws NamingException JavaDoc
171   {
172     return null;
173   }
174
175   public String JavaDoc toString()
176   {
177     return "ClientEjbRef[" + _ejbRefName + ", " + _ejbLink + ", " + _jndiName + "]";
178   }
179 }
180
Popular Tags