KickJava   Java API By Example, From Geeks To Geeks.

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


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
28 import org.w3c.dom.Node JavaDoc;
29
30 import com.sun.enterprise.deployment.Descriptor;
31 import com.sun.enterprise.deployment.EnvironmentProperty;
32 import com.sun.enterprise.deployment.InjectionTarget;
33 import com.sun.enterprise.deployment.types.EjbReference;
34 import com.sun.enterprise.deployment.xml.EjbTagNames;
35 import com.sun.enterprise.deployment.xml.TagNames;
36
37 /**
38  * This class handles all information in the ejb-reference xml node
39  *
40  * @author Jerome Dochez
41  * @version
42  */

43 public class EjbReferenceNode extends DeploymentDescriptorNode {
44
45     protected EjbReference descriptor;
46     
47     public EjbReferenceNode() {
48         super();
49         registerElementHandler(new XMLElement(TagNames.INJECTION_TARGET),
50                                 InjectionTargetNode.class, "addInjectionTarget");
51     }
52         
53     /**
54     * @return the descriptor instance to associate with this XMLNode
55     */

56     public Object JavaDoc getDescriptor() {
57         if (descriptor==null) {
58             descriptor = (EjbReference) DescriptorFactory.getDescriptor(getXMLPath());
59             descriptor.setLocal(false);
60         }
61         return descriptor;
62     }
63     
64     /**
65      * all sub-implementation of this class can use a dispatch table to map xml element to
66      * method name on the descriptor class for setting the element value.
67      *
68      * @return the map with the element name as a key, the setter method as a value
69      */

70     protected Map JavaDoc getDispatchTable() {
71         Map JavaDoc table = super.getDispatchTable();
72         table.put(EjbTagNames.EJB_REFERENCE_NAME, "setName");
73         table.put(EjbTagNames.EJB_REFERENCE_TYPE, "setType");
74         table.put(EjbTagNames.HOME, "setEjbHomeInterface");
75         table.put(EjbTagNames.REMOTE, "setEjbInterface");
76         table.put(EjbTagNames.LOCAL_HOME, "setEjbHomeInterface");
77         table.put(EjbTagNames.LOCAL, "setEjbInterface");
78         table.put(EjbTagNames.EJB_LINK, "setLinkName");
79         table.put(TagNames.MAPPED_NAME, "setMappedName");
80         return table;
81     }
82
83     /**
84      * write the descriptor class to a DOM tree and return it
85      *
86      * @param parent node in the DOM tree
87      * @param node name for the root element of this xml fragment
88      * @param the descriptor to write
89      * @return the DOM tree top node
90      */

91     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, EjbReference descriptor) {
92         Node JavaDoc ejbRefNode = appendChild(parent, nodeName);
93         if (descriptor instanceof Descriptor) {
94             Descriptor ejbRefDesc = (Descriptor)descriptor;
95             writeLocalizedDescriptions(ejbRefNode, ejbRefDesc);
96         }
97         appendTextChild(ejbRefNode, EjbTagNames.EJB_REFERENCE_NAME, descriptor.getName());
98         appendTextChild(ejbRefNode, EjbTagNames.EJB_REFERENCE_TYPE, descriptor.getType());
99         if (descriptor.isLocal()) {
100             appendTextChild(ejbRefNode, EjbTagNames.LOCAL_HOME, descriptor.getEjbHomeInterface());
101             appendTextChild(ejbRefNode, EjbTagNames.LOCAL, descriptor.getEjbInterface());
102         } else {
103             appendTextChild(ejbRefNode, EjbTagNames.HOME, descriptor.getEjbHomeInterface());
104             appendTextChild(ejbRefNode, EjbTagNames.REMOTE, descriptor.getEjbInterface());
105         }
106         appendTextChild(ejbRefNode, EjbTagNames.EJB_LINK, descriptor.getLinkName());
107
108         if( descriptor instanceof EnvironmentProperty) {
109             EnvironmentProperty envProp = (EnvironmentProperty)descriptor;
110             appendTextChild(ejbRefNode, TagNames.MAPPED_NAME, envProp.getMappedName());
111         }
112         if( descriptor.isInjectable() ) {
113             InjectionTargetNode ijNode = new InjectionTargetNode();
114             for (InjectionTarget target : descriptor.getInjectionTargets()) {
115                 ijNode.writeDescriptor(ejbRefNode, TagNames.INJECTION_TARGET, target);
116             }
117         }
118
119         return ejbRefNode;
120     }
121         
122 }
123
Popular Tags