KickJava   Java API By Example, From Geeks To Geeks.

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


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 package com.sun.enterprise.deployment.node.runtime;
24
25 import java.util.Map JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.logging.Level JavaDoc;
28 import org.w3c.dom.Node JavaDoc;
29
30 import com.sun.enterprise.deployment.types.EjbReferenceContainer;
31 import com.sun.enterprise.deployment.types.EjbReference;
32 import com.sun.enterprise.deployment.Descriptor;
33 import com.sun.enterprise.deployment.node.XMLElement;
34 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
35 import com.sun.enterprise.deployment.xml.RuntimeTagNames;
36 import com.sun.enterprise.deployment.util.DOLUtils;
37
38 /**
39  * This node class is responsible for handling runtime deployment descriptors
40  * for ejb-ref
41  *
42  * @author Jerome Dochez
43  * @version
44  */

45 public class EjbRefNode extends DeploymentDescriptorNode {
46
47     EjbReference descriptor=null;
48     
49    /**
50     * @return the descriptor instance to associate with this XMLNode
51     */

52     public Object JavaDoc getDescriptor() {
53         return descriptor;
54     }
55     
56     /**
57      * all sub-implementation of this class can use a dispatch table to map xml element to
58      * method name on the descriptor class for setting the element value.
59      *
60      * @return the map with the element name as a key, the setter method as a value
61      */

62     protected Map JavaDoc getDispatchTable() {
63         Map JavaDoc table = super.getDispatchTable();
64         table.put(RuntimeTagNames.JNDI_NAME, "setJndiName");
65         return table;
66     }
67     
68     /**
69      * receives notiification of the value for a particular tag
70      *
71      * @param element the xml element
72      * @param value it's associated value
73      */

74     public void setElementValue(XMLElement element, String JavaDoc value) {
75         if (RuntimeTagNames.EJB_REFERENCE_NAME.equals(element.getQName())) {
76             Object JavaDoc parentDesc = getParentNode().getDescriptor();
77             if (parentDesc instanceof EjbReferenceContainer) {
78                 descriptor = ((EjbReferenceContainer) parentDesc).getEjbReference(value);
79                 DOLUtils.getDefaultLogger().finer("Applying ref runtime to " + descriptor);
80             }
81             if (descriptor==null) {
82                 DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.addDescriptorFailure",
83                         new Object JavaDoc[]{"ejb-ref" , value });
84             }
85         } else super.setElementValue(element, value);
86     }
87     
88     /**
89      * write the descriptor class to a DOM tree and return it
90      *
91      * @param parent node for the DOM tree
92      * @param node name for the descriptor
93      * @param the descriptor to write
94      * @return the DOM tree top node
95      */

96     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, EjbReference ejbRef) {
97         Node JavaDoc ejbRefNode = appendChild(parent, nodeName);
98         appendTextChild(ejbRefNode, RuntimeTagNames.EJB_REFERENCE_NAME, ejbRef.getName());
99         appendTextChild(ejbRefNode, RuntimeTagNames.JNDI_NAME, ejbRef.getJndiName());
100         return ejbRefNode;
101     }
102     
103     /**
104      * writes all the runtime information for ejb references
105      *
106      * @param parent node to add the runtime xml info
107      * @param the J2EE component containing ejb references
108      */

109     public static void writeEjbReferences(Node JavaDoc parent, EjbReferenceContainer descriptor) {
110         
111         // ejb-ref*
112
Iterator JavaDoc ejbRefs = descriptor.getEjbReferenceDescriptors().iterator();
113         if (ejbRefs.hasNext()) {
114             EjbRefNode refNode = new EjbRefNode();
115             while (ejbRefs.hasNext()) {
116                 EjbReference ejbRef = (EjbReference) ejbRefs.next();
117                 if (!ejbRef.isLocal()) {
118                     refNode.writeDescriptor(parent, RuntimeTagNames.EJB_REFERENCE, ejbRef );
119                 }
120             }
121         }
122     }
123 }
124
Popular Tags