KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.w3c.dom.Node JavaDoc;
28
29 import com.sun.enterprise.deployment.InjectionTarget;
30 import com.sun.enterprise.deployment.xml.TagNames;
31 import com.sun.enterprise.deployment.Descriptor;
32 import com.sun.enterprise.deployment.EnvironmentProperty;
33
34 /**
35  * This node is responsible for handling all env-entry related xml tags
36  *
37  * @author Jerome Dochez
38  * @version
39  */

40 public class EnvEntryNode extends DeploymentDescriptorNode {
41     
42     private boolean setValueCalled = false;
43
44     public EnvEntryNode() {
45         super();
46         registerElementHandler(new XMLElement(TagNames.INJECTION_TARGET),
47                                 InjectionTargetNode.class, "addInjectionTarget");
48     }
49     
50    /**
51      * all sub-implementation of this class can use a dispatch table to map xml element to
52      * method name on the descriptor class for setting the element value.
53      *
54      * @return the map with the element name as a key, the setter method as a value
55      */

56     protected Map JavaDoc getDispatchTable() {
57         Map JavaDoc table = super.getDispatchTable();
58         table.put(TagNames.ENVIRONMENT_PROPERTY_NAME, "setName");
59         table.put(TagNames.ENVIRONMENT_PROPERTY_VALUE, "setValue");
60         table.put(TagNames.ENVIRONMENT_PROPERTY_TYPE, "setType");
61         table.put(TagNames.MAPPED_NAME, "setMappedName");
62         return table;
63     }
64     
65     public boolean endElement(XMLElement element) {
66
67         if (TagNames.ENVIRONMENT_PROPERTY_NAME.equals(element.getQName())) {
68             // name element is always right before value, so initialize
69
// setValueCalled to false when it is processed.
70
setValueCalled = false;
71         } else if( TagNames.ENVIRONMENT_PROPERTY_VALUE.equals
72                    (element.getQName()) ) {
73             setValueCalled = true;
74         }
75
76         return super.endElement(element);
77     }
78
79     public void addDescriptor(Object JavaDoc newDescriptor) {
80         if( setValueCalled ) {
81             super.addDescriptor(newDescriptor);
82         } else {
83             // Don't add it to DOL. The env-entry only exists
84
// at runtime if it has been assigned a value.
85
}
86     }
87
88     /**
89      * write the descriptor class to a DOM tree and return it
90      *
91      * @param parent node in the DOM tree
92      * @param node name for the root element of this xml fragment
93      * @param the descriptor to write
94      * @return the DOM tree top node
95      */

96     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, Descriptor descriptor) {
97         if (!(descriptor instanceof EnvironmentProperty)) {
98             throw new IllegalArgumentException JavaDoc(getClass() + " cannot handles descriptors of type " + descriptor.getClass());
99         }
100         EnvironmentProperty envProp = (EnvironmentProperty) descriptor;
101         Node JavaDoc envEntryNode = super.writeDescriptor(parent, nodeName, descriptor);
102         
103         writeLocalizedDescriptions(envEntryNode, envProp);
104         appendTextChild(envEntryNode, TagNames.ENVIRONMENT_PROPERTY_NAME, envProp.getName());
105         appendTextChild(envEntryNode, TagNames.ENVIRONMENT_PROPERTY_TYPE, envProp.getType());
106         appendTextChild(envEntryNode, TagNames.ENVIRONMENT_PROPERTY_VALUE, envProp.getValue());
107         appendTextChild(envEntryNode, TagNames.MAPPED_NAME, envProp.getMappedName());
108         if( envProp.isInjectable() ) {
109             InjectionTargetNode ijNode = new InjectionTargetNode();
110             for (InjectionTarget target : envProp.getInjectionTargets()) {
111                 ijNode.writeDescriptor(envEntryNode, TagNames.INJECTION_TARGET, target);
112             }
113         }
114
115         return envEntryNode;
116     }
117 }
118
Popular Tags