KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > ejb > 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.ejb;
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.HashSet JavaDoc;
32 import java.util.Iterator JavaDoc;
33
34 import com.sun.enterprise.deployment.node.XMLElement;
35 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
36
37 import com.sun.enterprise.deployment.EnvironmentProperty;
38 import com.sun.enterprise.deployment.Descriptor;
39 import com.sun.enterprise.deployment.ActivationConfigDescriptor;
40 import com.sun.enterprise.deployment.xml.EjbTagNames;
41 import com.sun.enterprise.deployment.util.DOLUtils;
42
43 /**
44  * This class is responsible for hanlding the activation config elements.
45  *
46  * @author Kenneth Saks
47  * @version
48  */

49 public class ActivationConfigNode extends DeploymentDescriptorNode {
50
51     private ActivationConfigDescriptor descriptor = null;
52     private String JavaDoc propertyName = null;
53
54     public ActivationConfigNode() {
55         super();
56         registerElementHandler(new XMLElement(EjbTagNames.ACTIVATION_CONFIG),
57                                ActivationConfigNode.class,
58                                "setActivationConfigDescriptor");
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 = (ActivationConfigDescriptor) super.getDescriptor();
68         }
69         return descriptor;
70     }
71     
72     /**
73      * receives notiification of the value for a particular tag
74      *
75      * @param element the xml element
76      * @param value it's associated value
77      */

78     public void setElementValue(XMLElement element, String JavaDoc value) {
79         if (EjbTagNames.ACTIVATION_CONFIG_PROPERTY_NAME.equals
80             (element.getQName())) {
81             propertyName = value;
82         } else if(EjbTagNames.ACTIVATION_CONFIG_PROPERTY_VALUE.equals
83                   (element.getQName())) {
84             EnvironmentProperty prop =
85                 new EnvironmentProperty(propertyName, value, "");
86             descriptor.getActivationConfig().add(prop);
87             propertyName = null;
88         }
89     }
90     
91     /**
92      * write the descriptor class to a DOM tree and return it
93      *
94      * @param parent node in the DOM tree
95      * @param node name for the root element of this xml fragment
96      * @param the descriptor to write
97      * @return the DOM tree top node
98      */

99     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName,
100                                 ActivationConfigDescriptor descriptor) {
101
102         Node JavaDoc activationConfigNode = null;
103         Set JavaDoc activationConfig = descriptor.getActivationConfig();
104
105         // ActionConfig must have at least one ActionConfigProperty
106
// and ActionConfigProperty must have a pair of name/value
107
// so filter out the entries with blank name or value
108
Set JavaDoc activationConfig2 = new HashSet JavaDoc();
109         for(Iterator JavaDoc iter = activationConfig.iterator(); iter.hasNext();) {
110             EnvironmentProperty next = (EnvironmentProperty) iter.next();
111             if ( ! next.getName().trim().equals("") &&
112                  ! next.getValue().trim().equals("")) {
113                 activationConfig2.add(next);
114             }
115         }
116
117         if( activationConfig2.size() > 0 ) {
118             activationConfigNode =
119                 appendChild(parent, nodeName);
120             writeLocalizedDescriptions(activationConfigNode, descriptor);
121             
122             for(Iterator JavaDoc iter = activationConfig2.iterator(); iter.hasNext();) {
123                 Node JavaDoc activationConfigPropertyNode =
124                     appendChild(activationConfigNode,
125                                 EjbTagNames.ACTIVATION_CONFIG_PROPERTY);
126                 EnvironmentProperty next = (EnvironmentProperty) iter.next();
127                 appendTextChild(activationConfigPropertyNode,
128                                 EjbTagNames.ACTIVATION_CONFIG_PROPERTY_NAME,
129                                 (String JavaDoc) next.getName());
130                 appendTextChild(activationConfigPropertyNode,
131                                 EjbTagNames.ACTIVATION_CONFIG_PROPERTY_VALUE,
132                                 (String JavaDoc) next.getValue());
133             }
134         }
135         return activationConfigNode;
136     }
137 }
138
Popular Tags