KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > ejb > cmp3 > xml > accessors > XMLOneToManyAccessor


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
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
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 in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22
package oracle.toplink.essentials.internal.ejb.cmp3.xml.accessors;
23
24 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.OneToManyAccessor;
25 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.objects.MetadataAccessibleObject;
26
27 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.tables.MetadataJoinTable;
28
29 import oracle.toplink.essentials.internal.ejb.cmp3.xml.tables.XMLJoinTable;
30
31 import oracle.toplink.essentials.internal.ejb.cmp3.xml.XMLConstants;
32 import oracle.toplink.essentials.internal.ejb.cmp3.xml.XMLHelper;
33
34 import org.w3c.dom.Node JavaDoc;
35
36 /**
37  * A OneToMany relationship accessor.
38  *
39  * @author Guy Pelletier
40  * @since TopLink EJB 3.0 Reference Implementation
41  */

42 public class XMLOneToManyAccessor extends OneToManyAccessor {
43     protected Node JavaDoc m_node;
44     protected XMLHelper m_helper;
45     
46     /**
47      * INTERNAL:
48      */

49     public XMLOneToManyAccessor(MetadataAccessibleObject accessibleObject, Node JavaDoc node, XMLClassAccessor classAccessor) {
50         super(accessibleObject, classAccessor);
51         m_node = node;
52         m_helper = classAccessor.getHelper();
53         
54         XMLAccessorHelper.setRelationshipAccessorData(this, m_node, m_helper);
55     }
56     
57     /**
58      * INTERNAL: (Override from CollectionAccessor)
59      */

60     public MetadataJoinTable getJoinTable() {
61         Node JavaDoc node = m_helper.getNode(m_node, XMLConstants.JOIN_TABLE);
62         
63         if (node == null) {
64             return super.getJoinTable();
65         } else {
66             return new XMLJoinTable(node, m_helper);
67         }
68     }
69     
70     /**
71      * INTERNAL: (Override from CollectionAccessor)
72      * Checks for a map-key node and returns its value if there is one.
73      * Otherwise, ask the parent to look for an annotation.
74      */

75     public String JavaDoc getMapKey() {
76         Node JavaDoc mapKeyNode = m_helper.getNode(m_node, XMLConstants.MAPKEY);
77         String JavaDoc mapKeyValue = m_helper.getNodeValue(mapKeyNode, XMLConstants.ATT_NAME);
78         
79         if (mapKeyNode == null) {
80             return super.getMapKey();
81         } else {
82             return mapKeyValue;
83         }
84     }
85     
86     /**
87      * INTERNAL: (Override from CollectionAccessor)
88      * If the order value is not specified, "" is returned.
89      */

90     public String JavaDoc getOrderBy() {
91         if (hasOrderBy()) {
92             return m_helper.getNodeTextValue(m_node, XMLConstants.ORDER_BY);
93         } else {
94             return super.getOrderBy();
95         }
96     }
97     
98     /**
99      * INTERNAL: (Override from CollectionAccessor)
100      * Checks for an order-by node. If one isn't found, as the parent to look
101      * for an annotation.
102      */

103     public boolean hasOrderBy() {
104         Node JavaDoc orderByNode = m_helper.getNode(m_node, XMLConstants.ORDER_BY);
105         
106         if (orderByNode == null) {
107             return super.hasOrderBy();
108         } else {
109             return true;
110         }
111     }
112 }
113
Popular Tags