KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > winstone > jndi > WebAppJNDIManager


1 /*
2  * Copyright 2003-2006 Rick Knowles <winstone-devel at lists sourceforge net>
3  * Distributed under the terms of either:
4  * - the common development and distribution license (CDDL), v1.0; or
5  * - the GNU Lesser General Public License, v2.1 or later
6  */

7 package winstone.jndi;
8
9 import java.util.Iterator JavaDoc;
10 import java.util.List JavaDoc;
11 import java.util.Map JavaDoc;
12
13 import org.w3c.dom.Node JavaDoc;
14
15 import winstone.Logger;
16 import winstone.WebAppConfiguration;
17
18 /**
19  * Implements a simple web.xml + command line arguments style jndi manager
20  *
21  * @author <a HREF="mailto:rick_knowles@hotmail.com">Rick Knowles</a>
22  * @version $Id: WebAppJNDIManager.java,v 1.9 2006/02/28 07:32:48 rickknowles Exp $
23  */

24 public class WebAppJNDIManager extends ContainerJNDIManager {
25     final static String JavaDoc ELEM_ENV_ENTRY = "env-entry";
26     final static String JavaDoc ELEM_ENV_ENTRY_NAME = "env-entry-name";
27     final static String JavaDoc ELEM_ENV_ENTRY_TYPE = "env-entry-type";
28     final static String JavaDoc ELEM_ENV_ENTRY_VALUE = "env-entry-value";
29
30     /**
31      * Gets the relevant list of objects from the args, validating against the
32      * web.xml nodes supplied. All node addresses are assumed to be relative to
33      * the java:/comp/env context
34      */

35     public WebAppJNDIManager(Map JavaDoc args, List JavaDoc webXMLNodes, ClassLoader JavaDoc loader) {
36         super(args, webXMLNodes, loader);
37
38         // If the webXML nodes are not null, validate that all the entries we
39
// wanted have been created
40
if (webXMLNodes != null)
41             for (Iterator JavaDoc i = webXMLNodes.iterator(); i.hasNext();) {
42                 Node JavaDoc node = (Node JavaDoc) i.next();
43
44                 // Extract the env-entry nodes and create the objects
45
if (node.getNodeType() != Node.ELEMENT_NODE)
46                     continue;
47                 else if (node.getNodeName().equals(ELEM_ENV_ENTRY)) {
48                     String JavaDoc name = null;
49                     String JavaDoc type = null;
50                     String JavaDoc value = null;
51                     for (int m = 0; m < node.getChildNodes().getLength(); m++) {
52                         Node JavaDoc envNode = node.getChildNodes().item(m);
53                         if (envNode.getNodeType() != Node.ELEMENT_NODE)
54                             continue;
55                         else if (envNode.getNodeName().equals(ELEM_ENV_ENTRY_NAME))
56                             name = WebAppConfiguration.getTextFromNode(envNode);
57                         else if (envNode.getNodeName().equals(ELEM_ENV_ENTRY_TYPE))
58                             type = WebAppConfiguration.getTextFromNode(envNode);
59                         else if (envNode.getNodeName().equals(ELEM_ENV_ENTRY_VALUE))
60                             value = WebAppConfiguration.getTextFromNode(envNode);
61                     }
62                     if ((name != null) && (type != null) && (value != null)) {
63                         Logger.log(Logger.FULL_DEBUG, JNDI_RESOURCES,
64                                 "WebAppJNDIManager.CreatingResourceWebXML",
65                                 name);
66                         Object JavaDoc obj = createObject(name, type, value, args, loader);
67                         if (obj != null)
68                             this.objectsToCreate.put(name, obj);
69                     }
70                 }
71             }
72     }
73
74 }
75
Popular Tags