KickJava   Java API By Example, From Geeks To Geeks.

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


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.Map JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import org.w3c.dom.Node JavaDoc;
29 import org.w3c.dom.Element JavaDoc;
30 import com.sun.enterprise.deployment.xml.TagNames;
31 import com.sun.enterprise.deployment.DeploymentExtensionDescriptor;
32 import com.sun.enterprise.deployment.ExtensionElementDescriptor;
33
34 /**
35  * This node is responsible for handling the deployment-extension xml fragment
36  *
37  * @author Jerome Dochez
38  */

39 public class DeploymentExtensionNode extends DeploymentDescriptorNode {
40         
41    /**
42      * all sub-implementation of this class can use a dispatch table to map xml element to
43      * method name on the descriptor class for setting the element value.
44      *
45      * @return the map with the element name as a key, the setter method as a value
46      */

47     protected Map JavaDoc getDispatchTable() {
48         Map JavaDoc table = super.getDispatchTable();
49         table.put(TagNames.NAMESPACE, "setNameSpace");
50         return table;
51     }
52     
53     /**
54      * receives notification of the value for a particular tag
55      *
56      * @param element the xml element
57      * @param value it's associated value
58      */

59     public void setElementValue(XMLElement element, String JavaDoc value) {
60         if (TagNames.MUST_UNDERSTAND.equals(element.getQName())) {
61             if ("true".equals(value)) {
62                 throw new RuntimeException JavaDoc("a deployment-extension tagged with mustUnderstand attribute is not understood");
63             }
64         } else
65             super.setElementValue(element, value);
66     }
67     
68     /**
69      * @return true if the element tag can be handled by any registered sub nodes of the
70      * current XMLNode
71      */

72     public boolean handlesElement(XMLElement element) {
73         if (TagNames.EXTENSION_ELEMENT.equals(element.getQName())) {
74             return false;
75         }
76         return true;
77     }
78     
79     /**
80      * @return the handler registered for the subtag element of the curent XMLNode
81      */

82     public XMLNode getHandlerFor(XMLElement element) {
83         ExtensionElementNode subNode = new ExtensionElementNode();
84         DeploymentExtensionDescriptor o = (DeploymentExtensionDescriptor) getDescriptor();
85         o.addElement((ExtensionElementDescriptor) subNode.getDescriptor());
86         subNode.setXMLRootTag(new XMLElement(TagNames.EXTENSION_ELEMENT));
87         subNode.setParentNode(this);
88         return subNode;
89     }
90     
91     /**
92      * Adds a new DOL descriptor instance to the descriptor instance associated with
93      * this XMLNode
94      *
95      * @param descriptor the new descriptor
96      */

97     public void addDescriptor(Object JavaDoc descriptor) {
98         // done is getHandlerFor
99
}
100     
101     /**
102      * write the deployment extensions nodes associated with this node
103      *
104      * @param parent node for the DOM tree
105      * @param iterator of deployment extension descriptor
106      */

107     protected void writeDescriptor(Node JavaDoc parentNode, Iterator JavaDoc itr) {
108         
109         ExtensionElementNode subNode = new ExtensionElementNode();
110         do {
111             DeploymentExtensionDescriptor descriptor = (DeploymentExtensionDescriptor) itr.next();
112             Element JavaDoc extensionNode = appendChild(parentNode, TagNames.DEPLOYMENT_EXTENSION);
113             setAttribute(extensionNode, TagNames.NAMESPACE, descriptor.getNameSpace());
114             if (descriptor.getMustUnderstand()) {
115                 setAttribute(extensionNode, TagNames.MUST_UNDERSTAND, "true");
116             }
117             for (Iterator JavaDoc elements = descriptor.elements();elements.hasNext();) {
118                 ExtensionElementDescriptor element = (ExtensionElementDescriptor) elements.next();
119                 subNode.writeDescriptor(extensionNode, TagNames.EXTENSION_ELEMENT, element );
120             }
121         } while(itr.hasNext());
122     }
123 }
124
Popular Tags