KickJava   Java API By Example, From Geeks To Geeks.

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


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.ArrayList JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.logging.Level JavaDoc;
30 import java.util.Map JavaDoc;
31
32 import org.xml.sax.Attributes JavaDoc;
33 import org.w3c.dom.Node JavaDoc;
34 import com.sun.enterprise.deployment.xml.ApplicationTagNames;
35 import com.sun.enterprise.deployment.Descriptor;
36 import com.sun.enterprise.deployment.EjbBundleDescriptor;
37 import com.sun.enterprise.deployment.WebBundleDescriptor;
38 import com.sun.enterprise.deployment.Application;
39 import com.sun.enterprise.deployment.util.ModuleDescriptor;
40 import com.sun.enterprise.deployment.xml.EjbTagNames;
41
42 import com.sun.enterprise.deployment.util.DOLUtils;
43
44 /**
45  * This class is responsible for loading and saving XML elements
46  *
47  * @author Jerome Dochez
48  * @version
49  */

50 public class ApplicationNode extends BundleNode implements RootXMLNode{
51
52    /**
53     * The public ID.
54     */

55     public final static String JavaDoc PUBLIC_DTD_ID = "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN";
56     public final static String JavaDoc PUBLIC_DTD_ID_12 = "-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN";
57     /**
58      * The system ID.
59      */

60     public final static String JavaDoc SYSTEM_ID = "http://java.sun.com/dtd/application_1_3.dtd";
61     public final static String JavaDoc SYSTEM_ID_12 = "http://java.sun.com/dtd/application_1_2.dtd";
62     
63     public final static String JavaDoc SCHEMA_ID_14 = "application_1_4.xsd";
64
65     public final static String JavaDoc SCHEMA_ID = "application_5.xsd";
66     public final static String JavaDoc SPEC_VERSION = "5";
67     private static List JavaDoc<String JavaDoc> systemIDs = null;
68      
69     // The XML tag associated with this Node
70
public final static XMLElement tag = new XMLElement(ApplicationTagNames.APPLICATION);
71     
72     // The DOL Descriptor we are working for
73
private Application descriptor;
74     
75     /**
76      * register this node as a root node capable of loading entire DD files
77      *
78      * @param publicIDToDTD is a mapping between xml Public-ID to DTD
79      * @return the doctype tag name
80      */

81     public static String JavaDoc registerBundle(Map JavaDoc publicIDToDTD) {
82         publicIDToDTD.put(PUBLIC_DTD_ID, SYSTEM_ID);
83         publicIDToDTD.put(PUBLIC_DTD_ID_12, SYSTEM_ID_12);
84         return tag.getQName();
85     }
86    
87     /** Creates new ApplicationNode */
88     public ApplicationNode() {
89         super();
90         registerElementHandler(new XMLElement(ApplicationTagNames.MODULE), ModuleNode.class, "addModule");
91         registerElementHandler(new XMLElement(ApplicationTagNames.ROLE), SecurityRoleNode.class, "addAppRole");
92     }
93     
94     /**
95      * @return the XML tag associated with this XMLNode
96      */

97     protected XMLElement getXMLRootTag() {
98         return tag;
99     }
100
101    /**
102      * receives notiification of the value for a particular tag
103      *
104      * @param element the xml element
105      * @param value it's associated value
106      */

107     public void setElementValue(XMLElement element, String JavaDoc value) {
108         Application application = (Application)getDescriptor();
109         if (element.getQName().equals(
110             ApplicationTagNames.LIBRARY_DIRECTORY)) {
111             application.setLibraryDirectory(value);
112         } else super.setElementValue(element, value);
113     }
114
115     
116     /**
117      * Adds a new DOL descriptor instance to the descriptor instance associated with
118      * this XMLNode
119      *
120      * @param descriptor the new descriptor
121      */

122     public void addDescriptor(Object JavaDoc newDescriptor) {
123        if (newDescriptor instanceof EjbBundleDescriptor) {
124         if(DOLUtils.getDefaultLogger().isLoggable(Level.FINE)) {
125         DOLUtils.getDefaultLogger().fine("In " + toString() +
126             " adding descriptor " + newDescriptor);
127         }
128            descriptor.addEjbBundleDescriptor((EjbBundleDescriptor) newDescriptor);
129        } else if (newDescriptor instanceof WebBundleDescriptor) {
130            DOLUtils.getDefaultLogger().fine("In " + toString() + " adding web descriptor " + newDescriptor);
131            descriptor.addWebBundleDescriptor((WebBundleDescriptor) newDescriptor);
132        }
133     }
134    
135    /**
136     * @return the descriptor instance to associate with this XMLNode
137     */

138     public Object JavaDoc getDescriptor() {
139         if (descriptor==null) {
140             descriptor = (Application) DescriptorFactory.getDescriptor(getXMLPath());
141         }
142         return descriptor;
143     }
144
145     /**
146      * @return the DOCTYPE of the XML file
147      */

148     public String JavaDoc getDocType() {
149         return null;
150     }
151     
152     /**
153      * @return the SystemID of the XML file
154      */

155     public String JavaDoc getSystemID() {
156         return SCHEMA_ID;
157     }
158
159     /**
160      * @return the list of SystemID of the XML schema supported
161      */

162     public List JavaDoc<String JavaDoc> getSystemIDs() {
163         if (systemIDs != null) {
164             return systemIDs;
165         }
166
167         systemIDs = new ArrayList JavaDoc<String JavaDoc>();
168         systemIDs.add(SCHEMA_ID);
169         systemIDs.add(SCHEMA_ID_14);
170         return systemIDs;
171     }
172     
173     /**
174      * write the descriptor class to a DOM tree and return it
175      *
176      * @param the descriptor to write
177      * @return the DOM tree top node
178      */

179     public Node JavaDoc writeDescriptor(Node JavaDoc parent, Descriptor descriptor) {
180         if (! (descriptor instanceof Application)) {
181             throw new IllegalArgumentException JavaDoc(getClass() + " cannot handles descriptors of type " + descriptor.getClass());
182         }
183         Application application = (Application) descriptor;
184         Node JavaDoc appNode = super.writeDescriptor(parent, application);
185         
186         // module
187
ModuleNode moduleNode = new ModuleNode();
188         for (Iterator JavaDoc modules = application.getModules();modules.hasNext();) {
189             ModuleDescriptor next = (ModuleDescriptor) modules.next();
190             moduleNode.writeDescriptor(appNode, ApplicationTagNames.MODULE, next);
191         }
192
193         // security-role*
194
// this information is not written out since it's already included
195
// in the sub module deployment descriptors
196

197
198         // library-directory
199
if (application.getLibraryDirectoryRawValue() != null) {
200             appendTextChild(appNode, ApplicationTagNames.LIBRARY_DIRECTORY,
201                 application.getLibraryDirectoryRawValue());
202         }
203         return appNode;
204     }
205         
206     /**
207      * @return the default spec version level this node complies to
208      */

209     public String JavaDoc getSpecVersion() {
210         return SPEC_VERSION;
211     }
212     
213 }
214
Popular Tags