KickJava   Java API By Example, From Geeks To Geeks.

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


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

29
30 package com.sun.enterprise.deployment.node.ejb;
31
32 import java.util.Map JavaDoc;
33 import org.w3c.dom.Node JavaDoc;
34
35 import com.sun.enterprise.deployment.node.XMLElement;
36 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
37 import com.sun.enterprise.deployment.node.LocalizedInfoNode;
38 import com.sun.enterprise.deployment.node.DescriptorFactory;
39
40 import com.sun.enterprise.deployment.Descriptor;
41 import com.sun.enterprise.deployment.RelationRoleDescriptor;
42 import com.sun.enterprise.deployment.RelationshipDescriptor;
43 import com.sun.enterprise.deployment.xml.EjbTagNames;
44
45 /**
46  *
47  * @author dochez
48  * @version
49  */

50 public class EjbRelationNode extends DeploymentDescriptorNode {
51
52     RelationRoleDescriptor source = null;
53     RelationRoleDescriptor sink = null;
54     RelationshipDescriptor descriptor = null;
55     
56     public EjbRelationNode() {
57        super();
58        registerElementHandler(new XMLElement(EjbTagNames.EJB_RELATIONSHIP_ROLE),
59                                                             EjbRelationshipRoleNode.class);
60     }
61         
62    /**
63     * @return the descriptor instance to associate with this XMLNode
64     */

65     public Object JavaDoc getDescriptor() {
66         if (descriptor==null) {
67             descriptor = (RelationshipDescriptor) DescriptorFactory.getDescriptor(getXMLPath());
68         }
69         return descriptor;
70     }
71     
72     /**
73      * Adds a new DOL descriptor instance to the descriptor instance associated with
74      * this XMLNode
75      *
76      * @param descriptor the new descriptor
77      */

78     public void addDescriptor(Object JavaDoc newDescriptor) {
79         if (newDescriptor instanceof RelationRoleDescriptor) {
80             if (source==null) {
81                 source = (RelationRoleDescriptor) newDescriptor;
82             } else {
83                 sink = (RelationRoleDescriptor) newDescriptor;
84                 
85                 descriptor.setSource(source);
86                 source.setPartner(sink);
87                 source.setRelationshipDescriptor(descriptor);
88                 descriptor.setSink(sink);
89                 sink.setPartner(source);
90                 sink.setRelationshipDescriptor(descriptor);
91
92                 if ( source.getCMRField() != null && sink.getCMRField() != null )
93                     descriptor.setIsBidirectional(true);
94                 else
95                     descriptor.setIsBidirectional(false);
96             }
97         }
98     }
99         
100     /**
101      * all sub-implementation of this class can use a dispatch table to map xml element to
102      * method name on the descriptor class for setting the element value.
103      *
104      * @return the map with the element name as a key, the setter method as a value
105      */

106     protected Map JavaDoc getDispatchTable() {
107         // no need to be synchronized for now
108
Map JavaDoc table = super.getDispatchTable();
109         table.put(EjbTagNames.EJB_RELATION_NAME, "setName");
110         return table;
111     }
112
113    /**
114      * write the relationships descriptor class to a DOM tree and return it
115      *
116      * @param parent node in the DOM tree
117      * @param node name for the root element of this xml fragment
118      * @param the descriptor to write
119      * @return the DOM tree top node
120      */

121     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, RelationshipDescriptor descriptor) {
122         Node JavaDoc ejbRelationNode = super.writeDescriptor(parent, nodeName, descriptor);
123         writeLocalizedDescriptions(ejbRelationNode, descriptor);
124         appendTextChild(ejbRelationNode, EjbTagNames.EJB_RELATION_NAME, descriptor.getName());
125         EjbRelationshipRoleNode roleNode = new EjbRelationshipRoleNode();
126         roleNode.writeDescriptor(ejbRelationNode, EjbTagNames.EJB_RELATIONSHIP_ROLE, descriptor.getSource());
127         roleNode.writeDescriptor(ejbRelationNode, EjbTagNames.EJB_RELATIONSHIP_ROLE, descriptor.getSink());
128         return ejbRelationNode;
129     }
130 }
131
Popular Tags