KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > metadata > ResourceRefMetaData


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.metadata;
23
24 import org.jboss.deployment.DeploymentException;
25 import org.w3c.dom.Element JavaDoc;
26 import static org.jboss.metadata.MetaData.*;
27
28 /** The meta data information for a resource-ref element.
29  The resource-ref element contains a declaration of enterprise bean�s
30  reference to an external resource. It consists of an optional description,
31  the resource manager connection factory reference name, the
32  indication of the resource manager connection factory type expected
33  by the enterprise bean code, the type of authentication (Application
34  or Container), and an optional specification of the shareability of
35  connections obtained from the resource (Shareable or Unshareable).
36  Used in: entity, message-driven, and session
37
38  * @author <a HREF="mailto:sebastien.alborini@m4x.org">Sebastien Alborini</a>
39  * @author <a HREF="mailto:Scott.Stark@jboss.org">Scott Stark</a>.
40  * @version $Revision: 57300 $
41  */

42 public class ResourceRefMetaData extends Ref
43 {
44    // Constants -----------------------------------------------------
45

46    // Attributes ----------------------------------------------------
47
/** The ejb-jar/../resource-ref/res-ref-name element used by the bean code.
48     The res-ref-name element specifies the name of a resource manager con-nection
49     factory reference. The name is a JNDI name relative to the
50     java:comp/env context. The name must be unique within an enterprise
51     bean.
52     */

53    private String JavaDoc refName;
54    /** The jboss/../resource-ref/resource-name value that maps to a resource-manager */
55    private String JavaDoc name;
56    /** The jndi name of the deployed resource, or the URL in the case of
57     a java.net.URL resource type. This comes from either the:
58     jboss/../resource-ref/jndi-name element value or the
59     jboss/../resource-ref/res-url element value or the
60     jboss/../resource-manager/res-jndi-name element value
61     jboss/../resource-manager/res-url element value
62     */

63    private String JavaDoc jndiName;
64    private String JavaDoc resURL;
65    /** The ejb-jar/../resource-ref/res-type element.
66     The res-type element specifies the Java class or interface of the data source
67     */

68    private String JavaDoc type;
69    /** The ejb-jar/../resource-ref/res-auth value.
70     The res-auth element specifies whether the enterprise bean code signs
71     on programmatically to the resource manager, or whether the Container
72     will sign on to the resource manager on behalf of the enterprise bean.
73     In the latter case, the Container uses information that is supplied by
74     the Deployer.
75     The value of this element must be one of the following for EJB2.0,
76     Servlet 2.3:
77     <res-auth>Application</res-auth>
78     <res-auth>Container</res-auth>
79     or for Servlet 2.2:
80     <res-auth>CONTAINER</res-auth>
81     <res-auth>SERVLET</res-auth>
82     */

83    private boolean containerAuth;
84    /** The ejb-jar/../resource-ref/res-sharing-scope value
85     The res-sharing-scope element specifies whether connections obtained
86     through the given resource manager connection factory reference can
87     be shared. The value of this element, if specified, must be one of the
88     two following:
89     <res-sharing-scope>Shareable</res-sharing-scope>
90     <res-sharing-scope>Unshareable</res-sharing-scope>
91     The default value is Shareable.
92     */

93    private boolean isShareable;
94
95    // Static --------------------------------------------------------
96

97    // Constructors --------------------------------------------------
98
public ResourceRefMetaData()
99    {
100    }
101
102    // Public --------------------------------------------------------
103

104    public String JavaDoc getJndiName()
105    {
106       return jndiName;
107    }
108
109    public void setJndiName(String JavaDoc jndiName)
110    {
111       this.jndiName = jndiName;
112    }
113
114    public String JavaDoc getName()
115    {
116       return name;
117    }
118
119    public void setName(String JavaDoc name)
120    {
121       this.name = name;
122    }
123
124    public String JavaDoc getRefName()
125    {
126       return refName;
127    }
128
129    public void setRefName(String JavaDoc refName)
130    {
131       this.refName = refName;
132    }
133
134    public String JavaDoc getResURL()
135    {
136       return resURL;
137    }
138
139    public void setResURL(String JavaDoc resURL)
140    {
141       this.resURL = resURL;
142    }
143
144    public String JavaDoc getType()
145    {
146       return type;
147    }
148
149    public void setType(String JavaDoc type)
150    {
151       this.type = type;
152    }
153
154    public String JavaDoc getResourceName()
155    {
156       if (name == null)
157       {
158          // default is refName
159
name = refName;
160       }
161       return name;
162    }
163
164    public void setResourceName(String JavaDoc resName)
165    {
166       name = resName;
167    }
168
169    public boolean isContainerAuth()
170    {
171       return containerAuth;
172    }
173    public void setContainerAuth(String JavaDoc value)
174    {
175       this.containerAuth = value.equalsIgnoreCase("Container");
176    }
177    public void setContainerAuth(boolean flag)
178    {
179       this.containerAuth = flag;
180    }
181
182    public boolean isShareable()
183    {
184       return isShareable;
185    }
186    public void setSharable(String JavaDoc value)
187    {
188       this.isShareable = value.equalsIgnoreCase("Shareable");
189    }
190    public void setSharable(boolean flag)
191    {
192       this.isShareable = flag;
193    }
194
195    public void importEjbJarXml(Element JavaDoc element) throws DeploymentException
196    {
197       refName = getElementContent(getUniqueChild(element, "res-ref-name"));
198
199       type = getElementContent(getUniqueChild(element, "res-type"));
200
201       String JavaDoc auth = getElementContent(getUniqueChild(element, "res-auth"));
202       if (auth.equalsIgnoreCase("Container"))
203       {
204          containerAuth = true;
205       }
206       else if (auth.equals("Application") || auth.equals("SERVLET") )
207       {
208          containerAuth = false;
209       }
210       else
211       {
212          throw new DeploymentException("res-auth tag should be 'Container' or "
213             + "'Application' or 'SERVLET'");
214       }
215       // The res-sharing-scope element
216
String JavaDoc sharing = getElementContent(getOptionalChild(element, "res-sharing-scope"), "Shareable");
217       isShareable = sharing.equals("Shareable");
218    }
219
220    public void importJbossXml(Element JavaDoc element) throws DeploymentException
221    {
222       // Look for the resource-ref/resource-name element
223
Element JavaDoc child = getOptionalChild(element, "resource-name");
224       if (child == null)
225       {
226          if (type.equals("java.net.URL"))
227          {
228             // First look for an explict res-url
229
Element JavaDoc resUrl = getOptionalChild(element, "res-url");
230             if (resUrl != null)
231             {
232                resURL = getElementContent(resUrl);
233             }
234             else
235             {
236                Element JavaDoc name = getUniqueChild(element, "jndi-name");
237                jndiName = getElementContent(name);
238             }
239          }
240          // There must be a resource-ref/jndi-name value otherwise
241
else
242             jndiName = getElementContent(getUniqueChild(element, "jndi-name"));
243       }
244       else
245       {
246          name = getElementContent(child);
247       }
248    }
249
250    // Package protected ---------------------------------------------
251

252    // Protected -----------------------------------------------------
253

254    // Private -------------------------------------------------------
255

256    // Inner classes -------------------------------------------------
257
}
258
Popular Tags