KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > ModuleNode


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.deployment.node;
25
26 import java.util.Iterator JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.logging.Level JavaDoc;
29 import org.w3c.dom.Node JavaDoc;
30 import org.xml.sax.Attributes JavaDoc;
31
32 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
33
34 import com.sun.enterprise.deployment.Application;
35 import com.sun.enterprise.deployment.Descriptor;
36 import com.sun.enterprise.deployment.DeploymentExtensionDescriptor;
37 import com.sun.enterprise.deployment.util.ModuleDescriptor;
38 import com.sun.enterprise.deployment.xml.ApplicationTagNames;
39
40 import com.sun.enterprise.deployment.util.DOLUtils;
41
42 /**
43  * This node is responsible for handling the module xml fragment from
44  * application.xml files
45  *
46  * @author Jerome Dochez
47  * @version
48  */

49 public class ModuleNode extends DeploymentDescriptorNode {
50     
51    /**
52      * all sub-implementation of this class can use a dispatch table to map xml element to
53      * method name on the descriptor class for setting the element value.
54      *
55      * @return the map with the element name as a key, the setter method as a value
56      */

57     protected Map JavaDoc getDispatchTable() {
58         Map JavaDoc table = super.getDispatchTable();
59         table.put(ApplicationTagNames.ALTERNATIVE_DD, "setAlternateDescriptor");
60         table.put(ApplicationTagNames.CONTEXT_ROOT, "setContextRoot");
61         return table;
62     }
63         
64     /**
65      * receives notiification of the value for a particular tag
66      *
67      * @param element the xml element
68      * @param value it's associated value
69      */

70     public void setElementValue(XMLElement element, String JavaDoc value) {
71         ModuleDescriptor descriptor = (ModuleDescriptor) getDescriptor();
72          if (element.getQName().equals(ApplicationTagNames.WEB_URI)) {
73             descriptor.setModuleType(ModuleType.WAR);
74             descriptor.setArchiveUri(value);
75         } else if (element.getQName().equals(ApplicationTagNames.EJB)) {
76             descriptor.setModuleType(ModuleType.EJB);
77             descriptor.setArchiveUri(value);
78         } else if (element.getQName().equals(ApplicationTagNames.CONNECTOR)) {
79             descriptor.setModuleType(ModuleType.RAR);
80             descriptor.setArchiveUri(value);
81         } else if (element.getQName().equals(ApplicationTagNames.APPLICATION_CLIENT)) {
82             descriptor.setModuleType(ModuleType.CAR);
83             descriptor.setArchiveUri(value);
84         } else if (element.getQName().equals(ApplicationTagNames.WEB)) {
85             descriptor.setModuleType(ModuleType.WAR);
86         } else super.setElementValue(element, value);
87     }
88         
89     /**
90      * write the descriptor class to a DOM tree and return it
91      *
92      * @param parent node in the DOM tree
93      * @param node name for the root element of this xml fragment
94      * @param the descriptor to write
95      * @return the DOM tree top node
96      */

97     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, ModuleDescriptor descriptor) {
98         
99         Node JavaDoc module = appendChild(parent, nodeName);
100         if (ModuleType.WAR.equals(descriptor.getModuleType())) {
101             Node JavaDoc modType = appendChild(module, ApplicationTagNames.WEB);
102             appendTextChild(modType, ApplicationTagNames.WEB_URI, descriptor.getArchiveUri());
103             forceAppendTextChild(modType, ApplicationTagNames.CONTEXT_ROOT, descriptor.getContextRoot());
104
105         } else {
106             // default initialization if ejb...
107
String JavaDoc type = ApplicationTagNames.EJB;
108             if (ModuleType.CAR.equals(descriptor.getModuleType())) {
109                 type = ApplicationTagNames.APPLICATION_CLIENT;
110             } else if (ModuleType.RAR.equals(descriptor.getModuleType())) {
111                 type = ApplicationTagNames.CONNECTOR;
112             }
113             appendTextChild(module, type, descriptor.getArchiveUri());
114         }
115         appendTextChild(module,ApplicationTagNames.ALTERNATIVE_DD, descriptor.getAlternateDescriptor());
116         return module;
117     }
118 }
119
Popular Tags