001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.metadata;
023:
024: import org.w3c.dom.Element;
025:
026: import org.jboss.deployment.DeploymentException;
027:
028: /** The meta data information for a resource-ref element.
029: The resource-ref element contains a declaration of enterprise bean�s
030: reference to an external resource. It consists of an optional description,
031: the resource manager connection factory reference name, the
032: indication of the resource manager connection factory type expected
033: by the enterprise bean code, the type of authentication (Application
034: or Container), and an optional specification of the shareability of
035: connections obtained from the resource (Shareable or Unshareable).
036: Used in: entity, message-driven, and session
037:
038: * @author <a href="mailto:sebastien.alborini@m4x.org">Sebastien Alborini</a>
039: * @author <a href="mailto:Scott.Stark@jboss.org">Scott Stark</a>.
040: * @version $Revision: 57209 $
041: */
042: public class ResourceRefMetaData extends MetaData {
043: // Constants -----------------------------------------------------
044:
045: // Attributes ----------------------------------------------------
046: /** The ejb-jar/../resource-ref/res-ref-name element used by the bean code.
047: The res-ref-name element specifies the name of a resource manager con-nection
048: factory reference. The name is a JNDI name relative to the
049: java:comp/env context. The name must be unique within an enterprise
050: bean.
051: */
052: private String refName;
053: /** The jboss/../resource-ref/resource-name value that maps to a resource-manager */
054: private String name;
055: /** The jndi name of the deployed resource, or the URL in the case of
056: a java.net.URL resource type. This comes from either the:
057: jboss/../resource-ref/jndi-name element value or the
058: jboss/../resource-ref/res-url element value or the
059: jboss/../resource-manager/res-jndi-name element value
060: jboss/../resource-manager/res-url element value
061: */
062: private String jndiName;
063: private String resURL;
064: /** The ejb-jar/../resource-ref/res-type element.
065: The res-type element specifies the Java class or interface of the data source
066: */
067: private String type;
068: /** The ejb-jar/../resource-ref/res-auth value.
069: The res-auth element specifies whether the enterprise bean code signs
070: on programmatically to the resource manager, or whether the Container
071: will sign on to the resource manager on behalf of the enterprise bean.
072: In the latter case, the Container uses information that is supplied by
073: the Deployer.
074: The value of this element must be one of the following for EJB2.0,
075: Servlet 2.3:
076: <res-auth>Application</res-auth>
077: <res-auth>Container</res-auth>
078: or for Servlet 2.2:
079: <res-auth>CONTAINER</res-auth>
080: <res-auth>SERVLET</res-auth>
081: */
082: private boolean containerAuth;
083: /** The ejb-jar/../resource-ref/res-sharing-scope value
084: The res-sharing-scope element specifies whether connections obtained
085: through the given resource manager connection factory reference can
086: be shared. The value of this element, if specified, must be one of the
087: two following:
088: <res-sharing-scope>Shareable</res-sharing-scope>
089: <res-sharing-scope>Unshareable</res-sharing-scope>
090: The default value is Shareable.
091: */
092: private boolean isShareable;
093:
094: // Static --------------------------------------------------------
095:
096: // Constructors --------------------------------------------------
097: public ResourceRefMetaData() {
098: }
099:
100: // Public --------------------------------------------------------
101:
102: public String getRefName() {
103: return refName;
104: }
105:
106: public String getResourceName() {
107: if (name == null) {
108: // default is refName
109: name = refName;
110: }
111: return name;
112: }
113:
114: public void setResourceName(String resName) {
115: name = resName;
116: }
117:
118: public String getJndiName() {
119: return jndiName;
120: }
121:
122: public String getResURL() {
123: return resURL;
124: }
125:
126: public String getType() {
127: return type;
128: }
129:
130: public boolean isContainerAuth() {
131: return containerAuth;
132: }
133:
134: public boolean isShareable() {
135: return isShareable;
136: }
137:
138: public void importEjbJarXml(Element element)
139: throws DeploymentException {
140: refName = getElementContent(getUniqueChild(element,
141: "res-ref-name"));
142:
143: type = getElementContent(getUniqueChild(element, "res-type"));
144:
145: String auth = getElementContent(getUniqueChild(element,
146: "res-auth"));
147: if (auth.equalsIgnoreCase("Container")) {
148: containerAuth = true;
149: } else if (auth.equals("Application") || auth.equals("SERVLET")) {
150: containerAuth = false;
151: } else {
152: throw new DeploymentException(
153: "res-auth tag should be 'Container' or "
154: + "'Application' or 'SERVLET'");
155: }
156: // The res-sharing-scope element
157: String sharing = getElementContent(getOptionalChild(element,
158: "res-sharing-scope"), "Shareable");
159: isShareable = sharing.equals("Shareable");
160: }
161:
162: public void importJbossXml(Element element)
163: throws DeploymentException {
164: // Look for the resource-ref/resource-name element
165: Element child = getOptionalChild(element, "resource-name");
166: if (child == null) {
167: if (type.equals("java.net.URL")) {
168: // First look for an explict res-url
169: Element resUrl = getOptionalChild(element, "res-url");
170: if (resUrl != null) {
171: resURL = getElementContent(resUrl);
172: } else {
173: Element name = getUniqueChild(element, "jndi-name");
174: jndiName = getElementContent(name);
175: }
176: }
177: // There must be a resource-ref/jndi-name value otherwise
178: else
179: jndiName = getElementContent(getUniqueChild(element,
180: "jndi-name"));
181: } else {
182: name = getElementContent(child);
183: }
184: }
185:
186: // Package protected ---------------------------------------------
187:
188: // Protected -----------------------------------------------------
189:
190: // Private -------------------------------------------------------
191:
192: // Inner classes -------------------------------------------------
193: }
|