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: // $Id: ClientMetaData.java 61248 2007-03-10 04:12:47Z thomas.diesler@jboss.com $
025:
026: import org.jboss.deployment.DeploymentException;
027: import org.jboss.metadata.serviceref.ServiceRefDelegate;
028: import org.jboss.ws.integration.ServiceRefMetaData;
029: import org.w3c.dom.Element;
030:
031: import java.util.ArrayList;
032: import java.util.HashMap;
033: import java.util.Iterator;
034: import java.net.URLClassLoader;
035:
036: /** The metdata data from a j2ee application-client.xml descriptor
037: *
038: * @author Scott.Stark@jboss.org
039: * @author Thomas.Diesler@jboss.org
040: * @version $Revision: 61248 $
041: */
042: public class ClientMetaData {
043: /** The application-client/display-name */
044: private String displayName;
045: /** The location for the server side client context ENC bindings */
046: private String jndiName;
047: /** An ArrayList<EnvEntryMetaData> for the env-entry element(s) */
048: private ArrayList environmentEntries = new ArrayList();
049: /** A HashMap<String, EjbRefMetaData> for the ejb-ref element(s) */
050: private HashMap ejbReferences = new HashMap();
051: /** The HashMap<String, ServiceRefMetaData> service-ref element(s) info */
052: private HashMap<String, ServiceRefMetaData> serviceReferences = new HashMap<String, ServiceRefMetaData>();
053: /** A HashMap<String, ResourceRefMetaData> resource-ref element(s) info */
054: private HashMap resourceReferences = new HashMap();
055: /** A HashMap<String, ResourceEnvRefMetaData> resource-env-ref element(s) info */
056: private HashMap resourceEnvReferences = new HashMap();
057: /** A HashMap<String, ArrayList<ResourceEnvRefMetaData>> of
058: * message-destination-ref that resolve to a jndi-name via a message-destination
059: * via a message-destination-link
060: */
061: private HashMap resourceEnvReferenceLinks = new HashMap();
062: /** The JAAS callback handler */
063: private String callbackHandler;
064:
065: /** The ClassLoader to load additional resources */
066: private URLClassLoader resourceCl;
067:
068: /** Set the ClassLoader to load additional resources */
069: public void setResourceClassLoader(URLClassLoader resourceCl) {
070: this .resourceCl = resourceCl;
071: }
072:
073: /** The application-client/display-name
074: * @return application-client/display-name value
075: */
076: public String getDisplayName() {
077: return displayName;
078: }
079:
080: /** The location for the server side client context ENC bindings
081: * @return the JNDI name for the server side client context ENC bindings. This
082: * is either the jboss-client/jndi-name or the application-client/display-name
083: * value.
084: */
085: public String getJndiName() {
086: String name = jndiName;
087: if (name == null)
088: name = displayName;
089: return name;
090: }
091:
092: /**
093: * @return ArrayList<EnvEntryMetaData>
094: */
095: public ArrayList getEnvironmentEntries() {
096: return environmentEntries;
097: }
098:
099: /**
100: * @return HashMap<EjbRefMetaData>
101: */
102: public HashMap getEjbReferences() {
103: return ejbReferences;
104: }
105:
106: /**
107: * @return HashMap<ResourceRefMetaData>
108: */
109: public HashMap getResourceReferences() {
110: return resourceReferences;
111: }
112:
113: /**
114: * @return HashMap<ResourceEnvRefMetaData>
115: */
116: public HashMap getResourceEnvReferences() {
117: return resourceEnvReferences;
118: }
119:
120: /**
121: * @return The CallbackHandler if defined, null otherwise
122: */
123: public String getCallbackHandler() {
124: return callbackHandler;
125: }
126:
127: /**
128: * @return HashMap<ServiceRefMetaData>
129: */
130: public HashMap<String, ServiceRefMetaData> getServiceReferences() {
131: return serviceReferences;
132: }
133:
134: public void importClientXml(Element element)
135: throws DeploymentException {
136: displayName = MetaData.getOptionalChildContent(element,
137: "display-name");
138:
139: // set the environment entries
140: Iterator iterator = MetaData.getChildrenByTagName(element,
141: "env-entry");
142:
143: while (iterator.hasNext()) {
144: Element envEntry = (Element) iterator.next();
145:
146: EnvEntryMetaData envEntryMetaData = new EnvEntryMetaData();
147: envEntryMetaData.importEjbJarXml(envEntry);
148:
149: environmentEntries.add(envEntryMetaData);
150: }
151:
152: // set the ejb references
153: iterator = MetaData.getChildrenByTagName(element, "ejb-ref");
154:
155: while (iterator.hasNext()) {
156: Element ejbRef = (Element) iterator.next();
157:
158: EjbRefMetaData ejbRefMetaData = new EjbRefMetaData();
159: ejbRefMetaData.importEjbJarXml(ejbRef);
160:
161: ejbReferences.put(ejbRefMetaData.getName(), ejbRefMetaData);
162: }
163:
164: // Parse the service-ref elements
165: iterator = MetaData
166: .getChildrenByTagName(element, "service-ref");
167: while (iterator.hasNext()) {
168: Element serviceRef = (Element) iterator.next();
169: ServiceRefMetaData refMetaData = new ServiceRefDelegate()
170: .newServiceRefMetaData();
171: refMetaData.importStandardXml(serviceRef);
172: serviceReferences.put(refMetaData.getServiceRefName(),
173: refMetaData);
174: }
175:
176: // The callback-handler element
177: Element callbackElement = MetaData.getOptionalChild(element,
178: "callback-handler");
179: if (callbackElement != null) {
180: callbackHandler = MetaData
181: .getElementContent(callbackElement);
182: }
183:
184: // set the resource references
185: iterator = MetaData.getChildrenByTagName(element,
186: "resource-ref");
187: while (iterator.hasNext()) {
188: Element resourceRef = (Element) iterator.next();
189:
190: ResourceRefMetaData resourceRefMetaData = new ResourceRefMetaData();
191: resourceRefMetaData.importEjbJarXml(resourceRef);
192:
193: resourceReferences.put(resourceRefMetaData.getRefName(),
194: resourceRefMetaData);
195: }
196:
197: // Parse the resource-env-ref elements
198: iterator = MetaData.getChildrenByTagName(element,
199: "resource-env-ref");
200: while (iterator.hasNext()) {
201: Element resourceRef = (Element) iterator.next();
202: ResourceEnvRefMetaData refMetaData = new ResourceEnvRefMetaData();
203: refMetaData.importEjbJarXml(resourceRef);
204: resourceEnvReferences.put(refMetaData.getRefName(),
205: refMetaData);
206: }
207:
208: // Parse the message-destination-ref elements
209: iterator = MetaData.getChildrenByTagName(element,
210: "message-destination-ref");
211: while (iterator.hasNext()) {
212: Element resourceRef = (Element) iterator.next();
213: ResourceEnvRefMetaData refMetaData = new ResourceEnvRefMetaData();
214: refMetaData.importEjbJarXml(resourceRef);
215: /* A message-destination-ref is linked to a jndi-name either via
216: the message-destination-ref/message-destination-ref-name mapping to
217: a jboss resource-env-ref/resource-env-ref-name if there is no
218: message-destination-link, or by the message-destination-link ->
219: message-destination/message-destination-name mapping to a jboss
220: resource-env-ref/resource-env-ref-name.
221: */
222: String refName = refMetaData.getRefName();
223: String link = refMetaData.getLink();
224: if (link != null) {
225: ArrayList linkedRefs = (ArrayList) resourceEnvReferenceLinks
226: .get(link);
227: if (linkedRefs == null) {
228: linkedRefs = new ArrayList();
229: resourceEnvReferenceLinks.put(link, linkedRefs);
230: }
231: linkedRefs.add(refMetaData);
232: }
233: resourceEnvReferences.put(refName, refMetaData);
234: }
235: }
236:
237: public void importJbossClientXml(Element element)
238: throws DeploymentException {
239: jndiName = MetaData.getOptionalChildContent(element,
240: "jndi-name");
241:
242: // Get the JNDI names of ejb-refs
243: Iterator iterator = MetaData.getChildrenByTagName(element,
244: "ejb-ref");
245: while (iterator.hasNext()) {
246: Element ejbRef = (Element) iterator.next();
247: String ejbRefName = MetaData.getElementContent(MetaData
248: .getUniqueChild(ejbRef, "ejb-ref-name"));
249: EjbRefMetaData ejbRefMetaData = (EjbRefMetaData) ejbReferences
250: .get(ejbRefName);
251: if (ejbRefMetaData == null) {
252: throw new DeploymentException(
253: "ejb-ref "
254: + ejbRefName
255: + " found in jboss-client.xml but not in application-client.xml");
256: }
257: ejbRefMetaData.importJbossXml(ejbRef);
258: }
259:
260: // Parse the service-ref elements
261: iterator = MetaData
262: .getChildrenByTagName(element, "service-ref");
263: while (iterator.hasNext()) {
264: Element serviceRef = (Element) iterator.next();
265: String serviceRefName = MetaData.getUniqueChildContent(
266: serviceRef, "service-ref-name");
267: ServiceRefMetaData refMetaData = (ServiceRefMetaData) serviceReferences
268: .get(serviceRefName);
269: if (refMetaData == null) {
270: throw new DeploymentException(
271: "service-ref "
272: + serviceRefName
273: + " found in jboss-client.xml but not in application-client.xml");
274: }
275: refMetaData.importJBossXml(serviceRef);
276: }
277:
278: // Get the JNDI name binding for resource-refs
279: iterator = MetaData.getChildrenByTagName(element,
280: "resource-ref");
281: while (iterator.hasNext()) {
282: Element resourceRef = (Element) iterator.next();
283: String resRefName = MetaData.getElementContent(MetaData
284: .getUniqueChild(resourceRef, "res-ref-name"));
285: ResourceRefMetaData resourceRefMetaData = (ResourceRefMetaData) resourceReferences
286: .get(resRefName);
287: if (resourceRefMetaData == null) {
288: throw new DeploymentException(
289: "resource-ref "
290: + resRefName
291: + " found in jboss-client.xml but not in application-client.xml");
292: }
293: resourceRefMetaData.importJbossXml(resourceRef);
294: }
295:
296: // Get the JNDI name binding resource-env-refs
297: iterator = MetaData.getChildrenByTagName(element,
298: "resource-env-ref");
299: while (iterator.hasNext()) {
300: Element resourceRef = (Element) iterator.next();
301: String resRefName = MetaData.getElementContent(MetaData
302: .getUniqueChild(resourceRef,
303: "resource-env-ref-name"));
304: ResourceEnvRefMetaData refMetaData = (ResourceEnvRefMetaData) resourceEnvReferences
305: .get(resRefName);
306: if (refMetaData == null) {
307: // Try the resourceEnvReferenceLinks
308: ArrayList linkedRefs = (ArrayList) resourceEnvReferenceLinks
309: .get(resRefName);
310: if (linkedRefs != null) {
311: for (int n = 0; n < linkedRefs.size(); n++) {
312: refMetaData = (ResourceEnvRefMetaData) linkedRefs
313: .get(n);
314: refMetaData.importJbossXml(resourceRef);
315: }
316: } else {
317: throw new DeploymentException(
318: "resource-env-ref "
319: + resRefName
320: + " found in jboss-client.xml but not in application-client.xml");
321: }
322: } else {
323: refMetaData.importJbossXml(resourceRef);
324: }
325: }
326: }
327: }
|