001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer(s): Philippe Coq
022: * --------------------------------------------------------------------------
023: * $Id: JndiEnvRefsGroupDesc.java 5875 2004-12-08 13:36:20Z sauthieg $
024: * --------------------------------------------------------------------------
025: */package org.objectweb.jonas_lib.deployment.api;
026:
027: // import java
028: import java.util.HashMap;
029: import java.util.Iterator;
030: import java.util.List;
031: import java.util.Map;
032: import java.util.Set;
033: import java.util.Vector;
034:
035: import org.objectweb.jonas_lib.deployment.xml.EjbLocalRef;
036: import org.objectweb.jonas_lib.deployment.xml.EjbRef;
037: import org.objectweb.jonas_lib.deployment.xml.EnvEntry;
038: import org.objectweb.jonas_lib.deployment.xml.JndiEnvRefsGroupXml;
039: import org.objectweb.jonas_lib.deployment.xml.JonasEjbRef;
040: import org.objectweb.jonas_lib.deployment.xml.JonasJndiEnvRefsGroupXml;
041: import org.objectweb.jonas_lib.deployment.xml.JonasMessageDestinationRef;
042: import org.objectweb.jonas_lib.deployment.xml.JonasResource;
043: import org.objectweb.jonas_lib.deployment.xml.JonasResourceEnv;
044: import org.objectweb.jonas_lib.deployment.xml.JonasServiceRef;
045: import org.objectweb.jonas_lib.deployment.xml.MessageDestinationRef;
046: import org.objectweb.jonas_lib.deployment.xml.ResourceEnvRef;
047: import org.objectweb.jonas_lib.deployment.xml.ResourceRef;
048: import org.objectweb.jonas_lib.deployment.xml.ServiceRef;
049:
050: import org.objectweb.jonas_ws.deployment.api.ServiceRefDesc;
051: import org.objectweb.jonas_ws.deployment.api.WSDeploymentDescException;
052:
053: import org.objectweb.jonas.common.Log;
054:
055: import org.objectweb.util.monolog.api.BasicLevel;
056: import org.objectweb.util.monolog.api.Logger;
057:
058: /**
059: * This class is used to keep the usage of containedJNDI environment
060: * regerence elements consistent across J2EE deployment descriptors
061: * Elements are "env-entry", "ejb-ref", "ejb-local-ref", "resource-ref",
062: * "resource-env-ref, "service-ref", "message-destination-ref"
063: * This class extends DescriptionGroupDesc and give access to elements
064: * "description", "display-name", "icon"
065: * used by entity, session, message-driven-bean, web-app, clientApp
066: *
067: * @author Philippe Coq
068: *
069: */
070:
071: public abstract class JndiEnvRefsGroupDesc extends DescriptionGroupDesc
072: implements JndiEnvRefsGroup {
073:
074: /**
075: * List of resource env ref Descriptors.
076: */
077: private Vector resourceEnvRefs = new Vector();
078:
079: /**
080: * List of resource ref Descriptors..
081: */
082: private Vector resourceRefs = new Vector();
083:
084: /**
085: * List of env-entry Descriptors.
086: */
087: private Vector envEntries = new Vector();
088:
089: /**
090: * List of service-ref Descriptors.
091: */
092: private Vector serviceRefs = new Vector();
093:
094: /**
095: * List of EJB ref Descriptors..
096: */
097: private Vector ejbRefs = new Vector();
098:
099: /**
100: * List of local EJB ref Descriptors..
101: */
102: private Vector ejbLocalRefs = new Vector();
103:
104: /**
105: * List of message destination ref Descriptors..
106: */
107: private Vector messageDestinationRefs = new Vector();
108:
109: /**
110: * logger
111: */
112: private static Logger logger = Log.getLogger(Log.JONAS_WS_PREFIX);
113:
114: /**
115: * Construct an instance of a JndiEnvRefsGroupDesc. <BR>
116: *
117: * @param classLoader the classloader for the deployed module.
118: * @param app the data structure of the J2EE application
119: * @param jonasApp the data structure of the jonas specific deployment
120: * descriptor
121: * @param fileName the file name of the module (useful only for service-ref)
122: * @throws DeploymentDescException if the deployment descriptors are
123: * corrupted.
124: */
125: protected JndiEnvRefsGroupDesc(ClassLoader classLoader,
126: JndiEnvRefsGroupXml app, JonasJndiEnvRefsGroupXml jonasApp,
127: String fileName) throws DeploymentDescException {
128:
129: // test classloader
130: if (classLoader == null) {
131: throw new DeploymentDescException("Classloader is null");
132: }
133: // display name
134: displayName = null;
135: if (app.getDisplayName() != null) {
136: displayName = app.getDisplayName();
137: }
138:
139: // resource-env-ref
140: processResourceEnvRef(classLoader, app, jonasApp);
141:
142: // resource-ref
143: processResourceRef(classLoader, app, jonasApp);
144:
145: // env-entry
146: processEnvEntry(app);
147:
148: // ejb-ref
149: processEjbRef(app, jonasApp);
150:
151: // ejb-local-ref
152: processEjbLocalRef(app);
153:
154: // service-ref
155: processServiceRef(classLoader, app, jonasApp, fileName);
156:
157: // message-destination-ref
158: processMessageDestinationRef(app, jonasApp);
159:
160: }
161:
162: /**
163: * @param app the data structure of the J2EE application
164: * @throws DeploymentDescException if the deployment descriptors are
165: * corrupted.
166: */
167: private void processEnvEntry(JndiEnvRefsGroupXml app)
168: throws DeploymentDescException {
169: // env-entry
170: for (Iterator i = app.getEnvEntryList().iterator(); i.hasNext();) {
171: EnvEntryDesc envEntryDesc = new EnvEntryDesc((EnvEntry) i
172: .next());
173: envEntries.addElement(envEntryDesc);
174: }
175: }
176:
177: /**
178: * @param app the data structure of the J2EE application
179: * @param jonasApp the data structure of the jonas specific deployment
180: * descriptor
181: * @throws DeploymentDescException if the deployment descriptors are
182: * corrupted.
183: */
184: private void processMessageDestinationRef(JndiEnvRefsGroupXml app,
185: JonasJndiEnvRefsGroupXml jonasApp)
186: throws DeploymentDescException {
187: List messageDestinationRefList = app
188: .getMessageDestinationRefList();
189: List jonasMessageDestinationRefList = jonasApp
190: .getJonasMessageDestinationRefList();
191:
192: HashMap messageDestinationRef = new HashMap();
193: for (Iterator i = jonasMessageDestinationRefList.iterator(); i
194: .hasNext();) {
195: JonasMessageDestinationRef jonasMessageDestinationRef = (JonasMessageDestinationRef) i
196: .next();
197: String mdrName = jonasMessageDestinationRef
198: .getMessageDestinationRefName();
199: boolean findMDRef = false;
200: for (Iterator j = messageDestinationRefList.iterator(); j
201: .hasNext()
202: && !findMDRef;) {
203: MessageDestinationRef mdRef = (MessageDestinationRef) j
204: .next();
205: if (mdrName
206: .equals(mdRef.getMessageDestinationRefName())) {
207: findMDRef = true;
208: }
209: }
210: if (!findMDRef) {
211: throw new DeploymentDescException(
212: "message-destination-ref missing for jonas-message-destination-ref "
213: + mdrName);
214: }
215: messageDestinationRef.put(mdrName,
216: jonasMessageDestinationRef);
217: }
218: for (Iterator i = messageDestinationRefList.iterator(); i
219: .hasNext();) {
220: MessageDestinationRef mdRef = (MessageDestinationRef) i
221: .next();
222: String mdrName = mdRef.getMessageDestinationRefName();
223: JonasMessageDestinationRef jonasMessageDestinationRef = (JonasMessageDestinationRef) messageDestinationRef
224: .get(mdrName);
225: if (jonasMessageDestinationRef == null) {
226: // The message-destination-link must be specified when there is no jonas-message-destination-ref
227: if ((mdRef.getMessageDestinationLink() == null)) {
228: // Ignore the message-destination-link syntax "product.jar#ProductMD"
229: throw new DeploymentDescException(
230: "message-destination-link missing for message-destination-ref-name "
231: + mdrName);
232: }
233: }
234: messageDestinationRefs
235: .addElement(new MessageDestinationRefDesc(mdRef,
236: jonasMessageDestinationRef));
237: }
238: }
239:
240: /**
241: * @param classLoader the classloader for the deployed module.
242: * @param app the data structure of the J2EE application
243: * @param jonasApp the data structure of the jonas specific deployment
244: * descriptor
245: * @param fileName the file name of the module (useful only for service-ref)
246: * @throws WSDeploymentDescException if the deployment descriptors are
247: * corrupted.
248: */
249: private void processServiceRef(ClassLoader classLoader,
250: JndiEnvRefsGroupXml app, JonasJndiEnvRefsGroupXml jonasApp,
251: String fileName) throws WSDeploymentDescException {
252: Map links = linksSR2JSR(app, jonasApp);
253: List serviceRefList = app.getServiceRefList();
254: for (Iterator i = serviceRefList.iterator(); i.hasNext();) {
255: ServiceRef serviceRef = ((ServiceRef) i.next());
256: JonasServiceRef jsr = (JonasServiceRef) links
257: .get(serviceRef.getServiceRefName());
258: serviceRefs.addElement(new ServiceRefDesc(classLoader,
259: serviceRef, jsr, fileName));
260: }
261: }
262:
263: /**
264: * @param app the data structure of the J2EE application
265: * @throws DeploymentDescException if the deployment descriptors are
266: * corrupted.
267: */
268: private void processEjbLocalRef(JndiEnvRefsGroupXml app)
269: throws DeploymentDescException {
270: List ejbLocalRefList = app.getEjbLocalRefList();
271: for (Iterator i = ejbLocalRefList.iterator(); i.hasNext();) {
272: EjbLocalRef ejbLocalRef = (EjbLocalRef) i.next();
273: if ((ejbLocalRef.getEjbLink() == null)) {
274: throw new DeploymentDescException(
275: "ejb-link missing for ejb-ref-name "
276: + ejbLocalRef.getEjbRefName());
277: }
278: ejbLocalRefs.addElement(new EjbLocalRefDesc(ejbLocalRef));
279: }
280: }
281:
282: /**
283: * @param app the data structure of the J2EE application
284: * @param jonasApp the data structure of the jonas specific deployment
285: * descriptor
286: * @throws DeploymentDescException if the deployment descriptors are
287: * corrupted.
288: */
289: private void processEjbRef(JndiEnvRefsGroupXml app,
290: JonasJndiEnvRefsGroupXml jonasApp)
291: throws DeploymentDescException {
292: List ejbRefList = app.getEjbRefList();
293: List jonasEjbRefList = jonasApp.getJonasEjbRefList();
294:
295: HashMap ejbRef = new HashMap();
296: for (Iterator i = jonasEjbRefList.iterator(); i.hasNext();) {
297: JonasEjbRef jonasEjbRef = (JonasEjbRef) i.next();
298: String brName = jonasEjbRef.getEjbRefName();
299: boolean findBRef = false;
300: for (Iterator j = ejbRefList.iterator(); j.hasNext()
301: && !findBRef;) {
302: EjbRef eRef = (EjbRef) j.next();
303: if (brName.equals(eRef.getEjbRefName())) {
304: findBRef = true;
305: }
306: }
307: if (!findBRef) {
308: throw new DeploymentDescException(
309: "ejb-ref missing for jonas-ejb-ref " + brName);
310: }
311: ejbRef.put(brName, jonasEjbRef);
312: }
313: for (Iterator i = ejbRefList.iterator(); i.hasNext();) {
314: EjbRef eRef = (EjbRef) i.next();
315: String brName = eRef.getEjbRefName();
316: JonasEjbRef jonasEjbRef = (JonasEjbRef) ejbRef.get(brName);
317: if (jonasEjbRef == null) {
318: // The ejb-link must be specified when there is no jonas-ejb-ref
319: if ((eRef.getEjbLink() == null)) {
320: // Ignore the ejb-link syntax "product.jar#ProductEJB"
321: throw new DeploymentDescException(
322: "ejb-link missing for ejb-ref-name "
323: + brName);
324: }
325: }
326: ejbRefs.addElement(new EjbRefDesc(eRef, jonasEjbRef));
327: }
328: }
329:
330: /**
331: * @param classLoader the classloader for the deployed module.
332: * @param app the data structure of the J2EE application
333: * @param jonasApp the data structure of the jonas specific deployment
334: * descriptor
335: * @throws DeploymentDescException if the deployment descriptors are
336: * corrupted.
337: */
338: private void processResourceRef(ClassLoader classLoader,
339: JndiEnvRefsGroupXml app, JonasJndiEnvRefsGroupXml jonasApp)
340: throws DeploymentDescException {
341: List resourceRefList = app.getResourceRefList();
342: List jonasResourceList = jonasApp.getJonasResourceList();
343: HashMap resource = new HashMap();
344: for (Iterator i = jonasResourceList.iterator(); i.hasNext();) {
345: JonasResource jonasResource = ((JonasResource) i.next());
346: String rName = jonasResource.getResRefName();
347: boolean findResRef = false;
348: for (Iterator j = resourceRefList.iterator(); j.hasNext()
349: && !findResRef;) {
350: if (rName.equals(((ResourceRef) j.next())
351: .getResRefName())) {
352: findResRef = true;
353: }
354: }
355: if (!findResRef) {
356: throw new DeploymentDescException(
357: "resource-ref missing for jonas-resource "
358: + rName);
359: }
360: resource.put(rName, jonasResource);
361: }
362:
363: for (Iterator i = resourceRefList.iterator(); i.hasNext();) {
364: ResourceRef resourceRef = ((ResourceRef) i.next());
365: String rName = resourceRef.getResRefName();
366: if (!resource.containsKey(rName)) {
367: throw new DeploymentDescException(
368: "jonas-resource missing for res-ref-name "
369: + rName);
370: }
371: resourceRefs.addElement(new ResourceRefDesc(classLoader,
372: resourceRef, (JonasResource) resource.get(rName)));
373: }
374: }
375:
376: /**
377: * @param classLoader the classloader for the deployed module.
378: * @param app the data structure of the J2EE application
379: * @param jonasApp the data structure of the jonas specific deployment
380: * descriptor
381: * @throws DeploymentDescException if the deployment descriptors are
382: * corrupted.
383: */
384: private void processResourceEnvRef(ClassLoader classLoader,
385: JndiEnvRefsGroupXml app, JonasJndiEnvRefsGroupXml jonasApp)
386: throws DeploymentDescException {
387: List resourceEnvRefList = app.getResourceEnvRefList();
388: List jonasResourceEnvList = jonasApp.getJonasResourceEnvList();
389: HashMap resourceEnv = new HashMap();
390: for (Iterator i = jonasResourceEnvList.iterator(); i.hasNext();) {
391: JonasResourceEnv jonasResourceEnv = (JonasResourceEnv) i
392: .next();
393: String rName = jonasResourceEnv.getResourceEnvRefName();
394: boolean findResRef = false;
395: for (Iterator j = resourceEnvRefList.iterator(); j
396: .hasNext()
397: && !findResRef;) {
398: ResourceEnvRef resourceEnvRef = (ResourceEnvRef) j
399: .next();
400: if (rName
401: .equals(resourceEnvRef.getResourceEnvRefName())) {
402: findResRef = true;
403: }
404: }
405: if (!findResRef) {
406: throw new DeploymentDescException(
407: "resource-env-ref missing for jonas-resource-env "
408: + rName);
409: }
410: resourceEnv.put(rName, jonasResourceEnv);
411: }
412: for (Iterator i = resourceEnvRefList.iterator(); i.hasNext();) {
413: ResourceEnvRef resourceEnvRef = (ResourceEnvRef) i.next();
414: String rName = resourceEnvRef.getResourceEnvRefName();
415: if (!resourceEnv.containsKey(rName)) {
416: throw new DeploymentDescException(
417: "jonas-resource-env missing for resource-env-ref-name "
418: + rName);
419: }
420: resourceEnvRefs.addElement(new ResourceEnvRefDesc(
421: classLoader, resourceEnvRef,
422: (JonasResourceEnv) resourceEnv.get(rName)));
423: }
424: }
425:
426: /**
427: * @param app JndiEnvRefsGroupXml instance
428: * @param jonasApp linked JonasJndiEnvRefsGroupXml instance
429: * @return Returns a map associating the ServiceRef.name with the JonasServiceRef
430: */
431: private Map linksSR2JSR(JndiEnvRefsGroupXml app,
432: JonasJndiEnvRefsGroupXml jonasApp) {
433: Map res = new HashMap();
434: // for each sr
435: for (Iterator i = app.getServiceRefList().iterator(); i
436: .hasNext();) {
437: ServiceRef sr = (ServiceRef) i.next();
438: res.put(sr.getServiceRefName(), null);
439: }
440: // jonas-<desc>.xml
441: if (jonasApp != null) {
442:
443: // get all ServiceRef.name
444: Set keys = res.keySet();
445:
446: // for each jonas service ref
447: for (Iterator i = jonasApp.getJonasServiceRefList()
448: .iterator(); i.hasNext();) {
449: JonasServiceRef jsr = (JonasServiceRef) i.next();
450: String srName = jsr.getServiceRefName();
451:
452: if (keys.contains(srName)) {
453: // jonas-service-ref linked to service-ref
454: res.put(srName, jsr);
455: } else {
456: String err = "jonas-service-ref '"
457: + srName
458: + "' is not linked to any service-ref. It will be ignored."; //getI18n().getMessage("WSDeploymentDesc.wsdlDeclareUnknownPort", wsdlf.getName());
459: logger.log(BasicLevel.WARN, err);
460: }
461: }
462: }
463: return res;
464: }
465:
466: /**
467: * Get resource environment references.
468: *
469: * @return array of resource environment reference descriptors
470: */
471: public ResourceEnvRefDesc[] getResourceEnvRefDesc() {
472: ResourceEnvRefDesc[] ret = new ResourceEnvRefDesc[resourceEnvRefs
473: .size()];
474: resourceEnvRefs.copyInto(ret);
475: return ret;
476: }
477:
478: /**
479: * Get resource manager connection factory references.
480: *
481: * @return array of resource reference descriptors
482: */
483: public ResourceRefDesc[] getResourceRefDesc() {
484: ResourceRefDesc[] ret = new ResourceRefDesc[resourceRefs.size()];
485: resourceRefs.copyInto(ret);
486: return ret;
487: }
488:
489: /**
490: * Get environment entries.
491: *
492: * @return array of Env entries descriptors
493: */
494: public EnvEntryDesc[] getEnvEntryDesc() {
495: EnvEntryDesc[] ret = new EnvEntryDesc[envEntries.size()];
496: envEntries.copyInto(ret);
497: return ret;
498: }
499:
500: /**
501: * Get EJB references.
502: *
503: * @return array of EJB reference descriptors
504: */
505: public EjbRefDesc[] getEjbRefDesc() {
506: EjbRefDesc[] ret = new EjbRefDesc[ejbRefs.size()];
507: ejbRefs.copyInto(ret);
508: return ret;
509: }
510:
511: /**
512: * Get ejb local references.
513: *
514: * @return array of ejb local reference descriptors
515: */
516: public EjbLocalRefDesc[] getEjbLocalRefDesc() {
517: EjbLocalRefDesc[] ret = new EjbLocalRefDesc[ejbLocalRefs.size()];
518: ejbLocalRefs.copyInto(ret);
519: return ret;
520: }
521:
522: /**
523: * Get service references.
524: *
525: * @return array of service references descriptors
526: */
527: public ServiceRefDesc[] getServiceRefDesc() {
528: ServiceRefDesc[] ret = new ServiceRefDesc[serviceRefs.size()];
529: serviceRefs.copyInto(ret);
530: return ret;
531: }
532:
533: /**
534: * Get message-destination references.
535: * @return array of message-destination references descriptors
536: */
537: public MessageDestinationRefDesc[] getMessageDestinationRefDesc() {
538: MessageDestinationRefDesc[] ret = new MessageDestinationRefDesc[messageDestinationRefs
539: .size()];
540: messageDestinationRefs.copyInto(ret);
541: return ret;
542: }
543: }
|