KickJava   Java API By Example, From Geeks To Geeks.

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


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 /*
25  * RelationshipsRole.java
26  *
27  * Created on February 1, 2002, 3:01 PM
28  */

29
30 package com.sun.enterprise.deployment.node.ejb;
31
32 import java.util.Map JavaDoc;
33 import java.util.HashMap JavaDoc;
34 import java.util.Iterator JavaDoc;
35 import org.w3c.dom.Node JavaDoc;
36
37 import com.sun.enterprise.deployment.node.XMLElement;
38 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
39
40 import com.sun.enterprise.deployment.Descriptor;
41 import com.sun.enterprise.deployment.EjbBundleDescriptor;
42 import com.sun.enterprise.deployment.RelationshipDescriptor;
43 import com.sun.enterprise.deployment.xml.EjbTagNames;
44
45 /**
46  * This class is responsible for handling the ejb-relationships xml element
47  *
48  * @author Jerome Dochez
49  * @version
50  */

51 public class RelationshipsNode extends DeploymentDescriptorNode {
52
53     public RelationshipsNode() {
54         super();
55         registerElementHandler(new XMLElement(EjbTagNames.EJB_RELATION),
56                                                             EjbRelationNode.class);
57     }
58     
59    /**
60     * @return the descriptor instance to associate with this XMLNode
61     */

62     public Object JavaDoc getDescriptor() {
63         return getParentNode().getDescriptor();
64     }
65     
66    
67     /**
68      * receives notification of the end of an XML element by the Parser
69      *
70      * @param element the xml tag identification
71      * @return true if this node is done processing the XML sub tree
72      */

73     public boolean endElement(XMLElement element) {
74         return element.equals(getXMLRootTag());
75     }
76     
77     /**
78      * all sub-implementation of this class can use a dispatch table to map xml element to
79      * method name on the descriptor class for setting the element value.
80      *
81      * @return the map with the element name as a key, the setter method as a value
82      */

83     protected Map JavaDoc getDispatchTable() {
84         // no need to be synchronized for now
85
Map JavaDoc table = new HashMap JavaDoc();
86         table.put(EjbTagNames.DESCRIPTION, "setRelationshipsDescription");
87         return table;
88     }
89     
90     /**
91      * write the relationships descriptor class to a DOM tree and return it
92      *
93      * @param parent node in the DOM tree
94      * @param node name for the root element of this xml fragment
95      * @param the descriptor to write
96      * @return the DOM tree top node
97      */

98     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, EjbBundleDescriptor descriptor) {
99         Node JavaDoc relationshipsNode = super.writeDescriptor(parent, nodeName, descriptor);
100         appendTextChild(relationshipsNode, EjbTagNames.DESCRIPTION, descriptor.getRelationshipsDescription());
101         EjbRelationNode subNode = new EjbRelationNode();
102         for (Iterator JavaDoc e=descriptor.getRelationships().iterator();e.hasNext();) {
103             RelationshipDescriptor rd = (RelationshipDescriptor) e.next();
104             subNode.writeDescriptor(relationshipsNode, EjbTagNames.EJB_RELATION, rd);
105         }
106         
107         return relationshipsNode;
108     }
109 }
Popular Tags