KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > ejb > QueryNode


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.logging.Level JavaDoc;
28 import org.w3c.dom.Node JavaDoc;
29
30 import com.sun.enterprise.deployment.node.XMLElement;
31 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
32 import com.sun.enterprise.deployment.node.MethodNode;
33
34 import com.sun.enterprise.deployment.Descriptor;
35 import com.sun.enterprise.deployment.QueryDescriptor;
36 import com.sun.enterprise.deployment.MethodDescriptor;
37 import com.sun.enterprise.deployment.xml.EjbTagNames;
38 import com.sun.enterprise.deployment.util.DOLUtils;
39
40 /**
41  * This class is responsible for hanlding the query element
42  *
43  * @author Jerome Dochez
44  * @version
45  */

46 public class QueryNode extends DeploymentDescriptorNode {
47
48     private QueryDescriptor descriptor = null;
49     
50     /** Creates new QueryNode */
51     public QueryNode() {
52         super();
53         registerElementHandler(new XMLElement(EjbTagNames.QUERY_METHOD),
54                                                                 MethodNode.class, "setQueryMethodDescriptor");
55     }
56
57     /**
58      * @return the Descriptor subclass that was populated by reading
59      * the source XML file
60      */

61     public Object JavaDoc getDescriptor() {
62         if (descriptor == null) {
63             descriptor = (QueryDescriptor) super.getDescriptor();
64         }
65         return descriptor;
66     }
67         
68     /**
69      * all sub-implementation of this class can use a dispatch table to map xml element to
70      * method name on the descriptor class for setting the element value.
71      *
72      * @return the map with the element name as a key, the setter method as a value
73      */

74     protected Map JavaDoc getDispatchTable() {
75         // no need to be synchronized for now
76
Map JavaDoc table = super.getDispatchTable();
77         table.put(EjbTagNames.EJB_QL, "setQuery");
78         return table;
79     }
80     
81     
82     /**
83      * receives notiification of the value for a particular tag
84      *
85      * @param element the xml element
86      * @param value it's associated value
87      */

88     public void setElementValue(XMLElement element, String JavaDoc value) {
89         if (EjbTagNames.QUERY_RESULT_TYPE_MAPPING.equals(element.getQName())) {
90             if (EjbTagNames.QUERY_REMOTE_TYPE_MAPPING.equals(value)) {
91                 descriptor.setHasRemoteReturnTypeMapping();
92             } else if (EjbTagNames.QUERY_LOCAL_TYPE_MAPPING.equals(value)) {
93                 descriptor.setHasLocalReturnTypeMapping();
94             } else {
95                 DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.addDescriptorFailure",
96                                 new Object JavaDoc[] {((Descriptor) getParentNode().getDescriptor()).getName() , value});
97             }
98         } else {
99             super.setElementValue(element, value);
100         }
101     }
102     
103     /**
104      * write the descriptor class to a DOM tree and return it
105      *
106      * @param parent node in the DOM tree
107      * @param node name for the root element of this xml fragment
108      * @param the descriptor to write
109      * @return the DOM tree top node
110      */

111     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, QueryDescriptor descriptor) {
112         Node JavaDoc queryNode = super.writeDescriptor(parent, nodeName, descriptor);
113
114         writeLocalizedDescriptions(queryNode, descriptor);
115                 
116         // query-method
117
MethodNode methodNode = new MethodNode();
118         methodNode.writeQueryMethodDescriptor(queryNode, EjbTagNames.QUERY_METHOD,
119                                                                          descriptor.getQueryMethodDescriptor());
120         
121         if (descriptor.getHasRemoteReturnTypeMapping()) {
122             appendTextChild(queryNode, EjbTagNames.QUERY_RESULT_TYPE_MAPPING,
123                                                     EjbTagNames.QUERY_REMOTE_TYPE_MAPPING);
124         } else {
125         if (descriptor.getHasLocalReturnTypeMapping()) {
126                 appendTextChild(queryNode, EjbTagNames.QUERY_RESULT_TYPE_MAPPING,
127                                                     EjbTagNames.QUERY_LOCAL_TYPE_MAPPING);
128             }
129     }
130         // ejbql element is mandatory. If no EJB QL query has been
131
// specified for the method, the xml element will be empty
132
String JavaDoc ejbqlText = descriptor.getIsEjbQl() ? descriptor.getQuery() : "";
133         Node JavaDoc child = appendChild(queryNode, EjbTagNames.EJB_QL);
134         child.appendChild(getOwnerDocument(child).createTextNode(ejbqlText));
135         
136         return queryNode;
137     }
138 }
139
Popular Tags