KickJava   Java API By Example, From Geeks To Geeks.

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


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.Vector JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.Map JavaDoc;
29 import org.w3c.dom.Node JavaDoc;
30
31 import com.sun.enterprise.deployment.Descriptor;
32 import com.sun.enterprise.deployment.EjbBundleDescriptor;
33 import com.sun.enterprise.deployment.EjbDescriptor;
34 import com.sun.enterprise.deployment.MethodDescriptor;
35 import com.sun.enterprise.deployment.ContainerTransaction;
36 import com.sun.enterprise.deployment.xml.EjbTagNames;
37 /**
38  * This node is responsible for handling the container-transaction XML node
39  *
40  * @author Jerome Dochez
41  * @version
42  */

43 public class ContainerTransactionNode extends DeploymentDescriptorNode {
44
45     private String JavaDoc trans_attribute;
46     private String JavaDoc description;
47     private Vector JavaDoc methods = new Vector JavaDoc();
48     
49     /** Creates new ContainerTransactionNode */
50     public ContainerTransactionNode() {
51        registerElementHandler(new XMLElement(EjbTagNames.METHOD), MethodNode.class);
52     }
53     
54     /**
55      * Adds a new DOL descriptor instance to the descriptor instance associated with
56      * this XMLNode
57      *
58      * @param descriptor the new descriptor
59      */

60     public void addDescriptor(Object JavaDoc newDescriptor) {
61         if (newDescriptor instanceof MethodDescriptor) {
62             methods.add(newDescriptor);
63         }
64     }
65
66     /**
67      * @return the Descriptor subclass that was populated by reading
68      * the source XML file
69      */

70     public Object JavaDoc getDescriptor() {
71         return null;
72     }
73     
74     /**
75      * receives notification of the end of an XML element by the Parser
76      *
77      * @param element the xml tag identification
78      * @return true if this node is done processing the XML sub tree
79      */

80     public boolean endElement(XMLElement element) {
81         boolean doneWithNode = super.endElement(element);
82         
83         if (doneWithNode) {
84             ContainerTransaction ct = new ContainerTransaction(trans_attribute, description);
85             for (Iterator JavaDoc methodsIterator = methods.iterator();methodsIterator.hasNext();) {
86                 MethodDescriptor md = (MethodDescriptor) methodsIterator.next();
87                 EjbBundleDescriptor bundle = (EjbBundleDescriptor) getParentNode().getDescriptor();
88                 EjbDescriptor ejb = bundle.getEjbByName(md.getEjbName());
89                 ejb.getMethodContainerTransactions().put(md, ct);
90             }
91         }
92         return doneWithNode;
93     }
94     
95     /**
96      * receives notiification of the value for a particular tag
97      *
98      * @param element the xml element
99      * @param value it's associated value
100      */

101     public void setElementValue(XMLElement element, String JavaDoc value) {
102         if (EjbTagNames.DESCRIPTION.equals(element.getQName())) {
103             description = value;
104         }
105         if (EjbTagNames.TRANSACTION_ATTRIBUTE.equals(element.getQName())) {
106             trans_attribute = value;
107         }
108     }
109     
110     /**
111      * write the descriptor class to a DOM tree and return it
112      *
113      * @param parent node in the DOM tree
114      * @param node name for the root element of this xml fragment
115      * @param the descriptor to write
116      * @return the DOM tree top node
117      */

118     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, EjbDescriptor ejb) {
119         
120         Map JavaDoc methodToTransactions = ejb.getMethodContainerTransactions();
121         MethodNode mn = new MethodNode();
122         for (Iterator JavaDoc e=methodToTransactions.keySet().iterator();e.hasNext();) {
123             MethodDescriptor md = (MethodDescriptor) e.next();
124             Node JavaDoc ctNode = super.writeDescriptor(parent, nodeName, ejb);
125             ContainerTransaction ct = (ContainerTransaction) methodToTransactions.get(md);
126             appendTextChild(ctNode, EjbTagNames.DESCRIPTION, ct.getDescription());
127             mn.writeDescriptor(ctNode, EjbTagNames.METHOD, md, ejb.getName());
128             appendTextChild(ctNode, EjbTagNames.TRANSACTION_ATTRIBUTE, ct.getTransactionAttribute());
129         }
130         return null;
131     }
132 }
133
Popular Tags