KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > runtime > ActivationConfigNode


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.runtime;
25
26 import java.util.Map JavaDoc;
27 import java.util.Map.Entry;
28 import org.w3c.dom.Node JavaDoc;
29
30 import java.util.Set JavaDoc;
31 import java.util.Iterator JavaDoc;
32
33 import com.sun.enterprise.deployment.node.XMLElement;
34 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
35
36 import com.sun.enterprise.deployment.Descriptor;
37 import com.sun.enterprise.deployment.ActivationConfigDescriptor;
38 import com.sun.enterprise.deployment.EjbMessageBeanDescriptor;
39 import com.sun.enterprise.deployment.EnvironmentProperty;
40 import com.sun.enterprise.deployment.xml.RuntimeTagNames;
41
42 /**
43  * This class is responsible for hanlding the activation config elements.
44  *
45  * @author Qingqing Ouyang
46  * @version
47  */

48 public class ActivationConfigNode extends DeploymentDescriptorNode {
49     
50     private ActivationConfigDescriptor descriptor = null;
51     private String JavaDoc propertyName = null;
52     
53     public ActivationConfigNode() {
54         super();
55         registerElementHandler(
56                 new XMLElement(RuntimeTagNames.ACTIVATION_CONFIG),
57                 ActivationConfigNode.class,
58                 "setRuntimeActivationConfigDescriptor");
59     }
60
61     /**
62      * @return the Descriptor subclass that was populated by reading
63      * the source XML file
64      */

65     public Object JavaDoc getDescriptor() {
66         if (descriptor == null) {
67             descriptor = ((EjbMessageBeanDescriptor) getParentNode().getDescriptor()).getRuntimeActivationConfigDescriptor();
68         }
69         return descriptor;
70     }
71         
72     /**
73      * all sub-implementation of this class can use a dispatch table to
74      * map xml element to method name on the descriptor class for setting
75      * the element value.
76      *
77      * @return the map with the element name as a key, the setter method
78      * as a value
79      */

80     protected Map JavaDoc getDispatchTable() {
81         // no need to be synchronized for now
82
Map JavaDoc table = super.getDispatchTable();
83         return table;
84     }
85     
86     
87     /**
88      * receives notiification of the value for a particular tag
89      *
90      * @param element the xml element
91      * @param value it's associated value
92      */

93     public void setElementValue(XMLElement element, String JavaDoc value) {
94         if (RuntimeTagNames.ACTIVATION_CONFIG_PROPERTY_NAME.equals
95                 (element.getQName())) {
96             propertyName = value;
97         } else if(RuntimeTagNames.ACTIVATION_CONFIG_PROPERTY_VALUE.equals
98                 (element.getQName())) {
99             EnvironmentProperty prop =
100                 new EnvironmentProperty(propertyName, value, "");
101             descriptor.getActivationConfig().add(prop);
102             propertyName = null;
103         }
104         else super.setElementValue(element, value);
105     }
106     
107     /**
108      * write the descriptor class to a DOM tree and return it
109      *
110      * @param parent node in the DOM tree
111      * @param node name for the root element of this xml fragment
112      * @param the descriptor to write
113      * @return the DOM tree top node
114      */

115     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName,
116                                 ActivationConfigDescriptor descriptor) {
117
118         Node JavaDoc activationConfigNode = null;
119         Set JavaDoc activationConfig = descriptor.getActivationConfig();
120         if( activationConfig.size() > 0 ) {
121             activationConfigNode =
122                 appendChild(parent, nodeName);
123             for(Iterator JavaDoc iter = activationConfig.iterator(); iter.hasNext();) {
124                 Node JavaDoc activationConfigPropertyNode =
125                     appendChild(activationConfigNode,
126                                 RuntimeTagNames.ACTIVATION_CONFIG_PROPERTY);
127                 EnvironmentProperty next = (EnvironmentProperty) iter.next();
128                 appendTextChild(activationConfigPropertyNode,
129                         RuntimeTagNames.ACTIVATION_CONFIG_PROPERTY_NAME,
130                         (String JavaDoc) next.getName());
131                 appendTextChild(activationConfigPropertyNode,
132                         RuntimeTagNames.ACTIVATION_CONFIG_PROPERTY_VALUE,
133                         (String JavaDoc) next.getValue());
134             }
135         }
136         
137         return activationConfigNode;
138     }
139 }
140
Popular Tags