KickJava   Java API By Example, From Geeks To Geeks.

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


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.Descriptor;
30 import com.sun.enterprise.deployment.MethodDescriptor;
31 import com.sun.enterprise.deployment.xml.EjbTagNames;
32 import com.sun.enterprise.deployment.xml.RuntimeTagNames;
33
34 /**
35  * This class handle the method element
36  *
37  * @author Jerome Dochez
38  * @version
39  */

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

48     protected Map JavaDoc getDispatchTable() {
49         Map JavaDoc table = super.getDispatchTable();
50         table.put(EjbTagNames.EJB_NAME, "setEjbName");
51         table.put(EjbTagNames.METHOD_INTF, "setEjbClassSymbol");
52         table.put(EjbTagNames.METHOD_NAME, "setName");
53         table.put(EjbTagNames.METHOD_PARAM, "addParameterClass");
54         return table;
55     }
56
57     /**
58      * write the method descriptor class to a query-method DOM tree and return it
59      *
60      * @param parent node in the DOM tree
61      * @param node name for the root element of this xml fragment
62      * @param the descriptor to write
63      * @return the DOM tree top node
64      */

65     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, MethodDescriptor descriptor, String JavaDoc ejbName) {
66         Node JavaDoc methodNode = super.writeDescriptor(parent, nodeName, descriptor);
67         writeLocalizedDescriptions(methodNode, descriptor);
68         if (ejbName != null && ejbName.length() > 0) {
69             appendTextChild(methodNode, EjbTagNames.EJB_NAME, ejbName);
70         }
71         String JavaDoc methodIntfSymbol = descriptor.getEjbClassSymbol();
72         if( (methodIntfSymbol != null) &&
73             !methodIntfSymbol.equals(MethodDescriptor.EJB_BEAN) ) {
74             appendTextChild(methodNode, EjbTagNames.METHOD_INTF,
75                             methodIntfSymbol);
76         }
77         appendTextChild(methodNode, EjbTagNames.METHOD_NAME, descriptor.getName());
78         if (descriptor.getParameterClassNames()!=null) {
79             Node JavaDoc paramsNode = appendChild(methodNode, EjbTagNames.METHOD_PARAMS);
80             writeMethodParams(paramsNode, descriptor);
81         }
82         return methodNode;
83     }
84     
85     /**
86      * write the method descriptor class to a query-method DOM tree and return it
87      *
88      * @param parent node in the DOM tree
89      * @param node name for the root element of this xml fragment
90      * @param the descriptor to write
91      * @return the DOM tree top node
92      */

93     public Node JavaDoc writeQueryMethodDescriptor(Node JavaDoc parent, String JavaDoc nodeName, MethodDescriptor descriptor) {
94         Node JavaDoc methodNode = super.writeDescriptor(parent, nodeName, descriptor);
95         appendTextChild(methodNode, EjbTagNames.METHOD_NAME, descriptor.getName());
96         Node JavaDoc paramsNode = appendChild(methodNode, EjbTagNames.METHOD_PARAMS);
97         writeMethodParams(paramsNode, descriptor);
98         return methodNode;
99     }
100     
101     /**
102      * write the method descriptor class to a java-method DOM tree and return it
103      *
104      * @param parent node in the DOM tree
105      * @param node name for the root element of this xml fragment
106      * @param the descriptor to write
107      * @return the DOM tree top node
108      */

109     public Node JavaDoc writeJavaMethodDescriptor(Node JavaDoc parent, String JavaDoc nodeName,
110         MethodDescriptor descriptor) {
111         // Write out the java method description. In the case of a void
112
// method, a <method-params> element will *not* be written out.
113
return writeJavaMethodDescriptor(parent, nodeName, descriptor, false);
114     }
115
116     /**
117      * write the method descriptor class to a java-method DOM tree and return it
118      *
119      * @param parent node in the DOM tree
120      * @param node name for the root element of this xml fragment
121      * @param the descriptor to write
122      * @return the DOM tree top node
123      */

124     public Node JavaDoc writeJavaMethodDescriptor(Node JavaDoc parent, String JavaDoc nodeName,
125         MethodDescriptor descriptor,
126         boolean writeEmptyMethodParamsElementForVoidMethods) {
127         Node JavaDoc methodNode = super.writeDescriptor(parent, nodeName, descriptor);
128         appendTextChild(methodNode, RuntimeTagNames.METHOD_NAME,
129             descriptor.getName());
130         if (descriptor.getParameterClassNames() != null) {
131             Node JavaDoc paramsNode =
132                 appendChild(methodNode, RuntimeTagNames.METHOD_PARAMS);
133             writeMethodParams(paramsNode, descriptor);
134         } else {
135             if( writeEmptyMethodParamsElementForVoidMethods ) {
136                 appendChild(methodNode, RuntimeTagNames.METHOD_PARAMS);
137             }
138         }
139         return methodNode;
140     }
141
142
143     /**
144      * writes the method parameters to the DOM Tree
145      *
146      * @param the parent node for the parameters
147      * @param the method descriptor
148      */

149     private void writeMethodParams(Node JavaDoc paramsNode, MethodDescriptor descriptor) {
150         String JavaDoc[] params = descriptor.getParameterClassNames();
151         if (params==null)
152             return;
153         for (int i=0; i<params.length;i++) {
154             appendTextChild(paramsNode, RuntimeTagNames.METHOD_PARAM, params[i]);
155         }
156     }
157 }
158    
159
Popular Tags